forked from Mirrors/openclonk
Illuminate materials with no backface culling from both sides
This might need adaptions in some materials, but is probably the right thing to do.Controls
parent
572c582265
commit
a172245c1e
|
@ -4,6 +4,7 @@
|
|||
#ifdef HAVE_LIGHT
|
||||
uniform sampler2D lightTex;
|
||||
#endif
|
||||
uniform float cullMode; // 0 if backface culling is enabled, 1 if it is disabled
|
||||
|
||||
// uncomment the following lines for debugging light directions:
|
||||
// yellow: light up, blue: light down, turqoise: light right, pink: light left
|
||||
|
@ -55,9 +56,9 @@ slice(texture+5)
|
|||
|
||||
slice(light)
|
||||
{
|
||||
float light = 2.0 * lightBright * max(dot(normal, lightDir), 0.0);
|
||||
float light = 2.0 * lightBright * max(max(dot(normal, lightDir), 0.0), cullMode * max(dot(vec3(-normal.xy, normal.z), lightDir), 0.0));
|
||||
#ifdef HAVE_2PX
|
||||
float light2 = 2.0 * lightBright * max(dot(normal2, lightDir), 0.0);
|
||||
float light2 = 2.0 * lightBright * max(max(dot(normal2, lightDir), 0.0), cullMode * max(dot(vec3(-normal2.xy, normal2.z), lightDir), 0.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -399,6 +399,8 @@ void CStdGL::SetupMultiBlt(C4ShaderCall& call, const C4BltTransform* pTransform,
|
|||
call.SetUniformMatrix2x3fv(C4SSU_AmbientTransform, 1, ambientTransform);
|
||||
}
|
||||
|
||||
call.SetUniform1f(C4SSU_CullMode, 0.0f);
|
||||
|
||||
// Apply zoom and transform
|
||||
glPushMatrix();
|
||||
glTranslatef(ZoomX, ZoomY, 0.0f);
|
||||
|
@ -580,6 +582,7 @@ bool CStdGL::CreateSpriteShader(C4Shader& shader, const char* name, int ssc, C4G
|
|||
uniformNames[C4SSU_AmbientTransform] = "ambientTransform";
|
||||
uniformNames[C4SSU_AmbientBrightness] = "ambientBrightness";
|
||||
uniformNames[C4SSU_Bones] = "bones";
|
||||
uniformNames[C4SSU_CullMode] = "cullMode";
|
||||
uniformNames[C4SSU_Count] = NULL;
|
||||
|
||||
// Clear previous content
|
||||
|
|
|
@ -70,6 +70,7 @@ enum C4SS_Uniforms
|
|||
C4SSU_AmbientBrightness, // C4SSC_LIGHT
|
||||
|
||||
C4SSU_Bones, // for meshes
|
||||
C4SSU_CullMode, // for meshes
|
||||
|
||||
C4SSU_Count
|
||||
};
|
||||
|
|
|
@ -415,7 +415,7 @@ namespace
|
|||
return true;
|
||||
}
|
||||
|
||||
void SetStandardUniforms(C4ShaderCall& call, DWORD dwModClr, DWORD dwPlayerColor, DWORD dwBlitMode, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect)
|
||||
void SetStandardUniforms(C4ShaderCall& call, DWORD dwModClr, DWORD dwPlayerColor, DWORD dwBlitMode, bool cullFace, const C4FoWRegion* pFoW, const C4Rect& clipRect, const C4Rect& outRect)
|
||||
{
|
||||
// Draw transform
|
||||
const float fMod[4] = {
|
||||
|
@ -434,6 +434,9 @@ namespace
|
|||
};
|
||||
call.SetUniform3fv(C4SSU_OverlayClr, 1, fPlrClr);
|
||||
|
||||
// Backface culling flag
|
||||
call.SetUniform1f(C4SSU_CullMode, cullFace ? 0.0f : 1.0f);
|
||||
|
||||
// Dynamic light
|
||||
if(pFoW != NULL)
|
||||
{
|
||||
|
@ -582,10 +585,12 @@ namespace
|
|||
|
||||
// Upload the current bone transformation matrixes (if there are any)
|
||||
if (!bones.empty())
|
||||
{
|
||||
if (pGL->Workarounds.LowMaxVertexUniformCount)
|
||||
glUniformMatrix3x4fv(shader->GetUniform(C4SSU_Bones), bones.size(), GL_FALSE, &bones[0].m[0][0]);
|
||||
else
|
||||
glUniformMatrix4x3fv(shader->GetUniform(C4SSU_Bones), bones.size(), GL_TRUE, &bones[0].m[0][0]);
|
||||
}
|
||||
|
||||
// Bind the vertex data of the mesh
|
||||
#define VERTEX_OFFSET(field) reinterpret_cast<const uint8_t *>(offsetof(StdMeshVertex, field))
|
||||
|
@ -665,7 +670,7 @@ namespace
|
|||
}
|
||||
|
||||
// Set uniforms and instance parameters
|
||||
SetStandardUniforms(call, dwModClr, dwPlayerColor, dwBlitMode, pFoW, clipRect, outRect);
|
||||
SetStandardUniforms(call, dwModClr, dwPlayerColor, dwBlitMode, pass.CullHardware != StdMeshMaterialPass::CH_None, pFoW, clipRect, outRect);
|
||||
for(unsigned int i = 0; i < pass.Program->Parameters.size(); ++i)
|
||||
{
|
||||
const int uniform = pass.Program->Parameters[i].UniformIndex;
|
||||
|
|
|
@ -863,6 +863,7 @@ bool StdMeshMaterialProgram::CompileShader(StdMeshMaterialLoader& loader, C4Shad
|
|||
uniformNames[C4SSU_AmbientTransform] = "ambientTransform";
|
||||
uniformNames[C4SSU_AmbientBrightness] = "ambientBrightness";
|
||||
uniformNames[C4SSU_Bones] = "bones";
|
||||
uniformNames[C4SSU_CullMode] = "cullMode";
|
||||
for (unsigned int i = 0; i < ParameterNames.size(); ++i)
|
||||
uniformNames[C4SSU_Count + i] = ParameterNames[i].getData();
|
||||
uniformNames[C4SSU_Count + ParameterNames.size()] = NULL;
|
||||
|
|
Loading…
Reference in New Issue