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_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_object_pass.vert b/data/shaders/instanced_object_pass.vert index 8e618bd01..79bbd6d2d 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 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/src/graphics/command_buffer.cpp b/src/graphics/command_buffer.cpp index 5c68bab18..22ef6453d 100644 --- a/src/graphics/command_buffer.cpp +++ b/src/graphics/command_buffer.cpp @@ -41,9 +41,28 @@ template<> void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataThreeTex &instance) { fillOriginOrientationScale(node, instance); + instance.MiscData.X = 0; + instance.MiscData.Y = 0; + instance.MiscData.Z = 0; + instance.MiscData.W = 0; + instance.Texture = mesh->TextureHandles[0]; + instance.SecondTexture = mesh->TextureHandles[1]; + instance.ThirdTexture = mesh->TextureHandles[7]; +} + +// ---------------------------------------------------------------------------- +template<> +void InstanceFiller::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataFourTex &instance) +{ + fillOriginOrientationScale(node, instance); + instance.MiscData.X = 0; + instance.MiscData.Y = 0; + instance.MiscData.Z = 0; + instance.MiscData.W = 0; instance.Texture = mesh->TextureHandles[0]; instance.SecondTexture = mesh->TextureHandles[1]; instance.ThirdTexture = mesh->TextureHandles[2]; + instance.FourthTexture = mesh->TextureHandles[7]; } // ---------------------------------------------------------------------------- @@ -142,23 +161,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..f7d5b3d15 100644 --- a/src/graphics/command_buffer.hpp +++ b/src/graphics/command_buffer.hpp @@ -97,7 +97,7 @@ void FillInstances_impl(InstanceList instance_list, { 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)); + assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataThreeTex)); } DrawElementsIndirectCommand &CurrentCommand = command_buffer[command_buffer_offset++]; @@ -227,7 +227,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); } diff --git a/src/graphics/materials.hpp b/src/graphics/materials.hpp index 5d030c0d7..27a371f0f 100644 --- a/src/graphics/materials.hpp +++ b/src/graphics/materials.hpp @@ -636,7 +636,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 +657,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 +679,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 +701,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 +745,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 +767,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/vao_manager.cpp b/src/graphics/vao_manager.cpp index 6448488be..d4c2bec24 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(12); + glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float))); + glVertexAttribDivisorARB(12, 1); + glEnableVertexAttribArray(13); + glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned))); + glVertexAttribDivisorARB(13, 1); + glEnableVertexAttribArray(14); + glVertexAttribIPointer(14, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned))); + glVertexAttribDivisorARB(14, 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(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned))); + 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(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float) + 4 * sizeof(unsigned))); + 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