Try to use sun color to determine custom alpha for ghost karts
This may need more adjustments, also add custom_alpha uniform float to transparent fragment shader to remove duplicated shader
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
layout(bindless_sampler) uniform sampler2D tex;
|
||||
#else
|
||||
uniform sampler2D tex;
|
||||
uniform float custom_alpha;
|
||||
#endif
|
||||
|
||||
in vec2 uv;
|
||||
@@ -18,5 +19,5 @@ void main()
|
||||
Color.xyz *= pow(color.xyz, vec3(2.2));
|
||||
Color.a *= color.a;
|
||||
// Premultiply alpha
|
||||
FragColor = vec4(Color.rgb * Color.a, Color.a);
|
||||
FragColor = vec4(Color.rgb * (Color.a * custom_alpha), Color.a * custom_alpha);
|
||||
}
|
||||
|
||||
@@ -34,14 +34,14 @@
|
||||
|
||||
|
||||
// ============================================================================
|
||||
class Primitive2DList : public TextureShader<Primitive2DList, 1>
|
||||
class Primitive2DList : public TextureShader<Primitive2DList, 1, float>
|
||||
{
|
||||
public:
|
||||
Primitive2DList()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "primitive2dlist.vert",
|
||||
GL_FRAGMENT_SHADER, "transparent.frag");
|
||||
assignUniforms();
|
||||
assignUniforms("custom_alpha");
|
||||
assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED);
|
||||
} // Primitive2DList
|
||||
}; //Primitive2DList
|
||||
@@ -703,7 +703,7 @@ void draw2DVertexPrimitiveList(video::ITexture *tex, const void* vertices,
|
||||
VertexUtils::bindVertexArrayAttrib(vType);
|
||||
|
||||
Primitive2DList::getInstance()->use();
|
||||
Primitive2DList::getInstance()->setUniforms();
|
||||
Primitive2DList::getInstance()->setUniforms(1.0f);
|
||||
compressTexture(tex, false);
|
||||
Primitive2DList::getInstance()->setTextureUnits(getTextureGLuint(tex));
|
||||
glDrawElements(GL_TRIANGLE_FAN, primitiveCount, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
@@ -1563,11 +1563,11 @@ void IrrDriver::renderTransparent()
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glEnable(GL_CULL_FACE);
|
||||
renderTransparenPass<Shaders::GhostKartsShader, video::EVT_STANDARD, 2, 1>(
|
||||
renderTransparenPass<Shaders::TransparentShader, video::EVT_STANDARD, 3, 2, 1>(
|
||||
TexUnits(RenderGeometry::TexUnit(0, true)),
|
||||
ListGhostKart::getInstance());
|
||||
|
||||
renderTransparenPass<Shaders::GhostKartsShader, video::EVT_TANGENTS, 2, 1>(
|
||||
renderTransparenPass<Shaders::TransparentShader, video::EVT_TANGENTS, 3, 2, 1>(
|
||||
TexUnits(RenderGeometry::TexUnit(0, true)),
|
||||
ListGhostKartTangents::getInstance());
|
||||
|
||||
@@ -1596,11 +1596,11 @@ void IrrDriver::renderTransparent()
|
||||
{
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
renderTransparenPass<Shaders::TransparentShader,
|
||||
video::EVT_STANDARD, 2, 1>(
|
||||
video::EVT_STANDARD, 3, 2, 1>(
|
||||
TexUnits(RenderGeometry::TexUnit(0, true)),
|
||||
ListBlendTransparent::getInstance());
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
renderTransparenPass<Shaders::TransparentShader, video::EVT_STANDARD, 2, 1>(
|
||||
renderTransparenPass<Shaders::TransparentShader, video::EVT_STANDARD, 3, 2, 1>(
|
||||
TexUnits(RenderGeometry::TexUnit(0, true)),
|
||||
ListAdditiveTransparent::getInstance());
|
||||
}
|
||||
|
||||
@@ -365,19 +365,10 @@ Shaders::TransparentShader::TransparentShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
|
||||
GL_FRAGMENT_SHADER, "transparent.frag");
|
||||
assignUniforms("ModelMatrix", "TextureMatrix");
|
||||
assignUniforms("ModelMatrix", "TextureMatrix", "custom_alpha");
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -120,20 +120,13 @@ public:
|
||||
|
||||
// ========================================================================
|
||||
class TransparentShader : public TextureShader<TransparentShader, 1,
|
||||
core::matrix4, core::matrix4 >
|
||||
core::matrix4, core::matrix4,
|
||||
float >
|
||||
{
|
||||
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,
|
||||
|
||||
@@ -199,25 +199,26 @@ class MiscList : public Singleton<T>, public std::vector<STK::Tuple<Args...> >
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListBlendTransparent : public MiscList<ListBlendTransparent, GLMesh *,
|
||||
core::matrix4, core::matrix4>
|
||||
core::matrix4, core::matrix4,
|
||||
float>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListAdditiveTransparent : public MiscList<ListAdditiveTransparent,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4>
|
||||
core::matrix4, float>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListGhostKart : public MiscList<ListGhostKart,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4>
|
||||
core::matrix4, float>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class ListGhostKartTangents : public MiscList<ListGhostKartTangents,
|
||||
GLMesh *, core::matrix4,
|
||||
core::matrix4>
|
||||
core::matrix4, float>
|
||||
{};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -568,7 +568,7 @@ void STKMeshSceneNode::render()
|
||||
#endif
|
||||
Shaders::TransparentShader::getInstance()->setTextureUnits(getTextureGLuint(mesh.textures[0]));
|
||||
|
||||
Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix);
|
||||
Shaders::TransparentShader::getInstance()->setUniforms(AbsoluteTransformation, mesh.TextureMatrix, 1.0f);
|
||||
assert(mesh.vao);
|
||||
glBindVertexArray(mesh.vao);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
|
||||
@@ -340,14 +340,24 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector<scene::ISceneNode *> *Immed
|
||||
else
|
||||
{
|
||||
for (GLMesh *mesh : node->TransparentMesh[TM_DEFAULT])
|
||||
pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
|
||||
pushVector(ListBlendTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f);
|
||||
for (GLMesh *mesh : node->TransparentMesh[TM_ADDITIVE])
|
||||
pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
|
||||
pushVector(ListAdditiveTransparent::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, 1.0f);
|
||||
}
|
||||
|
||||
// Use sun color to determine custom alpha for ghost karts
|
||||
float custom_alpha = 1.0f;
|
||||
if (World::getWorld())
|
||||
{
|
||||
const video::SColor& c = World::getWorld()->getTrack()->getSunColor();
|
||||
float y = 0.2126f * c.getRed() + 0.7152f * c.getGreen() + 0.0722f * c.getBlue();
|
||||
custom_alpha = y > 128.0f ? 0.5f : 0.2f;
|
||||
}
|
||||
|
||||
for (GLMesh *mesh : node->TransparentMesh[TM_GHOST_KART])
|
||||
pushVector(ListGhostKart::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
|
||||
pushVector(ListGhostKart::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha);
|
||||
for (GLMesh *mesh : node->TransparentMesh[TM_GHOST_KART_TANGENTS])
|
||||
pushVector(ListGhostKartTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix);
|
||||
pushVector(ListGhostKartTangents::getInstance(), mesh, Node->getAbsoluteTransformation(), mesh->TextureMatrix, custom_alpha);
|
||||
for (GLMesh *mesh : node->TransparentMesh[TM_DISPLACEMENT])
|
||||
pushVector(ListDisplacement::getInstance(), mesh, Node->getAbsoluteTransformation());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user