diff --git a/data/shaders/glow_object.vert b/data/shaders/glow_object.vert index ec0eacec9..e7b7cddab 100644 --- a/data/shaders/glow_object.vert +++ b/data/shaders/glow_object.vert @@ -8,7 +8,7 @@ layout(location = 6) in vec3 Bitangent; layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; -layout(location = 12) in vec4 GlowColor; +layout(location = 15) in vec4 GlowColor; flat out vec4 glowColor; diff --git a/data/shaders/instanced_detailed_object_pass2.frag b/data/shaders/instanced_detailed_object_pass2.frag index 9cc428b0c..0b39a2b35 100644 --- a/data/shaders/instanced_detailed_object_pass2.frag +++ b/data/shaders/instanced_detailed_object_pass2.frag @@ -7,7 +7,7 @@ uniform sampler2D SpecMap; #ifdef Use_Bindless_Texture flat in sampler2D handle; flat in sampler2D secondhandle; -flat in sampler2D thirdhandle; +flat in sampler2D fourthhandle; #endif in vec2 uv; in vec2 uv_bis; @@ -23,7 +23,7 @@ void main(void) #ifdef SRGBBindlessFix color.xyz = pow(color.xyz, vec3(2.2)); #endif - vec4 detail = texture(thirdhandle, uv_bis); + vec4 detail = texture(fourthhandle, uv_bis); #else vec4 color = texture(Albedo, uv); vec4 detail = texture(Detail, uv_bis); diff --git a/data/shaders/instanced_grass.vert b/data/shaders/instanced_grass.vert index 778b28500..a224f8f1c 100644 --- a/data/shaders/instanced_grass.vert +++ b/data/shaders/instanced_grass.vert @@ -10,8 +10,8 @@ layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; #ifdef Use_Bindless_Texture -layout(location = 10) in sampler2D Handle; -layout(location = 11) in sampler2D SecondHandle; +layout(location = 11) in sampler2D Handle; +layout(location = 12) in sampler2D SecondHandle; #endif #else diff --git a/data/shaders/instanced_normalmap.frag b/data/shaders/instanced_normalmap.frag index cc7104a8d..c66e4f0c6 100644 --- a/data/shaders/instanced_normalmap.frag +++ b/data/shaders/instanced_normalmap.frag @@ -5,7 +5,7 @@ uniform sampler2D glossMap; #ifdef Use_Bindless_Texture flat in sampler2D secondhandle; -flat in sampler2D thirdhandle; +flat in sampler2D fourthhandle; #endif in vec3 tangent; in vec3 bitangent; @@ -18,7 +18,7 @@ void main() { // normal in Tangent Space #ifdef Use_Bindless_Texture - vec3 TS_normal = 2.0 * texture(thirdhandle, uv).rgb - 1.0; + vec3 TS_normal = 2.0 * texture(fourthhandle, uv).rgb - 1.0; float gloss = texture(secondhandle, uv).x; #else vec3 TS_normal = 2.0 * texture(normalMap, uv).rgb - 1.0; diff --git a/data/shaders/instanced_object_pass.vert b/data/shaders/instanced_object_pass.vert index 8e618bd01..e92bb1490 100644 --- a/data/shaders/instanced_object_pass.vert +++ b/data/shaders/instanced_object_pass.vert @@ -10,10 +10,12 @@ layout(location = 6) in vec3 Bitangent; layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; +layout(location = 10) in vec4 misc_data; #ifdef Use_Bindless_Texture -layout(location = 10) in sampler2D Handle; -layout(location = 11) in sampler2D SecondHandle; +layout(location = 11) in sampler2D Handle; +layout(location = 12) in sampler2D SecondHandle; layout(location = 13) in sampler2D ThirdHandle; +layout(location = 14) in sampler2D FourthHandle; #endif #else @@ -28,6 +30,7 @@ in vec3 Bitangent; in vec3 Origin; in vec3 Orientation; in vec3 Scale; +in vec4 misc_data; #endif out vec3 nor; @@ -36,10 +39,12 @@ out vec3 bitangent; out vec2 uv; out vec2 uv_bis; out vec4 color; +out vec2 color_change; #ifdef Use_Bindless_Texture flat out sampler2D handle; flat out sampler2D secondhandle; flat out sampler2D thirdhandle; +flat out sampler2D fourthhandle; #endif #stk_include "utils/getworldmatrix.vert" @@ -54,12 +59,14 @@ void main(void) // Keep direction tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz; bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz; - uv = Texcoord; + uv = vec2(Texcoord.x + misc_data.x, Texcoord.y + misc_data.y); uv_bis = SecondTexcoord; color = Color.zyxw; + color_change = misc_data.zw; #ifdef Use_Bindless_Texture handle = Handle; secondhandle = SecondHandle; thirdhandle = ThirdHandle; + fourthhandle = FourthHandle; #endif } diff --git a/data/shaders/instanced_object_pass2.frag b/data/shaders/instanced_object_pass2.frag index 6d8bb14f8..120f3e21a 100644 --- a/data/shaders/instanced_object_pass2.frag +++ b/data/shaders/instanced_object_pass2.frag @@ -7,12 +7,12 @@ uniform sampler2D colorization_mask; #ifdef Use_Bindless_Texture flat in sampler2D handle; flat in sampler2D secondhandle; +flat in sampler2D thirdhandle; #endif -uniform vec2 color_change; - in vec2 uv; in vec4 color; +in vec2 color_change; out vec4 FragColor; #stk_include "utils/getLightFactor.frag" @@ -24,6 +24,7 @@ void main(void) vec4 col = texture(handle, uv); float specmap = texture(secondhandle, uv).g; float emitmap = texture(secondhandle, uv).b; + float mask = texture(thirdhandle, uv).a; #ifdef SRGBBindlessFix col.xyz = pow(col.xyz, vec3(2.2)); #endif diff --git a/data/shaders/instanced_rsm.vert b/data/shaders/instanced_rsm.vert index d5a656c4a..8098d1c96 100644 --- a/data/shaders/instanced_rsm.vert +++ b/data/shaders/instanced_rsm.vert @@ -9,7 +9,7 @@ layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; #ifdef Use_Bindless_Texture -layout(location = 10) in uvec2 Handle; +layout(location = 11) in uvec2 Handle; #endif out vec3 nor; diff --git a/data/shaders/instanciedgrassshadow.vert b/data/shaders/instanciedgrassshadow.vert index 0a5f7f67a..e8d31d927 100644 --- a/data/shaders/instanciedgrassshadow.vert +++ b/data/shaders/instanciedgrassshadow.vert @@ -10,7 +10,7 @@ layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; #ifdef Use_Bindless_Texture -layout(location = 10) in uvec2 Handle; +layout(location = 11) in uvec2 Handle; #endif #else diff --git a/data/shaders/instanciedshadow.vert b/data/shaders/instanciedshadow.vert index 2a3cc5283..09885f333 100644 --- a/data/shaders/instanciedshadow.vert +++ b/data/shaders/instanciedshadow.vert @@ -8,7 +8,7 @@ layout(location = 7) in vec3 Origin; layout(location = 8) in vec3 Orientation; layout(location = 9) in vec3 Scale; #ifdef Use_Bindless_Texture -layout(location = 10) in uvec2 Handle; +layout(location = 11) in uvec2 Handle; #endif #else diff --git a/data/shaders/object_pass.vert b/data/shaders/object_pass.vert index 62f8c8dcd..c98c0c0a6 100644 --- a/data/shaders/object_pass.vert +++ b/data/shaders/object_pass.vert @@ -1,7 +1,7 @@ #ifdef GL_ES uniform mat4 ModelMatrix; uniform mat4 InverseModelMatrix; -uniform mat4 TextureMatrix; +uniform vec2 texture_trans; #else uniform mat4 ModelMatrix = mat4(1., 0., 0., 0., @@ -14,11 +14,7 @@ uniform mat4 InverseModelMatrix = 0., 0., 1., 0., 0., 0., 0., 1.); -uniform mat4 TextureMatrix = - mat4(1., 0., 0., 0., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 1.); +uniform vec2 texture_trans = vec2(0., 0.); #endif #if __VERSION__ >= 330 @@ -58,6 +54,6 @@ void main(void) // Keep direction tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz; bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz; - uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; + uv = vec2(Texcoord.x + texture_trans.x, Texcoord.y + texture_trans.y); uv_bis = SecondTexcoord; } diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index df11c2beb..c7da60205 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -1,6 +1,8 @@ #ifdef Use_Bindless_Texture layout(bindless_sampler) uniform sampler2D Albedo; layout(bindless_sampler) uniform sampler2D SpecMap; +layout(bindless_sampler) uniform sampler2D colorization_mask; + #else uniform sampler2D Albedo; uniform sampler2D SpecMap; @@ -20,6 +22,7 @@ void main(void) { #ifdef Use_Bindless_Texture vec4 col = texture(Albedo, uv); + float mask = texture(colorization_mask, uv).a; #ifdef SRGBBindlessFix col.xyz = pow(col.xyz, vec3(2.2)); #endif diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert index 68da61338..a02e62b30 100644 --- a/data/shaders/rsm.vert +++ b/data/shaders/rsm.vert @@ -1,11 +1,6 @@ uniform mat4 ModelMatrix; uniform mat4 RSMMatrix; - -uniform mat4 TextureMatrix = - mat4(1., 0., 0., 0., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 1.); +uniform vec2 texture_trans = vec2(0., 0.); #if __VERSION__ >= 330 layout(location = 0) in vec3 Position; @@ -33,7 +28,7 @@ void main(void) mat4 TransposeInverseModel = transpose(inverse(ModelMatrix)); gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); nor = (TransposeInverseModel * vec4(Normal, 0.)).xyz; - uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; + uv = vec2(Texcoord.x + texture_trans.x, Texcoord.y + texture_trans.y); uv_bis = SecondTexcoord; color = Color.zyxw; } diff --git a/data/shaders/transparent.frag b/data/shaders/transparent.frag index 03250aa21..67b6733de 100644 --- a/data/shaders/transparent.frag +++ b/data/shaders/transparent.frag @@ -14,7 +14,9 @@ void main() { vec4 Color = texture(tex, uv); #ifdef Use_Bindless_Texture +#ifdef SRGBBindlessFix Color.xyz = pow(Color.xyz, vec3(2.2)); +#endif #endif Color.xyz *= pow(color.xyz, vec3(2.2)); Color.a *= color.a; diff --git a/data/shaders/transparentfog.frag b/data/shaders/transparentfog.frag index d960f07e1..0f1c74dff 100644 --- a/data/shaders/transparentfog.frag +++ b/data/shaders/transparentfog.frag @@ -21,7 +21,9 @@ void main() { vec4 diffusecolor = texture(tex, uv); #ifdef Use_Bindless_Texture +#ifdef SRGBBindlessFix diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2)); +#endif #endif diffusecolor.xyz *= pow(color.xyz, vec3(2.2)); diffusecolor.a *= color.a; diff --git a/data/shaders/volumetriclight.frag b/data/shaders/volumetriclight.frag index 1a7be4943..e6e303753 100644 --- a/data/shaders/volumetriclight.frag +++ b/data/shaders/volumetriclight.frag @@ -21,7 +21,9 @@ void main() { vec4 diffusecolor = texture(tex, uv); #ifdef Use_Bindless_Texture +#ifdef SRGBBindlessFix diffusecolor.xyz = pow(diffusecolor.xyz, vec3(2.2)); +#endif #endif diffusecolor.xyz *= pow(color.xyz, vec3(2.2)); diffusecolor.a *= color.a; diff --git a/src/graphics/command_buffer.cpp b/src/graphics/command_buffer.cpp index 5c68bab18..15bd9402a 100644 --- a/src/graphics/command_buffer.cpp +++ b/src/graphics/command_buffer.cpp @@ -21,26 +21,36 @@ // ---------------------------------------------------------------------------- template<> -void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataSingleTex &instance) +void InstanceFiller::add(GLMesh* mesh, + const InstanceSettings& is, + InstanceDataSingleTex& instance) { - fillOriginOrientationScale(node, instance); + fillOriginOrientationScale(STK::tuple_get<0>(is), instance); instance.Texture = mesh->TextureHandles[0]; } // ---------------------------------------------------------------------------- template<> -void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataDualTex &instance) +void InstanceFiller::add(GLMesh* mesh, + const InstanceSettings& is, + InstanceDataDualTex& instance) { - fillOriginOrientationScale(node, instance); + fillOriginOrientationScale(STK::tuple_get<0>(is), instance); instance.Texture = mesh->TextureHandles[0]; instance.SecondTexture = mesh->TextureHandles[1]; } // ---------------------------------------------------------------------------- template<> -void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataThreeTex &instance) +void InstanceFiller::add(GLMesh* mesh, + const InstanceSettings& is, + InstanceDataThreeTex& instance) { - fillOriginOrientationScale(node, instance); + fillOriginOrientationScale(STK::tuple_get<0>(is), instance); + instance.MiscData.X = STK::tuple_get<1>(is).X; + instance.MiscData.Y = STK::tuple_get<1>(is).Y; + instance.MiscData.Z = STK::tuple_get<2>(is).X; + instance.MiscData.W = STK::tuple_get<2>(is).Y; instance.Texture = mesh->TextureHandles[0]; instance.SecondTexture = mesh->TextureHandles[1]; instance.ThirdTexture = mesh->TextureHandles[2]; @@ -48,8 +58,28 @@ void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode * // ---------------------------------------------------------------------------- template<> -void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, GlowInstanceData &instance) +void InstanceFiller::add(GLMesh* mesh, + const InstanceSettings& is, + InstanceDataFourTex& instance) { + fillOriginOrientationScale(STK::tuple_get<0>(is), instance); + instance.MiscData.X = STK::tuple_get<1>(is).X; + instance.MiscData.Y = STK::tuple_get<1>(is).Y; + instance.MiscData.Z = STK::tuple_get<2>(is).X; + instance.MiscData.W = STK::tuple_get<2>(is).Y; + instance.Texture = mesh->TextureHandles[0]; + instance.SecondTexture = mesh->TextureHandles[1]; + instance.ThirdTexture = mesh->TextureHandles[2]; + instance.FourthTexture = mesh->TextureHandles[3]; +} + +// ---------------------------------------------------------------------------- +template<> +void InstanceFiller::add(GLMesh* mesh, + const InstanceSettings& is, + GlowInstanceData& instance) +{ + scene::ISceneNode* node = STK::tuple_get<0>(is); fillOriginOrientationScale(node, instance); STKMeshSceneNode *nd = dynamic_cast(node); instance.Color = nd->getGlowColor().color; @@ -142,23 +172,27 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map) mapIndirectBuffer(); std::vector dual_tex_material_list = + createVector(Material::SHADERTYPE_VEGETATION); + + fillInstanceData + (mesh_map, dual_tex_material_list, InstanceTypeDualTex); + + std::vector three_tex_material_list = createVector(Material::SHADERTYPE_SOLID, Material::SHADERTYPE_ALPHA_TEST, Material::SHADERTYPE_SOLID_UNLIT, - Material::SHADERTYPE_SPHERE_MAP, - Material::SHADERTYPE_VEGETATION); - - fillInstanceData - (mesh_map, dual_tex_material_list, InstanceTypeDualTex); - - std::vector three_tex_material_list = - createVector(Material::SHADERTYPE_DETAIL_MAP, - Material::SHADERTYPE_NORMAL_MAP); - + Material::SHADERTYPE_SPHERE_MAP); + fillInstanceData (mesh_map, three_tex_material_list, InstanceTypeThreeTex); - - + + std::vector four_tex_material_list = + createVector(Material::SHADERTYPE_DETAIL_MAP, + Material::SHADERTYPE_NORMAL_MAP); + + fillInstanceData + (mesh_map, four_tex_material_list, InstanceTypeFourTex); + if (!CVS->supportsAsyncInstanceUpload()) glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); } //SolidCommandBuffer::fill diff --git a/src/graphics/command_buffer.hpp b/src/graphics/command_buffer.hpp index 084bb328c..506e882e4 100644 --- a/src/graphics/command_buffer.hpp +++ b/src/graphics/command_buffer.hpp @@ -29,15 +29,17 @@ #include #include +typedef STK::Tuple InstanceSettings; + struct InstanceList { GLMesh *m_mesh; - std::vector m_scene_nodes; + std::vector m_instance_settings; }; typedef std::unordered_map , InstanceList, MeshRenderInfoHash, MeshRenderInfoEquals> SolidPassMeshMap; - + typedef std::unordered_map OtherMeshMap; // ---------------------------------------------------------------------------- @@ -67,7 +69,7 @@ void fillOriginOrientationScale(scene::ISceneNode *node, InstanceData &instance) template struct InstanceFiller { - static void add(GLMesh *, scene::ISceneNode *, InstanceData &); + static void add(GLMesh *, const InstanceSettings&, InstanceData &); }; // ---------------------------------------------------------------------------- @@ -82,7 +84,7 @@ struct InstanceFiller * \param[in,out] poly_count Number of triangles. Will be updated. */ template -void FillInstances_impl(InstanceList instance_list, +void FillInstances_impl(const InstanceList& instance_list, T * instance_buffer, DrawElementsIndirectCommand *command_buffer, size_t &instance_buffer_offset, @@ -93,11 +95,11 @@ void FillInstances_impl(InstanceList instance_list, GLMesh *mesh = instance_list.m_mesh; 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::add(mesh, node, instance_buffer[instance_buffer_offset++]); - assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataDualTex)); + InstanceFiller::add(mesh, instance_list.m_instance_settings[i], + instance_buffer[instance_buffer_offset++]); + assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataThreeTex)); } DrawElementsIndirectCommand &CurrentCommand = command_buffer[command_buffer_offset++]; @@ -227,7 +229,7 @@ protected: VAOManager::getInstance()->getInstanceBuffer(instance_type)); instance_buffer = (InstanceData*) glMapBufferRange(GL_ARRAY_BUFFER, 0, - 10000 * sizeof(InstanceDataDualTex), + 10000 * sizeof(InstanceDataThreeTex), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); } @@ -305,8 +307,7 @@ public: (const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand))); if (!mesh->mb->getMaterial().BackfaceCulling) glEnable(GL_CULL_FACE); - } - + } } //drawIndirectFirstPass // ---------------------------------------------------------------------------- @@ -356,19 +357,6 @@ public: { GLMesh *mesh = m_meshes[T::MaterialType][i]; expandTexSecondPass(*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) glDisable(GL_CULL_FACE); glDrawElementsIndirect(GL_TRIANGLES, @@ -376,11 +364,6 @@ public: (const void*)((m_offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand))); if (!mesh->mb->getMaterial().BackfaceCulling) glEnable(GL_CULL_FACE); - if (need_change_hue) - { - // Reset after changing - T::InstancedSecondPassShader::getInstance()->changeableColor(); - } } } //drawIndirectSecondPass diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index c6a52db7d..724ad0732 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -211,18 +211,18 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, tmpcol.getBlue() / 255.0f); for (GLMesh *mesh : node->TransparentMesh[TM_DEFAULT]) - pushVector(ListBlendTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, + pushVector(ListBlendTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, fogmax, startH, endH, start, end, col); for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE]) - pushVector(ListAdditiveTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, + pushVector(ListAdditiveTransparentFog::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, fogmax, startH, endH, start, end, col); } else { for (GLMesh *mesh : node->TransparentMesh[TM_DEFAULT]) - pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f); + pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, 1.0f); for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE]) - pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f); + pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, 1.0f); } // Use sun color to determine custom alpha for ghost karts @@ -235,11 +235,11 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, } for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_STD]) - pushVector(ListTranslucentStandard::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha); + pushVector(ListTranslucentStandard::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha); for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_TAN]) - pushVector(ListTranslucentTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha); + pushVector(ListTranslucentTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha); for (GLMesh *mesh : node->TransparentMesh[TM_TRANSLUCENT_2TC]) - pushVector(ListTranslucent2TCoords::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha); + pushVector(ListTranslucent2TCoords::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->texture_trans, custom_alpha); for (GLMesh *mesh : node->TransparentMesh[TM_DISPLACEMENT]) pushVector(ListDisplacement::getInstance(), mesh, Node->getAbsoluteTransformation()); @@ -254,53 +254,27 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, if (node->glow()) { 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 && mesh->TextureMatrix.isIdentity()) + if (Mat == Material::SHADERTYPE_SPLATTING) { - std::pair meshRenderInfo(mesh->mb, mesh->m_render_info); - m_solid_pass_mesh[Mat][meshRenderInfo].m_mesh = mesh; - m_solid_pass_mesh[Mat][meshRenderInfo].m_scene_nodes.emplace_back(Node); + //TODO: write instanced splatting solid shader and remove this if + core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; + ModelMatrix.getInverse(InvModelMatrix); + ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix); } else { - core::matrix4 ModelMatrix = Node->getAbsoluteTransformation(), InvModelMatrix; - ModelMatrix.getInverse(InvModelMatrix); - switch (Mat) - { - case Material::SHADERTYPE_SOLID: - ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, - (mesh->m_render_info && mesh->m_material ? - core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : - core::vector2df(0.0f, 0.0f))); - break; - case Material::SHADERTYPE_ALPHA_TEST: - ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); - break; - case Material::SHADERTYPE_SOLID_UNLIT: - ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); - 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); - } + // Only take render info into account if the node is not static (animated) + // So they can have different animation + std::pair mesh_render_info(mesh->mb, + dynamic_cast(Node) == NULL ? mesh->m_render_info : NULL); + m_solid_pass_mesh[Mat][mesh_render_info].m_mesh = mesh; + m_solid_pass_mesh[Mat][mesh_render_info].m_instance_settings.emplace_back(Node, mesh->texture_trans, + (mesh->m_render_info && mesh->m_material ? + core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : + core::vector2df(0.0f, 0.0f))); } } } @@ -314,28 +288,28 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, switch (Mat) { case Material::SHADERTYPE_SOLID: - ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, + ListMatDefault::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, (mesh->m_render_info && mesh->m_material ? core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : core::vector2df(0.0f, 0.0f))); break; case Material::SHADERTYPE_ALPHA_TEST: - ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatAlphaRef::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_NORMAL_MAP: - ListMatNormalMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, + ListMatNormalMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, (mesh->m_render_info && mesh->m_material ? core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : core::vector2df(0.0f, 0.0f))); break; case Material::SHADERTYPE_DETAIL_MAP: - ListMatDetails::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatDetails::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->TextureMatrix); + ListMatUnlit::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPHERE_MAP: - ListMatSphereMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatSphereMap::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPLATTING: ListMatSplatting::getInstance()->SolidPass.emplace_back(mesh, ModelMatrix, InvModelMatrix); @@ -369,7 +343,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, 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_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 @@ -382,22 +357,22 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, switch (Mat) { case Material::SHADERTYPE_SOLID: - ListMatDefault::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, core::vector2df(0.0f, 0.0f)); + ListMatDefault::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f)); break; case Material::SHADERTYPE_ALPHA_TEST: - ListMatAlphaRef::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatAlphaRef::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_NORMAL_MAP: - ListMatNormalMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, core::vector2df(0.0f, 0.0f)); + ListMatNormalMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f)); break; case Material::SHADERTYPE_DETAIL_MAP: - ListMatDetails::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatDetails::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SOLID_UNLIT: - ListMatUnlit::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatUnlit::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPHERE_MAP: - ListMatSphereMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatSphereMap::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPLATTING: ListMatSplatting::getInstance()->Shadows[cascade].emplace_back(mesh, ModelMatrix, InvModelMatrix); @@ -425,21 +400,20 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, { 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; ModelMatrix.getInverse(InvModelMatrix); ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix); } - } - else - { - for (GLMesh *mesh : node->MeshSolidMaterial[Mat]) + else { 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)); } } } @@ -453,22 +427,22 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, switch (Mat) { case Material::SHADERTYPE_SOLID: - ListMatDefault::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, core::vector2df(0.0f, 0.0f)); + ListMatDefault::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f)); break; case Material::SHADERTYPE_ALPHA_TEST: - ListMatAlphaRef::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatAlphaRef::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_NORMAL_MAP: - ListMatNormalMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix, core::vector2df(0.0f, 0.0f)); + ListMatNormalMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans, core::vector2df(0.0f, 0.0f)); break; case Material::SHADERTYPE_DETAIL_MAP: - ListMatDetails::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatDetails::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SOLID_UNLIT: - ListMatUnlit::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatUnlit::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPHERE_MAP: - ListMatSphereMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->TextureMatrix); + ListMatSphereMap::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix, mesh->texture_trans); break; case Material::SHADERTYPE_SPLATTING: ListMatSplatting::getInstance()->RSM.emplace_back(mesh, ModelMatrix, InvModelMatrix); diff --git a/src/graphics/draw_policies.cpp b/src/graphics/draw_policies.cpp index cddd3ebdf..5971dd9fd 100644 --- a/src/graphics/draw_policies.cpp +++ b/src/graphics/draw_policies.cpp @@ -198,13 +198,8 @@ void GL3DrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls, void IndirectDrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const { #if !defined(USE_GLES2) - //TODO: find a way to add TextureMarix in instanced shaders, - //and remove these four lines - renderMeshes1stPass(); + //TODO: add instanced splatting solid shader renderMeshes1stPass(); - renderMeshes1stPass(); - renderMeshes1stPass(); - draw_calls.drawIndirectSolidFirstPass(); #endif //!defined(USE_GLES2) } @@ -215,13 +210,8 @@ void IndirectDrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls, const std::vector& prefilled_tex) const { #if !defined(USE_GLES2) - //TODO: find a way to add TextureMatrix in instanced shaders, - //and remove these four lines - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - + //TODO: add instanced splatting solid shader + renderMeshes2ndPass (handles, prefilled_tex); draw_calls.drawIndirectSolidSecondPass(prefilled_tex); #endif //!defined(USE_GLES2) } @@ -271,13 +261,8 @@ void IndirectDrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls, void MultidrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const { #if !defined(USE_GLES2) - //TODO: find a way to add TextureMarix in instanced shaders, - //and remove these four lines - renderMeshes1stPass(); + //TODO: add instanced splatting solid shader renderMeshes1stPass(); - renderMeshes1stPass(); - renderMeshes1stPass(); - draw_calls.multidrawSolidFirstPass(); #endif //!defined(USE_GLES2) } @@ -288,13 +273,8 @@ void MultidrawPolicy::drawSolidSecondPass (const DrawCalls& draw_calls, const std::vector& prefilled_tex) const { #if !defined(USE_GLES2) - //TODO: find a way to add TextureMarix in instanced shaders, - //and remove these four lines - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - renderMeshes2ndPass (handles, prefilled_tex); - + //TODO: add instanced splatting solid shader + renderMeshes2ndPass (handles, prefilled_tex); draw_calls.multidrawSolidSecondPass(handles); #endif //!defined(USE_GLES2) } diff --git a/src/graphics/geometry_passes.cpp b/src/graphics/geometry_passes.cpp index 63c29a48c..268c88780 100644 --- a/src/graphics/geometry_passes.cpp +++ b/src/graphics/geometry_passes.cpp @@ -179,23 +179,15 @@ AbstractGeometryPasses::AbstractGeometryPasses() } // ---------------------------------------------------------------------------- -void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector& prefilled_textures) +void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector& prefilled_textures, + const std::vector& prefilled_handles) { m_prefilled_textures = prefilled_textures; #if !defined(USE_GLES2) if (CVS->isAZDOEnabled()) { - m_textures_handles.clear(); - for(size_t i=0;im_sampler_ids[i]); - if (!glIsTextureHandleResidentARB(handle)) - glMakeTextureHandleResidentARB(handle); - m_textures_handles.push_back(handle); - } + m_textures_handles = prefilled_handles; } #endif // !defined(USE_GLES2) } diff --git a/src/graphics/geometry_passes.hpp b/src/graphics/geometry_passes.hpp index 80e6836a1..70d450a4c 100644 --- a/src/graphics/geometry_passes.hpp +++ b/src/graphics/geometry_passes.hpp @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // -// You should have received a copy éof the GNU General Public License +// You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -45,7 +45,8 @@ public: AbstractGeometryPasses(); virtual ~AbstractGeometryPasses(){} - void setFirstPassRenderTargets(const std::vector& prefilled_textures); + void setFirstPassRenderTargets(const std::vector& prefilled_textures, + const std::vector& prefilled_handles); virtual void renderSolidFirstPass(const DrawCalls& draw_calls) const = 0; diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index eaae8118a..8d6221a6c 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -698,7 +698,7 @@ void IrrDriver::createSunInterposer() getUnicolorTexture(video::SColor(255, 255, 255, 255))); mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - mb->getMaterial().setTexture(7, + mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); } m_sun_interposer = new STKMeshSceneNode(sphere, @@ -1141,7 +1141,7 @@ scene::IMeshSceneNode *IrrDriver::addSphere(float radius, //m.setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180))); m.setTexture(0, getUnicolorTexture(color)); m.setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - m.setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + m.setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); if (CVS->isGLSL()) { diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index 0737b9523..d89d4d6ac 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -733,7 +733,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m glossytex = getUnicolorTexture(SColor(0, 0, 0, 0)); } - if (!m->getTexture(7)) + if (!m->getTexture(2)) { // Only set colorization mask if not set ITexture *colorization_mask_tex = getUnicolorTexture(SColor(0, 0, 0, 0)); @@ -741,7 +741,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m { colorization_mask_tex = irr_driver->getTexture(m_colorization_mask); } - m->setTexture(7, colorization_mask_tex); + m->setTexture(2, colorization_mask_tex); } @@ -796,26 +796,26 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m return; case SHADERTYPE_SPLATTING: tex = irr_driver->getTexture(m_splatting_texture_1); - m->setTexture(2, tex); + m->setTexture(3, tex); if (m_splatting_texture_2.size() > 0) { tex = irr_driver->getTexture(m_splatting_texture_2); } - m->setTexture(3, tex); + m->setTexture(4, tex); if (m_splatting_texture_3.size() > 0) { tex = irr_driver->getTexture(m_splatting_texture_3); } - m->setTexture(4, tex); + m->setTexture(5, tex); if (m_splatting_texture_4.size() > 0) { tex = irr_driver->getTexture(m_splatting_texture_4); } - m->setTexture(5, tex); - m->setTexture(6, glossytex); + m->setTexture(6, tex); + m->setTexture(7, glossytex); // Material and shaders m->MaterialType = Shaders::getShader(ES_SPLATTING); @@ -850,7 +850,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m if (m_normal_map_tex.size() > 0) { tex = irr_driver->getTexture(m_normal_map_tex); - m->setTexture(2, tex); + m->setTexture(3, tex); // Material and shaders m->MaterialType = Shaders::getShader(ES_NORMAL_MAP); @@ -863,9 +863,9 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m if (mb && mb->getVertexType() == video::EVT_2TCOORDS) { if (m->getTexture(1) != glossytex) - m->setTexture(2, m->getTexture(1)); - if (!m->getTexture(2)) - m->setTexture(2, getUnicolorTexture(SColor(255, 255, 255, 255))); + m->setTexture(3, m->getTexture(1)); + if (!m->getTexture(3)) + m->setTexture(3, getUnicolorTexture(SColor(255, 255, 255, 255))); } m->setTexture(1, glossytex); } diff --git a/src/graphics/materials.cpp b/src/graphics/materials.cpp index 35ed9be0b..8a232ce2d 100644 --- a/src/graphics/materials.cpp +++ b/src/graphics/materials.cpp @@ -20,7 +20,7 @@ const STK::Tuple DefaultMaterial::FirstPassTextures = STK::Tuple(1); const STK::Tuple DefaultMaterial::SecondPassTextures - = STK::Tuple(0, 1, 7); + = STK::Tuple(0, 1, 2); const STK::Tuple<> DefaultMaterial::ShadowTextures; const STK::Tuple DefaultMaterial::RSMTextures = STK::Tuple(0); @@ -55,24 +55,24 @@ const STK::Tuple GrassMat::RSMTextures = STK::Tuple(0); // ---------------------------------------------------------------------------- const STK::Tuple NormalMat::FirstPassTextures - = STK::Tuple(2, 1); + = STK::Tuple(3, 1); const STK::Tuple NormalMat::SecondPassTextures - = STK::Tuple(0, 1, 7); + = STK::Tuple(0, 1, 2); const STK::Tuple<> NormalMat::ShadowTextures; const STK::Tuple NormalMat::RSMTextures = STK::Tuple(0); // ---------------------------------------------------------------------------- const STK::Tuple DetailMat::FirstPassTextures = STK::Tuple(1); const STK::Tuple DetailMat::SecondPassTextures - = STK::Tuple(0, 2, 1); + = STK::Tuple(0, 3, 1); const STK::Tuple<> DetailMat::ShadowTextures; const STK::Tuple DetailMat::RSMTextures = STK::Tuple(0); // ---------------------------------------------------------------------------- -const STK::Tuple SplattingMat::FirstPassTextures = STK::Tuple(6); +const STK::Tuple SplattingMat::FirstPassTextures = STK::Tuple(7); const STK::Tuple SplattingMat::SecondPassTextures - = STK::Tuple(1, 2, 3, 4, 5); + = STK::Tuple(1, 3, 4, 5, 6); const STK::Tuple<> SplattingMat::ShadowTextures; const STK::Tuple SplattingMat::RSMTextures - = STK::Tuple(1, 2, 3, 4, 5); + = STK::Tuple(1, 3, 4, 5, 6); diff --git a/src/graphics/materials.hpp b/src/graphics/materials.hpp index 9f34a01f2..99e5d7cea 100644 --- a/src/graphics/materials.hpp +++ b/src/graphics/materials.hpp @@ -56,14 +56,14 @@ public: // ============================================================================ class ObjectRefPass2Shader : public TextureShader + core::matrix4, core::vector2df> { public: ObjectRefPass2Shader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "objectref_pass2.frag"); - assignUniforms("ModelMatrix", "TextureMatrix"); + assignUniforms("ModelMatrix", "texture_trans"); assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED, 1, "SpecularMap", ST_NEAREST_FILTERED, 2, "SSAO", ST_BILINEAR_FILTERED, @@ -75,15 +75,11 @@ public: // ============================================================================ class InstancedObjectPass2Shader : public TextureShader { -private: - GLint m_color_change_location; - public: InstancedObjectPass2Shader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_object_pass.vert", GL_FRAGMENT_SHADER, "instanced_object_pass2.frag"); - m_color_change_location = glGetUniformLocation(m_program, "color_change"); assignUniforms(); assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED, 1, "SpecularMap", ST_NEAREST_FILTERED, @@ -92,12 +88,6 @@ public: 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED, 5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // 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 // ============================================================================ @@ -172,7 +162,7 @@ public: }; // InstancedShadowShader // ============================================================================ -class CRSMShader : public TextureShader { public: @@ -181,7 +171,7 @@ public: loadProgram(OBJECT, GL_VERTEX_SHADER, "rsm.vert", GL_FRAGMENT_SHADER, "rsm.frag"); - assignUniforms("ModelMatrix", "TextureMatrix", "RSMMatrix"); + assignUniforms("ModelMatrix", "texture_trans", "RSMMatrix"); assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // CRSMShader }; // CRSMShader @@ -278,14 +268,14 @@ public: // ============================================================================ class ObjectRefPass1Shader : public TextureShader + core::matrix4, core::vector2df> { public: ObjectRefPass1Shader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "objectref_pass1.frag"); - assignUniforms("ModelMatrix", "InverseModelMatrix", "TextureMatrix"); + assignUniforms("ModelMatrix", "InverseModelMatrix", "texture_trans"); assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, 1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // ObjectRefPass1Shader @@ -324,14 +314,14 @@ public: // ============================================================================ class ObjectUnlitShader : public TextureShader + core::vector2df> { public: ObjectUnlitShader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "object_unlit.frag"); - assignUniforms("ModelMatrix", "TextureMatrix"); + assignUniforms("ModelMatrix", "texture_trans"); assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED, 1, "SpecularMap", ST_NEAREST_FILTERED, 2, "SSAO", ST_BILINEAR_FILTERED, @@ -636,7 +626,7 @@ struct DefaultMaterial static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_SOLID; - static const enum InstanceType Instance = InstanceTypeDualTex; + static const enum InstanceType Instance = InstanceTypeThreeTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple<> ShadowTextures; @@ -657,7 +647,7 @@ struct AlphaRef typedef ListMatAlphaRef List; static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_ALPHA_TEST; - static const enum InstanceType Instance = InstanceTypeDualTex; + static const enum InstanceType Instance = InstanceTypeThreeTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple ShadowTextures; @@ -679,7 +669,7 @@ struct SphereMap static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_SPHERE_MAP; - static const enum InstanceType Instance = InstanceTypeDualTex; + static const enum InstanceType Instance = InstanceTypeThreeTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple<> ShadowTextures; @@ -701,7 +691,7 @@ struct UnlitMat static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_SOLID_UNLIT; - static const enum InstanceType Instance = InstanceTypeDualTex; + static const enum InstanceType Instance = InstanceTypeThreeTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple ShadowTextures; @@ -745,7 +735,7 @@ struct NormalMat static const enum video::E_VERTEX_TYPE VertexType = video::EVT_TANGENTS; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_NORMAL_MAP; - static const enum InstanceType Instance = InstanceTypeThreeTex; + static const enum InstanceType Instance = InstanceTypeFourTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple<> ShadowTextures; @@ -767,7 +757,7 @@ struct DetailMat static const enum video::E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; static const enum Material::ShaderType MaterialType = Material::SHADERTYPE_DETAIL_MAP; - static const enum InstanceType Instance = InstanceTypeThreeTex; + static const enum InstanceType Instance = InstanceTypeFourTex; static const STK::Tuple FirstPassTextures; static const STK::Tuple SecondPassTextures; static const STK::Tuple<> ShadowTextures; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 62271c56a..f22d583c5 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -20,6 +20,7 @@ #include "config/user_config.hpp" #include "graphics/central_settings.hpp" #include "graphics/glwrap.hpp" +#include "graphics/shaders.hpp" #include "utils/log.hpp" static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type, unsigned mipmaplevel = 1) @@ -291,11 +292,39 @@ RTT::RTT(size_t width, size_t height) glClearColor(.5, .5, .5, .5); glClear(GL_COLOR_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, 0); + if (CVS->isAZDOEnabled()) + { + uint64_t handle = + glGetTextureSamplerHandleARB(getRenderTarget(RTT_DIFFUSE), + Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]); + glMakeTextureHandleResidentARB(handle); + m_prefilled_handles.push_back(handle); + handle = + glGetTextureSamplerHandleARB(getRenderTarget(RTT_SPECULAR), + Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[1]); + glMakeTextureHandleResidentARB(handle); + m_prefilled_handles.push_back(handle); + handle = + glGetTextureSamplerHandleARB(getRenderTarget(RTT_HALF1_R), + Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[2]); + glMakeTextureHandleResidentARB(handle); + m_prefilled_handles.push_back(handle); + handle = + glGetTextureSamplerHandleARB(getDepthStencilTexture(), + Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[3]); + glMakeTextureHandleResidentARB(handle); + m_prefilled_handles.push_back(handle); + } } RTT::~RTT() { glBindFramebuffer(GL_FRAMEBUFFER, 0); + if (CVS->isAZDOEnabled()) + { + for (uint64_t& handle : m_prefilled_handles) + glMakeTextureHandleNonResidentARB(handle); + } glDeleteTextures(RTT_COUNT, RenderTargetTextures); glDeleteTextures(1, &DepthStencilTexture); if (CVS->isShadowEnabled()) diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 4c19bbb00..f5102ff00 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -18,8 +18,9 @@ #ifndef HEADER_RTTS_HPP #define HEADER_RTTS_HPP -#include "utils/ptr_vector.hpp" #include "utils/leak_check.hpp" +#include "utils/ptr_vector.hpp" +#include "utils/types.hpp" #include class FrameBuffer; @@ -156,10 +157,12 @@ public: unsigned getDepthStencilTexture() const { return DepthStencilTexture; } unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; } FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; } + const std::vector& getPrefilledHandles() { return m_prefilled_handles; } private: unsigned RenderTargetTextures[RTT_COUNT]; PtrVector FrameBuffers; + std::vector m_prefilled_handles; unsigned DepthStencilTexture; size_t m_width; diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 3b755a9f1..ff56248ff 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -53,7 +53,8 @@ void ShaderBasedRenderer::setRTT(RTT* rtts) rtts->getRenderTarget(RTT_SPECULAR), rtts->getRenderTarget(RTT_HALF1_R), rtts->getDepthStencilTexture()); - m_geometry_passes->setFirstPassRenderTargets(prefilled_textures); + m_geometry_passes->setFirstPassRenderTargets(prefilled_textures, + rtts->getPrefilledHandles()); m_rtts = rtts; } else if (rtts == NULL) @@ -361,8 +362,8 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, m_rtts->getReflectiveShadowMapFrameBuffer()); } - m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind(); - glClear(GL_COLOR_BUFFER_BIT); + m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind(); + glClear(GL_COLOR_BUFFER_BIT); m_rtts->getFBO(FBO_DIFFUSE).bind(); if (CVS->isGlobalIlluminationEnabled() && hasShadow) @@ -718,7 +719,7 @@ void ShaderBasedRenderer::addSkyBox(const std::vector &texture if(spherical_harmonics_textures.size() == 6) { m_spherical_harmonics->setTextures(spherical_harmonics_textures); - } + } } // ---------------------------------------------------------------------------- @@ -750,7 +751,7 @@ GLuint ShaderBasedRenderer::getDepthStencilTexture() const void ShaderBasedRenderer::setAmbientLight(const video::SColorf &light, bool force_SH_computation) { - if(!m_spherical_harmonics->has6Textures() || force_SH_computation) + if (force_SH_computation) m_spherical_harmonics->setAmbientLight(light.toSColor()); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index beab50c00..a531c5cd9 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -350,7 +350,7 @@ Shaders::ObjectPass2Shader::ObjectPass2Shader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "object_pass2.frag"); - assignUniforms("ModelMatrix", "TextureMatrix", "color_change"); + assignUniforms("ModelMatrix", "texture_trans", "color_change"); assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED, 1, "SpecularMap", ST_NEAREST_FILTERED, 2, "SSAO", ST_BILINEAR_FILTERED, @@ -364,7 +364,7 @@ Shaders::TransparentShader::TransparentShader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "transparent.frag"); - assignUniforms("ModelMatrix", "TextureMatrix", "custom_alpha"); + assignUniforms("ModelMatrix", "texture_trans", "custom_alpha"); assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // TransparentShader @@ -373,7 +373,7 @@ Shaders::TransparentFogShader::TransparentFogShader() { loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "transparentfog.frag"); - assignUniforms("ModelMatrix", "TextureMatrix", "fogmax", "startH", + assignUniforms("ModelMatrix", "texture_trans", "fogmax", "startH", "endH", "start", "end", "col"); assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // TransparentFogShader diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 242d602db..33a0094c2 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -120,7 +120,7 @@ public: // ======================================================================== class TransparentShader : public TextureShader { public: @@ -129,7 +129,7 @@ public: // ======================================================================== class TransparentFogShader : public TextureShader { public: @@ -145,7 +145,7 @@ public: // ======================================================================== class ObjectPass2Shader : public TextureShader < ObjectPass2Shader, 6, - core::matrix4, core::matrix4, + core::matrix4, core::vector2df, core::vector2df > { public: diff --git a/src/graphics/show_curve.cpp b/src/graphics/show_curve.cpp index 60601ddac..39eea68b7 100644 --- a/src/graphics/show_curve.cpp +++ b/src/graphics/show_curve.cpp @@ -67,7 +67,7 @@ void ShowCurve::addEmptyMesh() m_buffer = m_mesh->getMeshBuffer(0); m_buffer->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180))); m_buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - m_buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + m_buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); assert(m_buffer->getVertexType()==video::EVT_STANDARD); } // addEmptyMesh diff --git a/src/graphics/stk_animated_mesh.cpp b/src/graphics/stk_animated_mesh.cpp index 1697acf18..d51bd8698 100644 --- a/src/graphics/stk_animated_mesh.cpp +++ b/src/graphics/stk_animated_mesh.cpp @@ -186,10 +186,18 @@ void STKAnimatedMesh::updateNoGL() for (u32 i = 0; i < m->getMeshBufferCount(); ++i) { scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); - if (!mb) - continue; - if (mb) - GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0); + if (mb != NULL) + { + // Test if texture matrix needs to be updated every frame + const core::matrix4& mat = getMaterial(i).getTextureMatrix(0); + if (mat.isIdentity()) + continue; + else + { + GLmeshes[i].texture_trans.X = mat[8]; + GLmeshes[i].texture_trans.Y = mat[9]; + } + } } } diff --git a/src/graphics/stk_mesh.cpp b/src/graphics/stk_mesh.cpp index 35dd33fa9..abf445998 100644 --- a/src/graphics/stk_mesh.cpp +++ b/src/graphics/stk_mesh.cpp @@ -233,7 +233,7 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name, } for (unsigned i = 0; i < 8; i++) result.textures[i] = mb->getMaterial().getTexture(i); - result.TextureMatrix = 0; + result.texture_trans = core::vector2df(0.0f, 0.0f); result.VAOType = mb->getVertexType(); return result; } // allocateMeshBuffer @@ -363,7 +363,10 @@ static void setTexture(GLMesh &mesh, unsigned i, bool is_srgb, Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); } if (!glIsTextureHandleResidentARB(mesh.TextureHandles[i])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[i]); + insertTextureHandle(mesh.TextureHandles[i]); + } } #endif } // setTexture @@ -399,19 +402,24 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat) switch (mat) { 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_ALPHA_TEST: - case Material::SHADERTYPE_VEGETATION: case Material::SHADERTYPE_SPHERE_MAP: case Material::SHADERTYPE_SOLID_UNLIT: setTexture(mesh, 0, true, getShaderTypeName(mat)); setTexture(mesh, 1, false, getShaderTypeName(mat)); + setTexture(mesh, 2, false, getShaderTypeName(mat)); break; case Material::SHADERTYPE_DETAIL_MAP: case Material::SHADERTYPE_NORMAL_MAP: setTexture(mesh, 0, true, getShaderTypeName(mat)); setTexture(mesh, 1, false, getShaderTypeName(mat)); setTexture(mesh, 2, false, getShaderTypeName(mat)); + setTexture(mesh, 3, false, getShaderTypeName(mat)); break; case Material::SHADERTYPE_SPLATTING: setTexture(mesh, 0, true, getShaderTypeName(mat)); @@ -421,6 +429,7 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat) setTexture(mesh, 4, true, getShaderTypeName(mat)); setTexture(mesh, 5, true, getShaderTypeName(mat)); setTexture(mesh, 6, false, getShaderTypeName(mat)); + setTexture(mesh, 7, false, getShaderTypeName(mat)); break; } } // initTextures @@ -443,7 +452,10 @@ void initTexturesTransparent(GLMesh &mesh) Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); } if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + insertTextureHandle(mesh.TextureHandles[0]); + } } #endif } // initTexturesTransparent diff --git a/src/graphics/stk_mesh.hpp b/src/graphics/stk_mesh.hpp index 5d72f6b0b..ed405acd8 100644 --- a/src/graphics/stk_mesh.hpp +++ b/src/graphics/stk_mesh.hpp @@ -53,11 +53,11 @@ struct GLMesh GLenum IndexType; size_t IndexCount; size_t Stride; - core::matrix4 TextureMatrix; + core::vector2df texture_trans; size_t vaoBaseVertex; size_t vaoOffset; video::E_VERTEX_TYPE VAOType; - uint64_t TextureHandles[6]; + uint64_t TextureHandles[8]; scene::IMeshBuffer *mb; RenderInfo* m_render_info; Material* m_material; @@ -112,18 +112,18 @@ public: // ---------------------------------------------------------------------------- class ListMatDefault : public MeshList {}; // ---------------------------------------------------------------------------- class ListMatAlphaRef : public MeshList + core::matrix4, core::vector2df> {}; // ---------------------------------------------------------------------------- class ListMatNormalMap : public MeshList {}; @@ -135,7 +135,7 @@ class ListMatGrass : public MeshList + core::vector2df> {}; // ---------------------------------------------------------------------------- @@ -145,12 +145,12 @@ class ListMatSplatting : public MeshList + core::matrix4, core::vector2df> {}; // ---------------------------------------------------------------------------- class ListMatDetails : public MeshList + core::matrix4, core::vector2df> {}; // ---------------------------------------------------------------------------- @@ -161,38 +161,38 @@ class MiscList : public Singleton, public std::vector > // ---------------------------------------------------------------------------- class ListBlendTransparent : public MiscList {}; // ---------------------------------------------------------------------------- class ListAdditiveTransparent : public MiscList + core::vector2df, float> {}; // ---------------------------------------------------------------------------- class ListTranslucentStandard : public MiscList + core::vector2df, float> {}; // ---------------------------------------------------------------------------- class ListTranslucentTangents : public MiscList + core::vector2df, float> {}; // ---------------------------------------------------------------------------- class ListTranslucent2TCoords : public MiscList + core::vector2df, float> {}; // ---------------------------------------------------------------------------- class ListBlendTransparentFog : public MiscList {}; @@ -200,7 +200,7 @@ class ListBlendTransparentFog : public MiscList {}; diff --git a/src/graphics/stk_mesh_scene_node.cpp b/src/graphics/stk_mesh_scene_node.cpp index 718b01c36..d2b3244e8 100644 --- a/src/graphics/stk_mesh_scene_node.cpp +++ b/src/graphics/stk_mesh_scene_node.cpp @@ -238,9 +238,18 @@ void STKMeshSceneNode::updateNoGL() for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); - if (!mb) - continue; - GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0); + if (mb != NULL) + { + // Test if texture matrix needs to be updated every frame + const core::matrix4& mat = getMaterial(i).getTextureMatrix(0); + if (mat.isIdentity()) + continue; + else + { + GLmeshes[i].texture_trans.X = mat[8]; + GLmeshes[i].texture_trans.Y = mat[9]; + } + } } } @@ -363,7 +372,10 @@ void STKMeshSceneNode::render() ::getInstance()->m_sampler_ids[0]); } if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + insertTextureHandle(mesh.TextureHandles[0]); + } Shaders::ObjectPass1Shader::getInstance()->setTextureHandles(mesh.TextureHandles[0]); } else @@ -416,23 +428,32 @@ void STKMeshSceneNode::render() if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), - Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]); + Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + insertTextureHandle(mesh.TextureHandles[0]); + } if (!mesh.TextureHandles[1]) mesh.TextureHandles[1] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[1]), - Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]); + Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[1])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[1]); + insertTextureHandle(mesh.TextureHandles[1]); + } if (!mesh.TextureHandles[2]) mesh.TextureHandles[2] = - glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[7]), - Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[0]); + glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[2]), + Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[2])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[2]); + insertTextureHandle(mesh.TextureHandles[2]); + } Shaders::ObjectPass2Shader::getInstance() ->setTextureHandles(DiffuseHandle, SpecularHandle, SSAOHandle, @@ -447,9 +468,9 @@ void STKMeshSceneNode::render() irr_driver->getRenderTargetTexture(RTT_HALF1_R), getTextureGLuint(mesh.textures[0]), getTextureGLuint(mesh.textures[1]), - getTextureGLuint(mesh.textures[7])); + getTextureGLuint(mesh.textures[2])); Shaders::ObjectPass2Shader::getInstance()->setUniforms(AbsoluteTransformation, - mesh.TextureMatrix, + mesh.texture_trans, core::vector2df(0.0f, 0.0f)); assert(mesh.vao); glBindVertexArray(mesh.vao); @@ -521,9 +542,12 @@ void STKMeshSceneNode::render() if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), - Shaders::TransparentFogShader::getInstance()->m_sampler_ids[0]); + Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + insertTextureHandle(mesh.TextureHandles[0]); + } Shaders::TransparentFogShader::getInstance() ->setTextureHandles(mesh.TextureHandles[0]); } @@ -534,7 +558,7 @@ void STKMeshSceneNode::render() ->setTextureUnits(getTextureGLuint(mesh.textures[0])); } Shaders::TransparentFogShader::getInstance() - ->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, + ->setUniforms(AbsoluteTransformation, mesh.texture_trans, fogmax, startH, endH, start, end, col); assert(mesh.vao); @@ -561,16 +585,19 @@ void STKMeshSceneNode::render() if (!mesh.TextureHandles[0]) mesh.TextureHandles[0] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[0]), - Shaders::TransparentShader::getInstance()->m_sampler_ids[0]); + Shaders::ObjectPass1Shader::getInstance()->m_sampler_ids[0]); if (!glIsTextureHandleResidentARB(mesh.TextureHandles[0])) + { glMakeTextureHandleResidentARB(mesh.TextureHandles[0]); + insertTextureHandle(mesh.TextureHandles[0]); + } Shaders::TransparentShader::getInstance()->setTextureHandles(mesh.TextureHandles[0]); } else #endif Shaders::TransparentShader::getInstance()->setTextureUnits(getTextureGLuint(mesh.textures[0])); - Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, 1.0f); + Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.texture_trans, 1.0f); assert(mesh.vao); glBindVertexArray(mesh.vao); glDrawElements(ptype, count, itype, 0); diff --git a/src/graphics/stk_text_billboard.cpp b/src/graphics/stk_text_billboard.cpp index 1ede26873..b99f4500b 100644 --- a/src/graphics/stk_text_billboard.cpp +++ b/src/graphics/stk_text_billboard.cpp @@ -122,7 +122,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, FontWithFace* fo buffer = new scene::SMeshBuffer(); buffer->getMaterial().setTexture(0, m_chars[i].m_texture); buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); buffer->getMaterial().MaterialType = Shaders::getShader(ES_OBJECT_UNLIT); buffers[m_chars[i].m_texture] = buffer; } diff --git a/src/graphics/texture_manager.cpp b/src/graphics/texture_manager.cpp index 7047446cd..25d03bb3b 100644 --- a/src/graphics/texture_manager.cpp +++ b/src/graphics/texture_manager.cpp @@ -19,6 +19,7 @@ #include "graphics/central_settings.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/shaders.hpp" #if defined(USE_GLES2) #define _IRR_COMPILE_WITH_OGLES2_ @@ -55,12 +56,28 @@ GLuint getDepthTexture(irr::video::ITexture *tex) static std::set AlreadyTransformedTexture; static std::map unicolor_cache; +static std::vector texture_handles; void resetTextureTable() { + if (CVS->isAZDOEnabled()) + { + // Driver seems to crash if texture handles are not cleared... + for (uint64_t& handle : texture_handles) + { + glMakeTextureHandleNonResidentARB(handle); + } + Shaders::ObjectPass1Shader::getInstance()->recreateTrilinearSampler(0); + texture_handles.clear(); + } AlreadyTransformedTexture.clear(); } +void insertTextureHandle(uint64_t handle) +{ + texture_handles.push_back(handle); +} + void cleanUnicolorTextures() { for (std::pair& uc : unicolor_cache) diff --git a/src/graphics/texture_manager.hpp b/src/graphics/texture_manager.hpp index d749b2925..217304431 100644 --- a/src/graphics/texture_manager.hpp +++ b/src/graphics/texture_manager.hpp @@ -33,5 +33,6 @@ void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = f bool loadCompressedTexture(const std::string& compressed_tex); void saveCompressedTexture(const std::string& compressed_tex); irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c); +void insertTextureHandle(uint64_t handle); #endif diff --git a/src/graphics/texture_shader.hpp b/src/graphics/texture_shader.hpp index b704ea603..54180cd17 100644 --- a/src/graphics/texture_shader.hpp +++ b/src/graphics/texture_shader.hpp @@ -243,13 +243,18 @@ public: for (unsigned i = 0; i < m_sampler_ids.size(); i++) glDeleteSamplers(1, &m_sampler_ids[i]); } // ~TextureShader - - /** Override this class and return true if a shader has changeable color. + // ------------------------------------------------------------------------ + /** For AZDO to remove the old texture handles, according to specification, + * they can only be removed when the underlying texture or sampler objects + * are finally deleted. This deletion will happen only when no handle + * using the texture or sampler object is resident on any context. */ - virtual bool changeableColor(float hue = 0.0f, float min_sat = 0.0f) const + void recreateTrilinearSampler(int sampler_id) { - return false; - } // changeableColor + glDeleteSamplers(1, &m_sampler_ids[sampler_id]); + m_sampler_ids[sampler_id] = + createSamplers(ST_TRILINEAR_ANISOTROPIC_FILTERED); + } // recreateTrilinearSampler }; // class TextureShader diff --git a/src/graphics/vao_manager.cpp b/src/graphics/vao_manager.cpp index 6448488be..39ef778bf 100644 --- a/src/graphics/vao_manager.cpp +++ b/src/graphics/vao_manager.cpp @@ -42,13 +42,13 @@ VAOManager::VAOManager() #if !defined(USE_GLES2) if (CVS->supportsAsyncInstanceUpload()) { - glBufferStorage(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataDualTex), 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT); - Ptr[i] = glMapBufferRange(GL_ARRAY_BUFFER, 0, 10000 * sizeof(InstanceDataDualTex), GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT); + glBufferStorage(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataThreeTex), 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT); + Ptr[i] = glMapBufferRange(GL_ARRAY_BUFFER, 0, 10000 * sizeof(InstanceDataThreeTex), GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT); } else #endif { - glBufferData(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataDualTex), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, 10000 * sizeof(InstanceDataThreeTex), 0, GL_STREAM_DRAW); } } } @@ -158,21 +158,21 @@ template<> void VAOInstanceUtil::SetVertexAttrib() { SetVertexAttrib_impl(); - glEnableVertexAttribArray(10); - glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataSingleTex), (GLvoid*)(9 * sizeof(float))); - glVertexAttribDivisorARB(10, 1); + glEnableVertexAttribArray(11); + glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataSingleTex), (GLvoid*)(9 * sizeof(float))); + glVertexAttribDivisorARB(11, 1); } template<> void VAOInstanceUtil::SetVertexAttrib() { SetVertexAttrib_impl(); - glEnableVertexAttribArray(10); - glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float))); - glVertexAttribDivisorARB(10, 1); glEnableVertexAttribArray(11); - glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float))); glVertexAttribDivisorARB(11, 1); + glEnableVertexAttribArray(12); + glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribDivisorARB(12, 1); } template<> @@ -180,23 +180,47 @@ void VAOInstanceUtil::SetVertexAttrib() { SetVertexAttrib_impl(); glEnableVertexAttribArray(10); - glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float))); + glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float))); glVertexAttribDivisorARB(10, 1); glEnableVertexAttribArray(11); - glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float))); glVertexAttribDivisorARB(11, 1); + glEnableVertexAttribArray(12); + glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribDivisorARB(12, 1); glEnableVertexAttribArray(13); - glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 4 * sizeof(unsigned))); + glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned))); glVertexAttribDivisorARB(13, 1); } +template<> +void VAOInstanceUtil::SetVertexAttrib() +{ + SetVertexAttrib_impl(); + glEnableVertexAttribArray(10); + glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceDataFourTex), (GLvoid*)(9 * sizeof(float))); + glVertexAttribDivisorARB(10, 1); + glEnableVertexAttribArray(11); + glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float))); + glVertexAttribDivisorARB(11, 1); + glEnableVertexAttribArray(12); + glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribDivisorARB(12, 1); + glEnableVertexAttribArray(13); + glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned))); + glVertexAttribDivisorARB(13, 1); + glEnableVertexAttribArray(14); + glVertexAttribIPointer(14, 2, GL_UNSIGNED_INT, sizeof(InstanceDataFourTex), (GLvoid*)(13 * sizeof(float) + 6 * sizeof(unsigned))); + glVertexAttribDivisorARB(14, 1); +} + template<> void VAOInstanceUtil::SetVertexAttrib() { SetVertexAttrib_impl(); - glEnableVertexAttribArray(12); - glVertexAttribPointer(12, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlowInstanceData), (GLvoid*)(9 * sizeof(float))); - glVertexAttribDivisorARB(12, 1); + glEnableVertexAttribArray(15); + glVertexAttribPointer(15, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlowInstanceData), (GLvoid*)(9 * sizeof(float))); + glVertexAttribDivisorARB(15, 1); } @@ -220,6 +244,11 @@ void VAOManager::regenerateInstancedVAO() VAOInstanceUtil::SetVertexAttrib(); InstanceVAO[std::pair(tp, InstanceTypeThreeTex)] = vao; + vao = createVAO(vbo[tp], ibo[tp], tp); + glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeFourTex]); + VAOInstanceUtil::SetVertexAttrib(); + InstanceVAO[std::pair(tp, InstanceTypeFourTex)] = vao; + vao = createVAO(vbo[tp], ibo[tp], tp); glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeShadow]); VAOInstanceUtil::SetVertexAttrib(); diff --git a/src/graphics/vao_manager.hpp b/src/graphics/vao_manager.hpp index e28491905..9e674066d 100644 --- a/src/graphics/vao_manager.hpp +++ b/src/graphics/vao_manager.hpp @@ -32,6 +32,7 @@ enum InstanceType { InstanceTypeDualTex, InstanceTypeThreeTex, + InstanceTypeFourTex, InstanceTypeShadow, InstanceTypeRSM, InstanceTypeGlow, @@ -116,6 +117,13 @@ struct InstanceDataThreeTex float Y; float Z; } Scale; + struct + { + float X; + float Y; + float Z; + float W; + } MiscData; uint64_t Texture; uint64_t SecondTexture; uint64_t ThirdTexture; @@ -125,6 +133,43 @@ struct InstanceDataThreeTex } __attribute__((packed)); #endif +struct InstanceDataFourTex +{ + struct + { + float X; + float Y; + float Z; + } Origin; + struct + { + float X; + float Y; + float Z; + } Orientation; + struct + { + float X; + float Y; + float Z; + } Scale; + struct + { + float X; + float Y; + float Z; + float W; + } MiscData; + uint64_t Texture; + uint64_t SecondTexture; + uint64_t ThirdTexture; + uint64_t FourthTexture; +#ifdef WIN32 +}; +#else +} __attribute__((packed)); +#endif + struct GlowInstanceData { struct diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index fe53e56d7..42e603a2c 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -73,7 +73,7 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart) // Gloss mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); // Colorization mask - mb->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); updatePosition(); m_node = irr_driver->addMesh(m_mesh, "rubberband"); irr_driver->applyObjectPassShader(m_node); diff --git a/src/tracks/check_line.cpp b/src/tracks/check_line.cpp index 0bd8490a5..4b42c6687 100644 --- a/src/tracks/check_line.cpp +++ b/src/tracks/check_line.cpp @@ -104,7 +104,7 @@ CheckLine::CheckLine(const XMLNode &node, unsigned int index) buffer->recalculateBoundingBox(); buffer->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180))); buffer->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - buffer->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + buffer->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); buffer->getMaterial().BackfaceCulling = false; //mesh->setBoundingBox(buffer->getBoundingBox()); m_debug_node = irr_driver->addMesh(mesh, "checkdebug"); diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index c7792c4db..04ad23449 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -109,7 +109,7 @@ void Graph::createMesh(bool show_invisible, bool enable_transparency, m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; m.setTexture(0, getUnicolorTexture(video::SColor(255, 255, 255, 255))); m.setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); - m.setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + m.setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); m_mesh = irr_driver->createQuadMesh(&m); m_mesh_buffer = m_mesh->getMeshBuffer(0); assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 56be84804..46fcd696c 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -792,7 +792,7 @@ void Track::createPhysicsModel(unsigned int main_track_count) // Gloss mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0))); // Colorization mask - mb->getMaterial().setTexture(7, getUnicolorTexture(video::SColor(0, 0, 0, 0))); + mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0))); } else irr_driver->removeNode(m_static_physics_only_nodes[i]); @@ -1819,8 +1819,9 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) // ---- Set ambient color m_ambient_color = m_default_ambient_color; - irr_driver->setAmbientLight(m_ambient_color, false); - + irr_driver->setAmbientLight(m_ambient_color, + m_spherical_harmonics_textures.size() != 6/*force_SH_computation*/); + // ---- Create sun (non-ambient directional light) if (m_sun_position.getLengthSQ() < 0.03f) {