Add alpha test skinned mesh instanced shaders

This commit is contained in:
Benau 2016-12-12 01:00:57 +08:00
parent e9b68a8a1f
commit 4327885f07
10 changed files with 194 additions and 34 deletions

View File

@ -46,6 +46,7 @@ void InstanceFiller<InstanceDataThreeTex>::add(GLMesh* mesh,
instance.Texture = mesh->TextureHandles[0];
instance.SecondTexture = mesh->TextureHandles[1];
instance.ThirdTexture = mesh->TextureHandles[2];
instance.skinning_offset = STK::tuple_get<3>(is);
}
// ----------------------------------------------------------------------------
@ -169,15 +170,16 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map)
Material::SHADERTYPE_ALPHA_TEST,
Material::SHADERTYPE_SOLID_UNLIT,
Material::SHADERTYPE_SPHERE_MAP,
Material::SHADERTYPE_VEGETATION);
Material::SHADERTYPE_VEGETATION,
Material::SHADERTYPE_SOLID_SKINNED_MESH,
Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH);
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,
Material::SHADERTYPE_SOLID_SKINNED_MESH);
Material::SHADERTYPE_NORMAL_MAP);
fillInstanceData<InstanceDataFourTex, SolidPassMeshMap>
(mesh_map, four_tex_material_list, InstanceTypeFourTex);
@ -202,10 +204,12 @@ void ShadowCommandBuffer::fill(OtherMeshMap *mesh_map)
std::vector<int> shadow_tex_material_list;
for(int cascade=0; cascade<4; cascade++)
{
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT
+ Material::SHADERTYPE_SOLID);
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT
+ Material::SHADERTYPE_SOLID_SKINNED_MESH);
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT
+ Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH);
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT
+ Material::SHADERTYPE_SOLID);
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT
+ Material::SHADERTYPE_ALPHA_TEST);
shadow_tex_material_list.push_back(cascade * Material::SHADERTYPE_COUNT

View File

@ -712,8 +712,9 @@ void DrawCalls::renderParticlesList() const
void DrawCalls::drawIndirectSolidFirstPass() const
{
m_solid_cmd_buffer->bind();
m_solid_cmd_buffer->drawIndirectFirstPass<DefaultMaterial>();
m_solid_cmd_buffer->drawIndirectFirstPass<SkinnedSolid>();
m_solid_cmd_buffer->drawIndirectFirstPass<SkinnedAlphaRef>();
m_solid_cmd_buffer->drawIndirectFirstPass<DefaultMaterial>();
m_solid_cmd_buffer->drawIndirectFirstPass<AlphaRef>();
m_solid_cmd_buffer->drawIndirectFirstPass<UnlitMat>();
m_solid_cmd_buffer->drawIndirectFirstPass<SphereMap>();
@ -729,8 +730,9 @@ void DrawCalls::drawIndirectSolidFirstPass() const
void DrawCalls::multidrawSolidFirstPass() const
{
m_solid_cmd_buffer->bind();
m_solid_cmd_buffer->multidrawFirstPass<DefaultMaterial>();
m_solid_cmd_buffer->multidrawFirstPass<SkinnedSolid>();
m_solid_cmd_buffer->multidrawFirstPass<SkinnedAlphaRef>();
m_solid_cmd_buffer->multidrawFirstPass<DefaultMaterial>();
m_solid_cmd_buffer->multidrawFirstPass<AlphaRef>();
m_solid_cmd_buffer->multidrawFirstPass<SphereMap>();
m_solid_cmd_buffer->multidrawFirstPass<UnlitMat>();
@ -749,8 +751,9 @@ void DrawCalls::multidrawSolidFirstPass() const
void DrawCalls::drawIndirectSolidSecondPass(const std::vector<GLuint> &prefilled_tex) const
{
m_solid_cmd_buffer->bind();
m_solid_cmd_buffer->drawIndirectSecondPass<DefaultMaterial>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<SkinnedSolid>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<SkinnedAlphaRef>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<DefaultMaterial>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<AlphaRef>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<UnlitMat>(prefilled_tex);
m_solid_cmd_buffer->drawIndirectSecondPass<SphereMap>(prefilled_tex);
@ -768,8 +771,9 @@ void DrawCalls::drawIndirectSolidSecondPass(const std::vector<GLuint> &prefilled
void DrawCalls::multidrawSolidSecondPass(const std::vector<uint64_t> &handles) const
{
m_solid_cmd_buffer->bind();
m_solid_cmd_buffer->multidraw2ndPass<DefaultMaterial>(handles);
m_solid_cmd_buffer->multidraw2ndPass<SkinnedSolid>(handles);
m_solid_cmd_buffer->multidraw2ndPass<SkinnedAlphaRef>(handles);
m_solid_cmd_buffer->multidraw2ndPass<DefaultMaterial>(handles);
m_solid_cmd_buffer->multidraw2ndPass<AlphaRef>(handles);
m_solid_cmd_buffer->multidraw2ndPass<SphereMap>(handles);
m_solid_cmd_buffer->multidraw2ndPass<UnlitMat>(handles);
@ -818,8 +822,9 @@ void DrawCalls::multidrawNormals() const
void DrawCalls::drawIndirectShadows(unsigned cascade) const
{
m_shadow_cmd_buffer->bind();
m_shadow_cmd_buffer->drawIndirect<DefaultMaterial>(cascade);
m_shadow_cmd_buffer->drawIndirect<SkinnedSolid>(cascade);
m_shadow_cmd_buffer->drawIndirect<SkinnedAlphaRef>(cascade);
m_shadow_cmd_buffer->drawIndirect<DefaultMaterial>(cascade);
m_shadow_cmd_buffer->drawIndirect<DetailMat>(cascade);
m_shadow_cmd_buffer->drawIndirect<AlphaRef>(cascade);
m_shadow_cmd_buffer->drawIndirect<UnlitMat>(cascade);
@ -837,8 +842,9 @@ void DrawCalls::drawIndirectShadows(unsigned cascade) const
void DrawCalls::multidrawShadows(unsigned cascade) const
{
m_shadow_cmd_buffer->bind();
m_shadow_cmd_buffer->multidrawShadow<DefaultMaterial>(cascade);
m_shadow_cmd_buffer->multidrawShadow<SkinnedSolid>(cascade);
m_shadow_cmd_buffer->multidrawShadow<SkinnedAlphaRef>(cascade);
m_shadow_cmd_buffer->multidrawShadow<DefaultMaterial>(cascade);
m_shadow_cmd_buffer->multidrawShadow<DetailMat>(cascade);
m_shadow_cmd_buffer->multidrawShadow<NormalMat>(cascade);
m_shadow_cmd_buffer->multidrawShadow<AlphaRef>(cascade);

View File

@ -50,14 +50,18 @@ public:
SHADERTYPE_SOLID = 0,
SHADERTYPE_SOLID_SKINNED_MESH,
SHADERTYPE_ALPHA_TEST,
SHADERTYPE_ALPHA_TEST_SKINNED_MESH,
SHADERTYPE_ALPHA_BLEND,
SHADERTYPE_ALPHA_BLEND_SKINNED_MESH,
SHADERTYPE_ADDITIVE,
SHADERTYPE_SOLID_UNLIT,
SHADERTYPE_SOLID_UNLIT_SKINNED_MESH,
/** Effect that makes grass wave as in the wind */
SHADERTYPE_VEGETATION,
SHADERTYPE_WATER,
SHADERTYPE_SPHERE_MAP,
SHADERTYPE_NORMAL_MAP,
SHADERTYPE_NORMAL_MAP_SKINNED_MESH,
SHADERTYPE_DETAIL_MAP,
SHADERTYPE_SPLATTING,
SHADERTYPE_COUNT,

View File

@ -19,6 +19,22 @@
#ifndef SERVER_ONLY
const STK::Tuple<size_t> SkinnedSolid::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> SkinnedSolid::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> SkinnedSolid::ShadowTextures;
const STK::Tuple<size_t> SkinnedSolid::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> SkinnedAlphaRef::FirstPassTextures
= STK::Tuple<size_t, size_t>(0, 1);
const STK::Tuple<size_t, size_t, size_t> SkinnedAlphaRef::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<size_t> SkinnedAlphaRef::ShadowTextures = STK::Tuple<size_t>(0);
const STK::Tuple<size_t> SkinnedAlphaRef::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> DefaultMaterial::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DefaultMaterial::SecondPassTextures
@ -26,14 +42,6 @@ const STK::Tuple<size_t, size_t, size_t> DefaultMaterial::SecondPassTextures
const STK::Tuple<> DefaultMaterial::ShadowTextures;
const STK::Tuple<size_t> DefaultMaterial::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t> SkinnedSolid::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> SkinnedSolid::SecondPassTextures
= STK::Tuple<size_t, size_t, size_t>(0, 1, 2);
const STK::Tuple<> SkinnedSolid::ShadowTextures;
const STK::Tuple<size_t> SkinnedSolid::RSMTextures = STK::Tuple<size_t>(0);
// ----------------------------------------------------------------------------
const STK::Tuple<size_t, size_t> AlphaRef::FirstPassTextures
= STK::Tuple<size_t, size_t>(0, 1);

View File

@ -652,10 +652,46 @@ public:
}; // InstancedSkinnedMeshPass2Shader
// ============================================================================
class InstancedSkinningShadowShader : public TextureShader<InstancedSkinningShadowShader, 0, int>
class InstancedSkinnedMeshRefPass1Shader : public TextureShader<InstancedSkinnedMeshRefPass1Shader, 2>
{
public:
InstancedSkinningShadowShader()
InstancedSkinnedMeshRefPass1Shader()
{
if (!CVS->supportsHardwareSkinning()) return;
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_skinning.vert",
GL_FRAGMENT_SHADER, "instanced_objectref_pass1.frag");
assignUniforms();
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED,
1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedSkinnedMeshRefPass1Shader
}; // InstancedSkinnedMeshRefPass1Shader
// ============================================================================
class InstancedSkinnedMeshRefPass2Shader : public TextureShader<InstancedSkinnedMeshRefPass2Shader, 6>
{
public:
InstancedSkinnedMeshRefPass2Shader()
{
if (!CVS->supportsHardwareSkinning()) return;
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_skinning.vert",
GL_FRAGMENT_SHADER, "instanced_objectref_pass2.frag");
assignUniforms();
assignSamplerNames(0, "DiffuseMap", ST_NEAREST_FILTERED,
1, "SpecularMap", ST_NEAREST_FILTERED,
2, "SSAO", ST_BILINEAR_FILTERED,
3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED,
4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED,
5, "colorization_mask", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedSkinnedMeshRefPass2Shader
}; // InstancedSkinnedMeshRefPass2Shader
// ============================================================================
class InstancedSkinnedShadowShader : public TextureShader<InstancedSkinnedShadowShader, 0, int>
{
public:
InstancedSkinnedShadowShader()
{
#if !defined(USE_GLES2)
// Geometry shader needed
@ -674,16 +710,45 @@ public:
}
assignUniforms("layer");
#endif
} // InstancedSkinningShadowShader
} // InstancedSkinnedShadowShader
}; // InstancedSkinningShadowShader
}; // InstancedSkinnedShadowShader
// ============================================================================
class InstancedSkinnedRefShadowShader : public TextureShader<InstancedSkinnedRefShadowShader,
1, int>
{
public:
InstancedSkinnedRefShadowShader()
{
#if !defined(USE_GLES2)
// Geometry shader needed
if (CVS->getGLSLVersion() < 150 || !CVS->supportsHardwareSkinning())
return;
if (CVS->isAMDVertexShaderLayerUsable())
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_skinning_shadow.vert",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
else
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "instanced_skinning_shadow.vert",
GL_GEOMETRY_SHADER, "instanced_shadow.geom",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
assignUniforms("layer");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
#endif
} // InstancedSkinnedRefShadowShader
}; // InstancedSkinnedRefShadowShader
// ============================================================================
struct SkinnedSolid
{
typedef InstancedSkinnedMeshPass1Shader InstancedFirstPassShader;
typedef InstancedSkinnedMeshPass2Shader InstancedSecondPassShader;
typedef InstancedSkinningShadowShader InstancedShadowPassShader;
typedef InstancedSkinnedShadowShader InstancedShadowPassShader;
//typedef CInstancedRSMShader InstancedRSMShader;
typedef Shaders::SkinnedMeshPass1Shader FirstPassShader;
typedef Shaders::SkinnedMeshPass2Shader SecondPassShader;
@ -693,13 +758,35 @@ struct SkinnedSolid
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_SKINNED_MESH;
static const enum Material::ShaderType MaterialType
= Material::SHADERTYPE_SOLID_SKINNED_MESH;
static const enum InstanceType Instance = InstanceTypeFourTex;
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;
static const STK::Tuple<size_t> RSMTextures;
}; // struct SkinnedSolid
// ----------------------------------------------------------------------------
struct SkinnedAlphaRef
{
typedef InstancedSkinnedMeshRefPass1Shader InstancedFirstPassShader;
typedef InstancedSkinnedMeshRefPass2Shader InstancedSecondPassShader;
typedef InstancedSkinnedRefShadowShader InstancedShadowPassShader;
//typedef CInstancedRSMShader InstancedRSMShader;
//typedef ObjectRefPass1Shader FirstPassShader;
//typedef ObjectRefPass2Shader SecondPassShader;
//typedef RefShadowShader ShadowPassShader;
//typedef CRSMShader RSMShader;
typedef ListSkinnedAlphaRef List;
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_SKINNED_MESH;
static const enum Material::ShaderType MaterialType =
Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH;
static const enum InstanceType Instance = InstanceTypeThreeTex;
static const STK::Tuple<size_t, size_t> FirstPassTextures;
static const STK::Tuple<size_t, size_t, size_t> SecondPassTextures;
static const STK::Tuple<size_t> ShadowTextures;
static const STK::Tuple<size_t> RSMTextures;
}; // struct SkinnedAlphaRef
// ----------------------------------------------------------------------------
struct DefaultMaterial
{

View File

@ -168,6 +168,15 @@ void STKAnimatedMesh::updateNoGL()
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
scene::SSkinMeshBuffer* ssmb = NULL;
video::E_VERTEX_TYPE prev_type = mb->getVertexType();
if (m_skinned_mesh)
{
ssmb = dynamic_cast<scene::SSkinMeshBuffer*>(mb);
ssmb->VertexType = video::EVT_SKINNED_MESH;
}
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
f32 MaterialTypeParam = mb->getMaterial().MaterialTypeParam;
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(type);
@ -196,8 +205,9 @@ void STKAnimatedMesh::updateNoGL()
else*/
{
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, NULL);
MeshSolidMaterial[m_skinned_mesh ? Material::SHADERTYPE_SOLID_SKINNED_MESH : MatType].push_back(&mesh);
MeshSolidMaterial[MatType].push_back(&mesh);
}
if (m_skinned_mesh) ssmb->VertexType = prev_type;
}
isMaterialInitialized = true;
}
@ -250,7 +260,7 @@ void STKAnimatedMesh::updateGL()
material2 = material_manager->getMaterialFor(mb->getMaterial().getTexture(1), mb);
Material::ShaderType MatType = getMeshMaterialFromType(type, mb->getVertexType(), material, material2);
initTextures(mesh, m_skinned_mesh ? Material::SHADERTYPE_SOLID_SKINNED_MESH : MatType);
initTextures(mesh, MatType);
}
else
initTexturesTransparent(mesh);

View File

@ -40,6 +40,22 @@ Material::ShaderType getMeshMaterialFromType(video::E_MATERIAL_TYPE material_typ
layer2_material->getShaderType() == Material::SHADERTYPE_SPLATTING)
return Material::SHADERTYPE_SPLATTING;
if (tp == video::EVT_SKINNED_MESH)
{
switch (material->getShaderType())
{
//case Material::SHADERTYPE_SOLID:
// if (material_type == Shaders::getShader(ES_NORMAL_MAP))
// return Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH;
case Material::SHADERTYPE_ALPHA_TEST:
return Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH;
//case Material::SHADERTYPE_SOLID_UNLIT:
// return Material::SHADERTYPE_SOLID_UNLIT_SKINNED_MESH;
default:
return Material::SHADERTYPE_SOLID_SKINNED_MESH;
}
}
switch (material->getShaderType())
{
default:
@ -423,13 +439,16 @@ void initTextures(GLMesh &mesh, Material::ShaderType mat)
case Material::SHADERTYPE_SPHERE_MAP:
case Material::SHADERTYPE_SOLID_UNLIT:
case Material::SHADERTYPE_VEGETATION:
case Material::SHADERTYPE_SOLID_SKINNED_MESH:
case Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH:
case Material::SHADERTYPE_SOLID_UNLIT_SKINNED_MESH:
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:
case Material::SHADERTYPE_SOLID_SKINNED_MESH:
case Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH:
setTexture(mesh, 0, true, getShaderTypeName(mat));
setTexture(mesh, 1, false, getShaderTypeName(mat));
setTexture(mesh, 2, false, getShaderTypeName(mat));

View File

@ -112,15 +112,33 @@ public:
// ----------------------------------------------------------------------------
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
class ListSkinnedSolid : public MeshList<ListSkinnedSolid, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedSolid : public MeshList<ListSkinnedSolid, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df, int>
class ListSkinnedAlphaRef : public MeshList<ListSkinnedAlphaRef, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedNormalMap : public MeshList<ListSkinnedNormalMap, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListSkinnedUnlit : public MeshList<ListSkinnedUnlit, GLMesh *,
core::matrix4, core::matrix4,
core::vector2df, core::vector2df, int>
{};
// ----------------------------------------------------------------------------
class ListMatDefault : public MeshList<ListMatDefault, GLMesh *, core::matrix4,
core::matrix4, core::vector2df,
core::vector2df>
{};
// ----------------------------------------------------------------------------

View File

@ -184,6 +184,9 @@ void VAOInstanceUtil<InstanceDataThreeTex>::SetVertexAttrib()
glEnableVertexAttribArray(13);
glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned)));
glVertexAttribDivisorARB(13, 1);
glEnableVertexAttribArray(15);
glVertexAttribIPointer(15, 1, GL_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 6 * sizeof(unsigned)));;
glVertexAttribDivisorARB(15, 1);
}
template<>

View File

@ -99,6 +99,7 @@ struct InstanceDataThreeTex
uint64_t Texture;
uint64_t SecondTexture;
uint64_t ThirdTexture;
int32_t skinning_offset;
#ifdef WIN32
};
#else