Allow normal map karts to be used in ghost race

Also split ghost karts out of additive shader, so fixed issues like
"drivers are facing backwards", "water in abyss affects ghost karts"

Todo: maybe transparency depend on current track color?
This commit is contained in:
Benau 2016-10-16 15:40:40 +08:00
parent 929b9b5c20
commit 23a1b08efe
8 changed files with 79 additions and 9 deletions

View File

@ -0,0 +1,19 @@
#ifdef Use_Bindless_Texture
layout(bindless_sampler) uniform sampler2D tex;
#else
uniform sampler2D tex;
#endif
in vec2 uv;
in vec4 color;
out vec4 FragColor;
void main()
{
vec4 Color = texture(tex, uv);
#ifdef Use_Bindless_Texture
Color.xyz = pow(Color.xyz, vec3(2.2));
#endif
Color.xyz *= pow(color.xyz, vec3(2.2));
FragColor = vec4(Color.rgb * 0.5, 0.5);
}

View File

@ -1555,14 +1555,24 @@ static video::ITexture *displaceTex = 0;
// ----------------------------------------------------------------------------
void IrrDriver::renderTransparent()
{
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glDisable(GL_CULL_FACE);
irr_driver->setPhase(TRANSPARENT_PASS);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glEnable(GL_CULL_FACE);
renderTransparenPass<Shaders::GhostKartsShader, video::EVT_STANDARD, 2, 1>(
TexUnits(RenderGeometry::TexUnit(0, true)),
ListGhostKart::getInstance());
renderTransparenPass<Shaders::GhostKartsShader, video::EVT_TANGENTS, 2, 1>(
TexUnits(RenderGeometry::TexUnit(0, true)),
ListGhostKartTangents::getInstance());
glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
for (unsigned i = 0; i < ImmediateDrawList::getInstance()->size(); i++)
ImmediateDrawList::getInstance()->at(i)->render();

View File

@ -369,6 +369,15 @@ Shaders::TransparentShader::TransparentShader()
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // TransparentShader
// ============================================================================
Shaders::GhostKartsShader::GhostKartsShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "ghost_karts.frag");
assignUniforms("ModelMatrix", "TextureMatrix");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // GhostKartsShader
// ============================================================================
Shaders::TransparentFogShader::TransparentFogShader()
{

View File

@ -126,6 +126,14 @@ public:
TransparentShader();
}; // TransparentShader
// ========================================================================
class GhostKartsShader : public TextureShader<GhostKartsShader, 1,
core::matrix4, core::matrix4 >
{
public:
GhostKartsShader();
}; // TransparentShader
// ========================================================================
class TransparentFogShader : public TextureShader<TransparentFogShader, 1,
core::matrix4, core::matrix4, float, float,

View File

@ -165,7 +165,10 @@ void STKAnimatedMesh::updateNoGL()
}
else if (mesh.m_render_info != NULL && mesh.m_render_info->isTransparent())
{
TransparentMesh[TM_ADDITIVE].push_back(&mesh);
if (mesh.VAOType == video::EVT_TANGENTS)
TransparentMesh[TM_GHOST_KART_TANGENTS].push_back(&mesh);
else
TransparentMesh[TM_GHOST_KART].push_back(&mesh);
}
else
{

View File

@ -37,6 +37,8 @@ enum TransparentMaterial
TM_DEFAULT,
TM_ADDITIVE,
TM_DISPLACEMENT,
TM_GHOST_KART,
TM_GHOST_KART_TANGENTS,
TM_COUNT
}; // TransparentMaterial
@ -206,6 +208,18 @@ class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
core::matrix4>
{};
// ----------------------------------------------------------------------------
class ListGhostKart : public MiscList<ListGhostKart,
GLMesh *, core::matrix4,
core::matrix4>
{};
// ----------------------------------------------------------------------------
class ListGhostKartTangents : public MiscList<ListGhostKartTangents,
GLMesh *, core::matrix4,
core::matrix4>
{};
// ----------------------------------------------------------------------------
class ListBlendTransparentFog : public MiscList<ListBlendTransparentFog,
GLMesh *, core::matrix4,

View File

@ -209,10 +209,11 @@ void STKMeshSceneNode::updateNoGL()
Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb);
if (mesh.m_render_info != NULL && mesh.m_render_info->isTransparent())
{
if (!immediate_draw)
TransparentMesh[TM_ADDITIVE].push_back(&mesh);
assert(!immediate_draw);
if (mesh.VAOType == video::EVT_TANGENTS)
TransparentMesh[TM_GHOST_KART_TANGENTS].push_back(&mesh);
else
additive = true;
TransparentMesh[TM_GHOST_KART].push_back(&mesh);
}
else if (rnd->isTransparent())
{

View File

@ -344,6 +344,10 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector<scene::ISceneNode *> *Immed
for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE])
pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
}
for (GLMesh *mesh : node->TransparentMesh[TM_GHOST_KART])
pushVector(ListGhostKart::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
for (GLMesh *mesh : node->TransparentMesh[TM_GHOST_KART_TANGENTS])
pushVector(ListGhostKartTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
for (GLMesh *mesh : node->TransparentMesh[TM_DISPLACEMENT])
pushVector(ListDisplacement::getInstance(), mesh, Node->getAbsoluteTransformation());
@ -606,6 +610,8 @@ void IrrDriver::PrepareDrawCalls(scene::ICameraSceneNode *camnode)
windDir = getWindDir();
ListBlendTransparent::getInstance()->clear();
ListAdditiveTransparent::getInstance()->clear();
ListGhostKart::getInstance()->clear();
ListGhostKartTangents::getInstance()->clear();
ListBlendTransparentFog::getInstance()->clear();
ListAdditiveTransparentFog::getInstance()->clear();
ListDisplacement::getInstance()->clear();