GL3: Unlit material color

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 4913e7dc94
commit ec190696ad

@ -128,7 +128,7 @@ struct CProgramIndex
FogColor, FogColor,
Color, Color,
DiffuseColor, //DiffuseColor,
Constant0, Constant0,
Constant1, Constant1,

@ -360,7 +360,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
for (int i = Weight; i < NumOffsets; i++) for (int i = Weight; i < NumOffsets; i++)
{ {
if (hasFlag(desc.VertexFormat, g_VertexFlags[i]) && (i != PrimaryColor)) if (hasFlag(desc.VertexFormat, g_VertexFlags[i]))
{ {
ss << "smooth in vec4 "; ss << "smooth in vec4 ";
ss << g_AttribNames[i] << ";" << std::endl; ss << g_AttribNames[i] << ";" << std::endl;
@ -435,25 +435,14 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc)
ss << std::endl; ss << std::endl;
} }
if (desc.VertexFormat & (g_VertexFlags[PrimaryColor])) // Note: Lighting and secondary are presented by primary flag ss << "smooth in vec4 vertexColor;" << std::endl;
{ ss << std::endl;
ss << "smooth in vec4 vertexColor;" << std::endl;
ss << std::endl;
}
ss << "void main(void)" << std::endl; ss << "void main(void)" << std::endl;
ss << "{" << std::endl; ss << "{" << std::endl;
// Vertex color (light, primary and secondary) // Vertex color (light or unlit diffuse, primary and secondary)
if (desc.VertexFormat & (g_VertexFlags[PrimaryColor])) ss << "fragColor = vertexColor;" << std::endl;
{
ss << "fragColor = vertexColor;" << std::endl;
// ss << "fragColor.g = 1.0; // DEBUG" << std::endl;
}
else
{
ss << "fragColor = vec4(1.0, 1.0, 1.0, 1.0);" << std::endl;
}
for (uint stage = 0; stage < maxTex; ++stage) for (uint stage = 0; stage < maxTex; ++stage)
{ {
@ -555,13 +544,8 @@ void CPPBuiltin::checkDriverStateTouched(CDriverGL3 *driver) // MUST NOT depend
for (sint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage) for (sint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage)
if (driver->m_VPBuiltinCurrent.TexGenMode[stage] >= 0) if (driver->m_VPBuiltinCurrent.TexGenMode[stage] >= 0)
vertexFormat |= g_VertexFlags[TexCoord0 + stage]; vertexFormat |= g_VertexFlags[TexCoord0 + stage];
if (driver->m_VPBuiltinCurrent.Lighting) // Present secondary by primary (vertexColor) vertexFormat &= ~g_VertexFlags[PrimaryColor];
vertexFormat |= g_VertexFlags[PrimaryColor]; vertexFormat &= ~g_VertexFlags[SecondaryColor];
if (vertexFormat & g_VertexFlags[SecondaryColor]) // Present secondary by primary (vertexColor)
{
vertexFormat |= g_VertexFlags[PrimaryColor];
vertexFormat &= ~g_VertexFlags[SecondaryColor];
}
// Compare values // Compare values
if (VertexFormat != vertexFormat) if (VertexFormat != vertexFormat)

@ -1004,7 +1004,7 @@ void CDriverGL3::setupUniforms(TProgram program)
nglProgramUniform4f(progId, colorIndex, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]); nglProgramUniform4f(progId, colorIndex, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
} }
uint diffuseIndex = p->getUniformIndex(CProgramIndex::DiffuseColor); /*uint diffuseIndex = p->getUniformIndex(CProgramIndex::DiffuseColor);
if (diffuseIndex != ~0) if (diffuseIndex != ~0)
{ {
/*GLfloat glCol[ 4 ]; /*GLfloat glCol[ 4 ];
@ -1014,8 +1014,8 @@ void CDriverGL3::setupUniforms(TProgram program)
glCol[ 2 ] = col.B / 255.0f; glCol[ 2 ] = col.B / 255.0f;
glCol[ 3 ] = col.A / 255.0f;*/ glCol[ 3 ] = col.A / 255.0f;*/
nglProgramUniform4f(progId, diffuseIndex, 1.0f, 1.0f, 1.0f, 0.0f); /*nglProgramUniform4f(progId, diffuseIndex, 1.0f, 1.0f, 1.0f, 0.0f);
} }*/
NLMISC::CRGBAF selfIllumination = NLMISC::CRGBAF(0.0f, 0.0f, 0.0f); NLMISC::CRGBAF selfIllumination = NLMISC::CRGBAF(0.0f, 0.0f, 0.0f);
NLMISC::CRGBAF matDiffuse = NLMISC::CRGBAF(mat.getDiffuse()); NLMISC::CRGBAF matDiffuse = NLMISC::CRGBAF(mat.getDiffuse());

@ -212,13 +212,11 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc)
ss << "smooth out vec4 ecPos;" << std::endl; ss << "smooth out vec4 ecPos;" << std::endl;
ss << std::endl; ss << std::endl;
bool vertexColor = desc.Lighting if (!desc.Lighting)
|| desc.VertexFormat & (g_VertexFlags[PrimaryColor] | g_VertexFlags[SecondaryColor]); ss << "uniform vec4 materialColor;" << std::endl; // Verify
if (vertexColor)
{ ss << "smooth out vec4 vertexColor;" << std::endl;
ss << "smooth out vec4 vertexColor;" << std::endl; ss << std::endl;
ss << std::endl;
}
if (desc.Lighting) if (desc.Lighting)
{ {
@ -242,17 +240,16 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc)
ss << "ecPos = ecPos4;" << std::endl; ss << "ecPos = ecPos4;" << std::endl;
ss << std::endl; ss << std::endl;
bool diffuseColor = desc.Lighting || desc.VertexFormat & g_VertexFlags[PrimaryColor]; bool specularVertex = desc.Lighting || desc.VertexFormat & g_VertexFlags[SecondaryColor];
bool specularColor = desc.Lighting || desc.VertexFormat & g_VertexFlags[SecondaryColor]; ss << "vec4 diffuseVertex;" << std::endl;
if (diffuseColor) ss << "vec4 diffuseColor;" << std::endl; if (specularVertex) ss << "vec4 specularVertex;" << std::endl;
if (specularColor) ss << "vec4 specularColor;" << std::endl;
ss << std::endl; ss << std::endl;
if (desc.Lighting) if (desc.Lighting)
{ {
// Calculate lights // Calculate lights
ss << "diffuseColor = vec4(0.0, 0.0, 0.0, 0.0);" << std::endl; ss << "diffuseVertex = vec4(0.0, 0.0, 0.0, 0.0);" << std::endl;
ss << "specularColor = vec4(0.0, 0.0, 0.0, 0.0);" << std::endl; ss << "specularVertex = vec4(0.0, 0.0, 0.0, 0.0);" << std::endl;
ss << "vec4 diffuseLight;" << std::endl; ss << "vec4 diffuseLight;" << std::endl;
ss << "vec4 specularLight;" << std::endl; ss << "vec4 specularLight;" << std::endl;
for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++) for (int i = 0; i < NL_OPENGL3_MAX_LIGHT; i++)
@ -260,48 +257,42 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc)
if (desc.LightMode[i] == CLight::DirectionalLight || desc.LightMode[i] == CLight::PointLight) if (desc.LightMode[i] == CLight::DirectionalLight || desc.LightMode[i] == CLight::PointLight)
{ {
ss << "getLight" << i << "Color(diffuseLight, specularLight);" << std::endl; ss << "getLight" << i << "Color(diffuseLight, specularLight);" << std::endl;
ss << "diffuseColor = diffuseColor + diffuseLight;" << std::endl; ss << "diffuseVertex = diffuseVertex + diffuseLight;" << std::endl;
ss << "specularColor = specularColor + specularLight;" << std::endl; ss << "specularVertex = specularVertex + specularLight;" << std::endl;
} }
} }
ss << "diffuseColor.a = 1.0;" << std::endl; // ... ss << "diffuseVertex.a = 1.0;" << std::endl; // ...
ss << "specularColor.a = 1.0;" << std::endl; // ... ss << "specularVertex.a = 1.0;" << std::endl; // ...
// Multiply with vertex colors
if (desc.VertexFormat & g_VertexFlags[PrimaryColor]) // Secondary color (lighted)
ss << "diffuseColor = diffuseColor * vprimaryColor;" << std::endl;
if (desc.VertexFormat & g_VertexFlags[SecondaryColor]) if (desc.VertexFormat & g_VertexFlags[SecondaryColor])
ss << "specularColor = specularColor * vsecondaryColor;" << std::endl; {
ss << "specularVertex = specularVertex * vsecondaryColor;" << std::endl;
}
} }
else else
{ {
if (desc.VertexFormat & g_VertexFlags[PrimaryColor]) // Unlit
ss << "diffuseColor = vprimaryColor;" << std::endl; ss << "diffuseVertex = materialColor;" << std::endl;
// Secondary color (unlit)
if (desc.VertexFormat & g_VertexFlags[SecondaryColor]) if (desc.VertexFormat & g_VertexFlags[SecondaryColor])
{ {
nlwarning("VP: Secondary color in vertex buffer without lighting"); nlwarning("VP: Secondary color in vertex buffer using material without lighting");
ss << "specularColor = vsecondaryColor;" << std::endl; ss << "specularVertex = vsecondaryColor;" << std::endl;
} }
} }
// Primary color
if (desc.VertexFormat & g_VertexFlags[PrimaryColor])
ss << "diffuseVertex = diffuseVertex * vprimaryColor;" << std::endl; // Note: Might need to replace materialColor if PrimaryColor exists
// Add diffuse and specular color // Add diffuse and specular color
if (diffuseColor) ss << "vertexColor = diffuseVertex;" << std::endl;
{ if (specularVertex)
ss << "vertexColor = diffuseColor;" << std::endl; ss << "vertexColor.rgb = vertexColor.rgb + (specularVertex.rgb * specularVertex.a);" << std::endl; // Verify
if (specularColor) ss << "vertexColor.rgb = vertexColor.rgb + (specularColor.rgb * specularColor.a);" << std::endl; // Verify
}
else if (specularColor)
{
nlwarning("VP: Vertex color only consists of specular color");
ss << "vertexColor = specularColor;" << std::endl;
}
else
{
nlassert(!vertexColor);
}
if (desc.Lighting) if (desc.Lighting)
{
ss << "vertexColor.rgb = vertexColor.rgb + selfIllumination.rgb;" << std::endl; // Note: Alpha of self illumination is ignored ss << "vertexColor.rgb = vertexColor.rgb + selfIllumination.rgb;" << std::endl; // Note: Alpha of self illumination is ignored
// ss << "vertexColor.r = 1.0; // DEBUG" << std::endl;
}
ss << std::endl; ss << std::endl;
for (int i = Weight; i < NumOffsets; i++) for (int i = Weight; i < NumOffsets; i++)

@ -98,7 +98,7 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] =
"fogColor", "fogColor",
"materialColor", "materialColor",
"diffuseColor", //"diffuseColor",
"constant0", "constant0",
"constant1", "constant1",

Loading…
Cancel
Save