Merge branch 'improve_instanced_rendering'

This commit is contained in:
Benau 2016-12-03 09:17:15 +08:00
commit 332811af84
45 changed files with 450 additions and 310 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -21,26 +21,36 @@
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataSingleTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataSingleTex &instance)
void InstanceFiller<InstanceDataSingleTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataSingleTex& instance)
{
fillOriginOrientationScale<InstanceDataSingleTex>(node, instance);
fillOriginOrientationScale<InstanceDataSingleTex>(STK::tuple_get<0>(is), instance);
instance.Texture = mesh->TextureHandles[0];
}
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataDualTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataDualTex &instance)
void InstanceFiller<InstanceDataDualTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataDualTex& instance)
{
fillOriginOrientationScale<InstanceDataDualTex>(node, instance);
fillOriginOrientationScale<InstanceDataDualTex>(STK::tuple_get<0>(is), instance);
instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1];
}
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *node, InstanceDataThreeTex &instance)
void InstanceFiller<InstanceDataThreeTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataThreeTex& instance)
{
fillOriginOrientationScale<InstanceDataThreeTex>(node, instance);
fillOriginOrientationScale<InstanceDataThreeTex>(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<InstanceDataThreeTex>::add(GLMesh *mesh, scene::ISceneNode *
// ----------------------------------------------------------------------------
template<>
void InstanceFiller<GlowInstanceData>::add(GLMesh *mesh, scene::ISceneNode *node, GlowInstanceData &instance)
void InstanceFiller<InstanceDataFourTex>::add(GLMesh* mesh,
const InstanceSettings& is,
InstanceDataFourTex& instance)
{
fillOriginOrientationScale<InstanceDataFourTex>(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<GlowInstanceData>::add(GLMesh* mesh,
const InstanceSettings& is,
GlowInstanceData& instance)
{
scene::ISceneNode* node = STK::tuple_get<0>(is);
fillOriginOrientationScale<GlowInstanceData>(node, instance);
STKMeshSceneNode *nd = dynamic_cast<STKMeshSceneNode*>(node);
instance.Color = nd->getGlowColor().color;
@ -142,23 +172,27 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map)
mapIndirectBuffer();
std::vector<int> dual_tex_material_list =
createVector<int>(Material::SHADERTYPE_VEGETATION);
fillInstanceData<InstanceDataDualTex, SolidPassMeshMap>
(mesh_map, dual_tex_material_list, InstanceTypeDualTex);
std::vector<int> three_tex_material_list =
createVector<int>(Material::SHADERTYPE_SOLID,
Material::SHADERTYPE_ALPHA_TEST,
Material::SHADERTYPE_SOLID_UNLIT,
Material::SHADERTYPE_SPHERE_MAP,
Material::SHADERTYPE_VEGETATION);
fillInstanceData<InstanceDataDualTex, SolidPassMeshMap>
(mesh_map, dual_tex_material_list, InstanceTypeDualTex);
std::vector<int> three_tex_material_list =
createVector<int>(Material::SHADERTYPE_DETAIL_MAP,
Material::SHADERTYPE_NORMAL_MAP);
Material::SHADERTYPE_SPHERE_MAP);
fillInstanceData<InstanceDataThreeTex, SolidPassMeshMap>
(mesh_map, three_tex_material_list, InstanceTypeThreeTex);
std::vector<int> four_tex_material_list =
createVector<int>(Material::SHADERTYPE_DETAIL_MAP,
Material::SHADERTYPE_NORMAL_MAP);
fillInstanceData<InstanceDataFourTex, SolidPassMeshMap>
(mesh_map, four_tex_material_list, InstanceTypeFourTex);
if (!CVS->supportsAsyncInstanceUpload())
glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER);
} //SolidCommandBuffer::fill

View File

@ -29,15 +29,17 @@
#include <array>
#include <unordered_map>
typedef STK::Tuple<scene::ISceneNode*, core::vector2df, core::vector2df> InstanceSettings;
struct InstanceList
{
GLMesh *m_mesh;
std::vector<irr::scene::ISceneNode*> m_scene_nodes;
std::vector<InstanceSettings> m_instance_settings;
};
typedef std::unordered_map <std::pair<scene::IMeshBuffer*, RenderInfo*>, InstanceList,
MeshRenderInfoHash, MeshRenderInfoEquals> SolidPassMeshMap;
typedef std::unordered_map <irr::scene::IMeshBuffer *, InstanceList > OtherMeshMap;
// ----------------------------------------------------------------------------
@ -67,7 +69,7 @@ void fillOriginOrientationScale(scene::ISceneNode *node, InstanceData &instance)
template<typename InstanceData>
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<typename T>
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<T>::add(mesh, node, instance_buffer[instance_buffer_offset++]);
assert(instance_buffer_offset * sizeof(T) < 10000 * sizeof(InstanceDataDualTex));
InstanceFiller<T>::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<T>(*mesh, prefilled_tex);
//TODO: next 10 lines are duplicated in draw_tools.hpp (see CustomUnrollArgs::drawMesh)
//TODO: find a way to remove duplicated code
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue =
(support_change_hue && mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
T::InstancedSecondPassShader::getInstance()->changeableColor
(mesh->m_render_info->getHue(),
mesh->m_material->getColorizationFactor());
}
if (!mesh->mb->getMaterial().BackfaceCulling)
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

View File

@ -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<scene::IMeshBuffer*, RenderInfo*> 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<scene::IMeshBuffer*, RenderInfo*> mesh_render_info(mesh->mb,
dynamic_cast<STKMeshSceneNode*>(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);

View File

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

View File

@ -179,23 +179,15 @@ AbstractGeometryPasses::AbstractGeometryPasses()
}
// ----------------------------------------------------------------------------
void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures)
void AbstractGeometryPasses::setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures,
const std::vector<uint64_t>& prefilled_handles)
{
m_prefilled_textures = prefilled_textures;
#if !defined(USE_GLES2)
if (CVS->isAZDOEnabled())
{
m_textures_handles.clear();
for(size_t i=0;i<m_prefilled_textures.size();i++)
{
uint64_t handle = 0;
handle = glGetTextureSamplerHandleARB(m_prefilled_textures[i],
Shaders::ObjectPass2Shader::getInstance()->m_sampler_ids[i]);
if (!glIsTextureHandleResidentARB(handle))
glMakeTextureHandleResidentARB(handle);
m_textures_handles.push_back(handle);
}
m_textures_handles = prefilled_handles;
}
#endif // !defined(USE_GLES2)
}

View File

@ -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<GLuint>& prefilled_textures);
void setFirstPassRenderTargets(const std::vector<GLuint>& prefilled_textures,
const std::vector<uint64_t>& prefilled_handles);
virtual void renderSolidFirstPass(const DrawCalls& draw_calls) const = 0;

View File

@ -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())
{

View File

@ -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);
}

View File

@ -20,7 +20,7 @@
const STK::Tuple<size_t> DefaultMaterial::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DefaultMaterial::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 7);
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> DefaultMaterial::ShadowTextures;
const STK::Tuple<size_t> DefaultMaterial::RSMTextures = STK::Tuple<size_t>(0);
@ -55,24 +55,24 @@ const STK::Tuple<size_t> GrassMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> NormalMat::FirstPassTextures
= STK::Tuple<size_t, size_t>(2, 1);
= STK::Tuple<size_t, size_t>(3, 1);
const STK::Tuple<size_t, size_t, size_t> NormalMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 7);
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> NormalMat::ShadowTextures;
const STK::Tuple<size_t> NormalMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> DetailMat::FirstPassTextures = STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DetailMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 2, 1);
= STK::Tuple<size_t, size_t, size_t>(0, 3, 1);
const STK::Tuple<> DetailMat::ShadowTextures;
const STK::Tuple<size_t> DetailMat::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> SplattingMat::FirstPassTextures = STK::Tuple<size_t>(6);
const STK::Tuple<size_t> SplattingMat::FirstPassTextures = STK::Tuple<size_t>(7);
const STK::Tuple<size_t, size_t, size_t, size_t, size_t>
SplattingMat::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 2, 3, 4, 5);
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 3, 4, 5, 6);
const STK::Tuple<> SplattingMat::ShadowTextures;
const STK::Tuple<size_t, size_t, size_t, size_t, size_t> SplattingMat::RSMTextures
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 2, 3, 4, 5);
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 3, 4, 5, 6);

View File

@ -56,14 +56,14 @@ public:
// ============================================================================
class ObjectRefPass2Shader : public TextureShader<ObjectRefPass2Shader, 5,
core::matrix4, core::matrix4>
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<InstancedObjectPass2Shader, 6>
{
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<CRSMShader, 1, core::matrix4, core::matrix4,
class CRSMShader : public TextureShader<CRSMShader, 1, core::matrix4, core::vector2df,
core::matrix4>
{
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<ObjectRefPass1Shader, 2, core::matrix4,
core::matrix4, core::matrix4>
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<ObjectUnlitShader, 4, core::matrix4,
core::matrix4>
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<size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> 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<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t> 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<size_t> FirstPassTextures;
static const STK::Tuple<size_t> 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<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t> SecondPassTextures;
static const STK::Tuple<size_t> 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<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> 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<size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<> ShadowTextures;

View File

@ -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())

View File

@ -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 <stddef.h>
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<uint64_t>& getPrefilledHandles() { return m_prefilled_handles; }
private:
unsigned RenderTargetTextures[RTT_COUNT];
PtrVector<FrameBuffer> FrameBuffers;
std::vector<uint64_t> m_prefilled_handles;
unsigned DepthStencilTexture;
size_t m_width;

View File

@ -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<video::ITexture*> &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());
}

View File

@ -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

View File

@ -120,7 +120,7 @@ public:
// ========================================================================
class TransparentShader : public TextureShader<TransparentShader, 1,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
float >
{
public:
@ -129,7 +129,7 @@ public:
// ========================================================================
class TransparentFogShader : public TextureShader<TransparentFogShader, 1,
core::matrix4, core::matrix4, float, float,
core::matrix4, core::vector2df, float, float,
float, float, float, video::SColorf >
{
public:
@ -145,7 +145,7 @@ public:
// ========================================================================
class ObjectPass2Shader : public TextureShader < ObjectPass2Shader, 6,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df >
{
public:

View File

@ -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

View File

@ -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];
}
}
}
}

View File

@ -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

View File

@ -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<ListMatDefault, GLMesh *, core::matrix4,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatAlphaRef : public MeshList<ListMatAlphaRef, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatNormalMap : public MeshList<ListMatNormalMap, GLMesh *, core::matrix4,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
@ -135,7 +135,7 @@ class ListMatGrass : public MeshList<ListMatGrass, GLMesh *, core::matrix4,
// ----------------------------------------------------------------------------
class ListMatSphereMap : public MeshList<ListMatSphereMap, GLMesh *,
core::matrix4, core::matrix4,
core::matrix4>
core::vector2df>
{};
// ----------------------------------------------------------------------------
@ -145,12 +145,12 @@ class ListMatSplatting : public MeshList<ListMatSplatting, GLMesh *,
// ----------------------------------------------------------------------------
class ListMatUnlit : public MeshList<ListMatUnlit, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
class ListMatDetails : public MeshList<ListMatDetails, GLMesh *, core::matrix4,
core::matrix4, core::matrix4>
core::matrix4, core::vector2df>
{};
// ----------------------------------------------------------------------------
@ -161,38 +161,38 @@ class MiscList : public Singleton<T>, public std::vector<STK::Tuple<Args...> >
// ----------------------------------------------------------------------------
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *,
core::matrix4, core::matrix4,
core::matrix4, core::vector2df,
float>
{};
// ----------------------------------------------------------------------------
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentStandard : public MiscList<ListTranslucentStandard,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucentTangents : public MiscList<ListTranslucentTangents,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListTranslucent2TCoords : public MiscList<ListTranslucent2TCoords,
GLMesh *, core::matrix4,
core::matrix4, float>
core::vector2df, float>
{};
// ----------------------------------------------------------------------------
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
GLMesh *, core::matrix4,
core::matrix4, float, float,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};
@ -200,7 +200,7 @@ class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
// ----------------------------------------------------------------------------
class ListAdditiveTransparentFog : public MiscList<ListAdditiveTransparentFog,
GLMesh *, core::matrix4,
core::matrix4, float, float,
core::vector2df, float, float,
float, float, float,
video::SColorf>
{};

View File

@ -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);

View File

@ -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;
}

View File

@ -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<irr::video::ITexture *> AlreadyTransformedTexture;
static std::map<int, video::ITexture*> unicolor_cache;
static std::vector<uint64_t> 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<const int, video::ITexture*>& uc : unicolor_cache)

View File

@ -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

View File

@ -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

View File

@ -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<InstanceDataSingleTex>::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<InstanceDataDualTex>::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<InstanceDataThreeTex>::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<InstanceDataFourTex>::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<GlowInstanceData>::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<InstanceDataThreeTex>::SetVertexAttrib();
InstanceVAO[std::pair<video::E_VERTEX_TYPE, InstanceType>(tp, InstanceTypeThreeTex)] = vao;
vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeFourTex]);
VAOInstanceUtil<InstanceDataFourTex>::SetVertexAttrib();
InstanceVAO[std::pair<video::E_VERTEX_TYPE, InstanceType>(tp, InstanceTypeFourTex)] = vao;
vao = createVAO(vbo[tp], ibo[tp], tp);
glBindBuffer(GL_ARRAY_BUFFER, instance_vbo[InstanceTypeShadow]);
VAOInstanceUtil<InstanceDataSingleTex>::SetVertexAttrib();

View File

@ -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

View File

@ -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);

View File

@ -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");

View File

@ -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);

View File

@ -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)
{