Improved colorization in instanced rendering

This commit is contained in:
Benau 2016-11-28 13:08:27 +08:00
parent decf3b9715
commit 45c5b0ffd6
9 changed files with 76 additions and 140 deletions

View File

@ -30,6 +30,7 @@ in vec3 Bitangent;
in vec3 Origin; in vec3 Origin;
in vec3 Orientation; in vec3 Orientation;
in vec3 Scale; in vec3 Scale;
in vec4 misc_data;
#endif #endif
out vec3 nor; out vec3 nor;
@ -38,10 +39,12 @@ out vec3 bitangent;
out vec2 uv; out vec2 uv;
out vec2 uv_bis; out vec2 uv_bis;
out vec4 color; out vec4 color;
out vec2 color_change;
#ifdef Use_Bindless_Texture #ifdef Use_Bindless_Texture
flat out sampler2D handle; flat out sampler2D handle;
flat out sampler2D secondhandle; flat out sampler2D secondhandle;
flat out sampler2D thirdhandle; flat out sampler2D thirdhandle;
flat out sampler2D fourthhandle;
#endif #endif
#stk_include "utils/getworldmatrix.vert" #stk_include "utils/getworldmatrix.vert"
@ -56,12 +59,18 @@ void main(void)
// Keep direction // Keep direction
tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz; tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz; bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
uv = Texcoord; uv = (mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
misc_data.x, misc_data.y, 1., 0.,
0., 0., 0., 1.)
* vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord; uv_bis = SecondTexcoord;
color = Color.zyxw; color = Color.zyxw;
color_change = misc_data.zw;
#ifdef Use_Bindless_Texture #ifdef Use_Bindless_Texture
handle = Handle; handle = Handle;
secondhandle = SecondHandle; secondhandle = SecondHandle;
thirdhandle = ThirdHandle; thirdhandle = ThirdHandle;
fourthhandle = FourthHandle;
#endif #endif
} }

View File

@ -7,12 +7,12 @@ uniform sampler2D colorization_mask;
#ifdef Use_Bindless_Texture #ifdef Use_Bindless_Texture
flat in sampler2D handle; flat in sampler2D handle;
flat in sampler2D secondhandle; flat in sampler2D secondhandle;
flat in sampler2D fourthhandle;
#endif #endif
uniform vec2 color_change;
in vec2 uv; in vec2 uv;
in vec4 color; in vec4 color;
in vec2 color_change;
out vec4 FragColor; out vec4 FragColor;
#stk_include "utils/getLightFactor.frag" #stk_include "utils/getLightFactor.frag"
@ -24,6 +24,7 @@ void main(void)
vec4 col = texture(handle, uv); vec4 col = texture(handle, uv);
float specmap = texture(secondhandle, uv).g; float specmap = texture(secondhandle, uv).g;
float emitmap = texture(secondhandle, uv).b; float emitmap = texture(secondhandle, uv).b;
float mask = texture(fourthhandle, uv).a;
#ifdef SRGBBindlessFix #ifdef SRGBBindlessFix
col.xyz = pow(col.xyz, vec3(2.2)); col.xyz = pow(col.xyz, vec3(2.2));
#endif #endif

View File

@ -21,30 +21,30 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> template<>
void InstanceFiller<InstanceDataSingleTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataSingleTex &instance) void InstanceFiller<InstanceDataSingleTex>::add(GLMesh *mesh, InstanceSettings is, InstanceDataSingleTex &instance)
{ {
fillOriginOrientationScale<InstanceDataSingleTex>(node, instance); fillOriginOrientationScale<InstanceDataSingleTex>(STK::tuple_get<0>(is), instance);
instance.Texture = mesh->TextureHandles[0]; instance.Texture = mesh->TextureHandles[0];
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> template<>
void InstanceFiller<InstanceDataDualTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataDualTex &instance) void InstanceFiller<InstanceDataDualTex>::add(GLMesh *mesh, InstanceSettings is, InstanceDataDualTex &instance)
{ {
fillOriginOrientationScale<InstanceDataDualTex>(node, instance); fillOriginOrientationScale<InstanceDataDualTex>(STK::tuple_get<0>(is), instance);
instance.Texture = mesh->TextureHandles[0]; instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1]; instance.SecondTexture = mesh->TextureHandles[1];
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> template<>
void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataThreeTex &instance) void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, InstanceSettings is, InstanceDataThreeTex &instance)
{ {
fillOriginOrientationScale<InstanceDataThreeTex>(node, instance); fillOriginOrientationScale<InstanceDataThreeTex>(STK::tuple_get<0>(is), instance);
instance.MiscData.X = 0; instance.MiscData.X = STK::tuple_get<1>(is).X;
instance.MiscData.Y = 0; instance.MiscData.Y = STK::tuple_get<1>(is).Y;
instance.MiscData.Z = 0; instance.MiscData.Z = STK::tuple_get<2>(is).X;
instance.MiscData.W = 0; instance.MiscData.W = STK::tuple_get<2>(is).Y;
instance.Texture = mesh->TextureHandles[0]; instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1]; instance.SecondTexture = mesh->TextureHandles[1];
instance.ThirdTexture = mesh->TextureHandles[7]; instance.ThirdTexture = mesh->TextureHandles[7];
@ -52,13 +52,13 @@ void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> template<>
void InstanceFiller<InstanceDataFourTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataFourTex &instance) void InstanceFiller<InstanceDataFourTex>::add(GLMesh *mesh, InstanceSettings is, InstanceDataFourTex &instance)
{ {
fillOriginOrientationScale<InstanceDataFourTex>(node, instance); fillOriginOrientationScale<InstanceDataFourTex>(STK::tuple_get<0>(is), instance);
instance.MiscData.X = 0; instance.MiscData.X = STK::tuple_get<1>(is).X;
instance.MiscData.Y = 0; instance.MiscData.Y = STK::tuple_get<1>(is).Y;
instance.MiscData.Z = 0; instance.MiscData.Z = STK::tuple_get<2>(is).X;
instance.MiscData.W = 0; instance.MiscData.W = STK::tuple_get<2>(is).Y;
instance.Texture = mesh->TextureHandles[0]; instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1]; instance.SecondTexture = mesh->TextureHandles[1];
instance.ThirdTexture = mesh->TextureHandles[2]; instance.ThirdTexture = mesh->TextureHandles[2];
@ -67,8 +67,9 @@ void InstanceFiller<InstanceDataFourTex>::add(GLMesh *mesh, scene::ISceneNode *n
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
template<> template<>
void InstanceFiller<GlowInstanceData>::add(GLMesh *mesh, scene::ISceneNode *node, GlowInstanceData &instance) void InstanceFiller<GlowInstanceData>::add(GLMesh *mesh, InstanceSettings is, GlowInstanceData &instance)
{ {
scene::ISceneNode* node = STK::tuple_get<0>(is);
fillOriginOrientationScale<GlowInstanceData>(node, instance); fillOriginOrientationScale<GlowInstanceData>(node, instance);
STKMeshSceneNode *nd = dynamic_cast<STKMeshSceneNode*>(node); STKMeshSceneNode *nd = dynamic_cast<STKMeshSceneNode*>(node);
instance.Color = nd->getGlowColor().color; instance.Color = nd->getGlowColor().color;

View File

@ -29,10 +29,12 @@
#include <array> #include <array>
#include <unordered_map> #include <unordered_map>
typedef STK::Tuple<scene::ISceneNode*, core::vector2df, core::vector2df> InstanceSettings;
struct InstanceList struct InstanceList
{ {
GLMesh *m_mesh; GLMesh *m_mesh;
std::vector<irr::scene::ISceneNode*> m_scene_nodes; std::vector<InstanceSettings> m_instance_settings;
}; };
typedef std::unordered_map <std::pair<scene::IMeshBuffer*, RenderInfo*>, InstanceList, typedef std::unordered_map <std::pair<scene::IMeshBuffer*, RenderInfo*>, InstanceList,
@ -67,7 +69,7 @@ void fillOriginOrientationScale(scene::ISceneNode *node, InstanceData &instance)
template<typename InstanceData> template<typename InstanceData>
struct InstanceFiller struct InstanceFiller
{ {
static void add(GLMesh *, scene::ISceneNode *, InstanceData &); static void add(GLMesh *, InstanceSettings, InstanceData &);
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -93,10 +95,10 @@ void FillInstances_impl(InstanceList instance_list,
GLMesh *mesh = instance_list.m_mesh; GLMesh *mesh = instance_list.m_mesh;
size_t initial_offset = instance_buffer_offset; size_t initial_offset = instance_buffer_offset;
for (unsigned i = 0; i < instance_list.m_scene_nodes.size(); i++) for (unsigned i = 0; i < instance_list.m_instance_settings.size(); i++)
{ {
scene::ISceneNode *node = instance_list.m_scene_nodes[i]; InstanceFiller<T>::add(mesh, instance_list.m_instance_settings[i],
InstanceFiller<T>::add(mesh, node, instance_buffer[instance_buffer_offset++]); instance_buffer[instance_buffer_offset++]);
assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataThreeTex)); assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataThreeTex));
} }
@ -306,7 +308,6 @@ public:
if (!mesh->mb->getMaterial().BackfaceCulling) if (!mesh->mb->getMaterial().BackfaceCulling)
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
} }
} //drawIndirectFirstPass } //drawIndirectFirstPass
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -356,19 +357,6 @@ public:
{ {
GLMesh *mesh = m_meshes[T::MaterialType][i]; GLMesh *mesh = m_meshes[T::MaterialType][i];
expandTexSecondPass<T>(*mesh, prefilled_tex); expandTexSecondPass<T>(*mesh, prefilled_tex);
//TODO: next 10 lines are duplicated in draw_tools.hpp (see CustomUnrollArgs::drawMesh)
//TODO: find a way to remove duplicated code
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue =
(support_change_hue && mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
T::InstancedSecondPassShader::getInstance()->changeableColor
(mesh->m_render_info->getHue(),
mesh->m_material->getColorizationFactor());
}
if (!mesh->mb->getMaterial().BackfaceCulling) if (!mesh->mb->getMaterial().BackfaceCulling)
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDrawElementsIndirect(GL_TRIANGLES, glDrawElementsIndirect(GL_TRIANGLES,
@ -376,11 +364,6 @@ public:
(const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand))); (const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand)));
if (!mesh->mb->getMaterial().BackfaceCulling) if (!mesh->mb->getMaterial().BackfaceCulling)
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
if (need_change_hue)
{
// Reset after changing
T::InstancedSecondPassShader::getInstance()->changeableColor();
}
} }
} //drawIndirectSecondPass } //drawIndirectSecondPass

View File

@ -254,53 +254,27 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
if (node->glow()) if (node->glow())
{ {
m_glow_pass_mesh[mesh->mb].m_mesh = mesh; m_glow_pass_mesh[mesh->mb].m_mesh = mesh;
m_glow_pass_mesh[mesh->mb].m_scene_nodes.emplace_back(Node); m_glow_pass_mesh[mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
} }
if (Mat == Material::SHADERTYPE_SPLATTING)
if (Mat != Material::SHADERTYPE_SPLATTING && mesh->texture_trans.getLength() == 0.0f)
{ {
std::pair<scene::IMeshBuffer*, RenderInfo*> meshRenderInfo(mesh->mb, mesh->m_render_info); //TODO: write instanced splatting solid shader and remove this if
m_solid_pass_mesh[Mat][meshRenderInfo].m_mesh = mesh; core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
m_solid_pass_mesh[Mat][meshRenderInfo].m_scene_nodes.emplace_back(Node); ModelMatrix.getInverse(InvModelMatrix);
ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix);
} }
else else
{ {
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; // Only take render info into account if the node is not static (animated)
ModelMatrix.getInverse(InvModelMatrix); // So they can have different animation
switch (Mat) std::pair<scene::IMeshBuffer*, RenderInfo*> mesh_render_info(mesh->mb,
{ dynamic_cast<STKMeshSceneNode*>(Node) == NULL ? mesh->m_render_info : NULL);
case Material::SHADERTYPE_SOLID: m_solid_pass_mesh[Mat][mesh_render_info].m_mesh = mesh;
ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, m_solid_pass_mesh[Mat][mesh_render_info].m_instance_settings.emplace_back(Node, mesh->texture_trans,
(mesh->m_render_info && mesh->m_material ? (mesh->m_render_info && mesh->m_material ?
core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) :
core::vector2df(0.0f, 0.0f))); core::vector2df(0.0f, 0.0f)));
break;
case Material::SHADERTYPE_ALPHA_TEST:
ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SOLID_UNLIT:
ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans);
break;
case Material::SHADERTYPE_SPLATTING:
ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix);
break;
case Material::SHADERTYPE_ALPHA_BLEND:
break;
case Material::SHADERTYPE_ADDITIVE:
break;
case Material::SHADERTYPE_VEGETATION:
break;
case Material::SHADERTYPE_WATER:
break;
case Material::SHADERTYPE_SPHERE_MAP:
break;
case Material::SHADERTYPE_NORMAL_MAP:
break;
case Material::SHADERTYPE_DETAIL_MAP:
break;
default:
Log::warn("DrawCalls", "Unknown material type: %d", Mat);
}
} }
} }
} }
@ -369,7 +343,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
for (GLMesh *mesh : node->MeshSolidMaterial[Mat]) for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
{ {
m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_mesh = mesh; m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_mesh = mesh;
m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_scene_nodes.emplace_back(Node); m_shadow_pass_mesh[cascade * Material::SHADERTYPE_COUNT + Mat][mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
} }
} }
else else
@ -424,22 +399,21 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
for (unsigned Mat = 0; Mat < Material::SHADERTYPE_COUNT; ++Mat) for (unsigned Mat = 0; Mat < Material::SHADERTYPE_COUNT; ++Mat)
{ {
if (CVS->supportsIndirectInstancingRendering()) if (CVS->supportsIndirectInstancingRendering())
{
if (Mat == Material::SHADERTYPE_SPLATTING)
{ {
for (GLMesh *mesh : node->MeshSolidMaterial[Mat]) for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
{ {
if (Mat == Material::SHADERTYPE_SPLATTING)
{
//TODO: write instanced splatting rsm shader and remove this if
core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix;
ModelMatrix.getInverse(InvModelMatrix); ModelMatrix.getInverse(InvModelMatrix);
ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix); ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix);
} }
}
else else
{
for (GLMesh *mesh : node->MeshSolidMaterial[Mat])
{ {
m_reflective_shadow_map_mesh[Mat][mesh->mb].m_mesh = mesh; m_reflective_shadow_map_mesh[Mat][mesh->mb].m_mesh = mesh;
m_reflective_shadow_map_mesh[Mat][mesh->mb].m_scene_nodes.emplace_back(Node); m_reflective_shadow_map_mesh[Mat][mesh->mb].m_instance_settings
.emplace_back(Node, core::vector2df(0.0f, 0.0f), core::vector2df(0.0f, 0.0f));
} }
} }
} }

View File

@ -198,13 +198,8 @@ void GL3DrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
void IndirectDrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const void IndirectDrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const
{ {
#if !defined(USE_GLES2) #if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders, //TODO: add instanced splatting solid shader
//and remove these four lines
renderMeshes1stPass<DefaultMaterial, 2, 1>();
renderMeshes1stPass<SplattingMat, 2, 1>(); renderMeshes1stPass<SplattingMat, 2, 1>();
renderMeshes1stPass<UnlitMat, 3, 2, 1>();
renderMeshes1stPass<AlphaRef, 3, 2, 1>();
draw_calls.drawIndirectSolidFirstPass(); draw_calls.drawIndirectSolidFirstPass();
#endif //!defined(USE_GLES2) #endif //!defined(USE_GLES2)
} }
@ -215,13 +210,8 @@ void IndirectDrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls,
const std::vector<GLuint>& prefilled_tex) const const std::vector<GLuint>& prefilled_tex) const
{ {
#if !defined(USE_GLES2) #if !defined(USE_GLES2)
//TODO: find a way to add TextureMatrix in instanced shaders, //TODO: add instanced splatting solid shader
//and remove these four lines
renderMeshes2ndPass<DefaultMaterial, 4, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 3, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex); renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex);
draw_calls.drawIndirectSolidSecondPass(prefilled_tex); draw_calls.drawIndirectSolidSecondPass(prefilled_tex);
#endif //!defined(USE_GLES2) #endif //!defined(USE_GLES2)
} }
@ -271,13 +261,8 @@ void IndirectDrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
void MultidrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const void MultidrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const
{ {
#if !defined(USE_GLES2) #if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders, //TODO: add instanced splatting solid shader
//and remove these four lines
renderMeshes1stPass<DefaultMaterial, 2, 1>();
renderMeshes1stPass<SplattingMat, 2, 1>(); renderMeshes1stPass<SplattingMat, 2, 1>();
renderMeshes1stPass<UnlitMat, 3, 2, 1>();
renderMeshes1stPass<AlphaRef, 3, 2, 1>();
draw_calls.multidrawSolidFirstPass(); draw_calls.multidrawSolidFirstPass();
#endif //!defined(USE_GLES2) #endif //!defined(USE_GLES2)
} }
@ -288,13 +273,8 @@ void MultidrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls,
const std::vector<GLuint>& prefilled_tex) const const std::vector<GLuint>& prefilled_tex) const
{ {
#if !defined(USE_GLES2) #if !defined(USE_GLES2)
//TODO: find a way to add TextureMarix in instanced shaders, //TODO: add instanced splatting solid shader
//and remove these four lines
renderMeshes2ndPass<DefaultMaterial, 4, 3, 1> (handles, prefilled_tex);
renderMeshes2ndPass<AlphaRef, 3, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<UnlitMat, 3, 1 > (handles, prefilled_tex);
renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex); renderMeshes2ndPass<SplattingMat, 1> (handles, prefilled_tex);
draw_calls.multidrawSolidSecondPass(handles); draw_calls.multidrawSolidSecondPass(handles);
#endif //!defined(USE_GLES2) #endif //!defined(USE_GLES2)
} }

View File

@ -75,15 +75,11 @@ public:
// ============================================================================ // ============================================================================
class InstancedObjectPass2Shader : public TextureShader<InstancedObjectPass2Shader, 6> class InstancedObjectPass2Shader : public TextureShader<InstancedObjectPass2Shader, 6>
{ {
private:
GLint m_color_change_location;
public: public:
InstancedObjectPass2Shader() InstancedObjectPass2Shader()
{ {
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_object_pass.vert", loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_object_pass.vert",
GL_FRAGMENT_SHADER, "instanced_object_pass2.frag"); GL_FRAGMENT_SHADER, "instanced_object_pass2.frag");
m_color_change_location = glGetUniformLocation(m_program, "color_change");
assignUniforms(); assignUniforms();
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED, assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED, 1, "SpecularMap", ST_NEAREST_FILTERED,
@ -92,12 +88,6 @@ public:
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED, 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED); 5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedObjectPass2Shader } // InstancedObjectPass2Shader
virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const OVERRIDE
{
glUniform2f(m_color_change_location, hue, min_sat);
return true;
} // changeableColor
}; // InstancedObjectPass2Shader }; // InstancedObjectPass2Shader
// ============================================================================ // ============================================================================

View File

@ -399,19 +399,24 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat)
switch (mat) switch (mat)
{ {
default: default:
case Material::SHADERTYPE_VEGETATION:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
break;
case Material::SHADERTYPE_SOLID: case Material::SHADERTYPE_SOLID:
case Material::SHADERTYPE_ALPHA_TEST: case Material::SHADERTYPE_ALPHA_TEST:
case Material::SHADERTYPE_VEGETATION:
case Material::SHADERTYPE_SPHERE_MAP: case Material::SHADERTYPE_SPHERE_MAP:
case Material::SHADERTYPE_SOLID_UNLIT: case Material::SHADERTYPE_SOLID_UNLIT:
setTexture(mesh, 0, true, getShaderTypeName(mat)); setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat)); setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 7, false, getShaderTypeName(mat));
break; break;
case Material::SHADERTYPE_DETAIL_MAP: case Material::SHADERTYPE_DETAIL_MAP:
case Material::SHADERTYPE_NORMAL_MAP: case Material::SHADERTYPE_NORMAL_MAP:
setTexture(mesh, 0, true, getShaderTypeName(mat)); setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat)); setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat)); setTexture(mesh, 2, false, getShaderTypeName(mat));
setTexture(mesh, 7, false, getShaderTypeName(mat));
break; break;
case Material::SHADERTYPE_SPLATTING: case Material::SHADERTYPE_SPLATTING:
setTexture(mesh, 0, true, getShaderTypeName(mat)); setTexture(mesh, 0, true, getShaderTypeName(mat));

View File

@ -244,13 +244,6 @@ public:
glDeleteSamplers(1, &m_sampler_ids[i]); glDeleteSamplers(1, &m_sampler_ids[i]);
} // ~TextureShader } // ~TextureShader
/** Override this class and return true if a shader has changeable color.
*/
virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const
{
return false;
} // changeableColor
}; // class TextureShader }; // class TextureShader
#endif #endif