From ec190696ad740cc18a9347670decc0e4a3702ff3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 2 Apr 2014 12:45:47 +0200 Subject: [PATCH] GL3: Unlit material color --HG-- branch : opengl3 --- code/nel/include/nel/3d/program.h | 2 +- .../opengl3/driver_opengl_pixel_program.cpp | 30 ++------ .../driver/opengl3/driver_opengl_program.cpp | 6 +- .../opengl3/driver_opengl_vertex_program.cpp | 75 ++++++++----------- code/nel/src/3d/program.cpp | 2 +- 5 files changed, 45 insertions(+), 70 deletions(-) diff --git a/code/nel/include/nel/3d/program.h b/code/nel/include/nel/3d/program.h index c67e673e5..67ecda6c0 100644 --- a/code/nel/include/nel/3d/program.h +++ b/code/nel/include/nel/3d/program.h @@ -128,7 +128,7 @@ struct CProgramIndex FogColor, Color, - DiffuseColor, + //DiffuseColor, Constant0, Constant1, diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_pixel_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_pixel_program.cpp index d3ad63218..d1863464d 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_pixel_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_pixel_program.cpp @@ -360,7 +360,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc) 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 << g_AttribNames[i] << ";" << std::endl; @@ -435,25 +435,14 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc) 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 << "{" << std::endl; - // Vertex color (light, primary and secondary) - if (desc.VertexFormat & (g_VertexFlags[PrimaryColor])) - { - 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; - } + // Vertex color (light or unlit diffuse, primary and secondary) + ss << "fragColor = vertexColor;" << std::endl; 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) if (driver->m_VPBuiltinCurrent.TexGenMode[stage] >= 0) vertexFormat |= g_VertexFlags[TexCoord0 + stage]; - if (driver->m_VPBuiltinCurrent.Lighting) // Present secondary by primary (vertexColor) - vertexFormat |= g_VertexFlags[PrimaryColor]; - if (vertexFormat & g_VertexFlags[SecondaryColor]) // Present secondary by primary (vertexColor) - { - vertexFormat |= g_VertexFlags[PrimaryColor]; - vertexFormat &= ~g_VertexFlags[SecondaryColor]; - } + vertexFormat &= ~g_VertexFlags[PrimaryColor]; + vertexFormat &= ~g_VertexFlags[SecondaryColor]; // Compare values if (VertexFormat != vertexFormat) diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp index 30ea9ddcd..3e5096ec3 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp @@ -1004,7 +1004,7 @@ void CDriverGL3::setupUniforms(TProgram program) 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) { /*GLfloat glCol[ 4 ]; @@ -1014,8 +1014,8 @@ void CDriverGL3::setupUniforms(TProgram program) glCol[ 2 ] = col.B / 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 matDiffuse = NLMISC::CRGBAF(mat.getDiffuse()); diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp index 9b4d63f1b..664a4b107 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_program.cpp @@ -212,13 +212,11 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc) ss << "smooth out vec4 ecPos;" << std::endl; ss << std::endl; - bool vertexColor = desc.Lighting - || desc.VertexFormat & (g_VertexFlags[PrimaryColor] | g_VertexFlags[SecondaryColor]); - if (vertexColor) - { - ss << "smooth out vec4 vertexColor;" << std::endl; - ss << std::endl; - } + if (!desc.Lighting) + ss << "uniform vec4 materialColor;" << std::endl; // Verify + + ss << "smooth out vec4 vertexColor;" << std::endl; + ss << std::endl; if (desc.Lighting) { @@ -242,17 +240,16 @@ void vpGenerate(std::string &result, const CVPBuiltin &desc) ss << "ecPos = ecPos4;" << std::endl; ss << std::endl; - bool diffuseColor = desc.Lighting || desc.VertexFormat & g_VertexFlags[PrimaryColor]; - bool specularColor = desc.Lighting || desc.VertexFormat & g_VertexFlags[SecondaryColor]; - if (diffuseColor) ss << "vec4 diffuseColor;" << std::endl; - if (specularColor) ss << "vec4 specularColor;" << std::endl; + bool specularVertex = desc.Lighting || desc.VertexFormat & g_VertexFlags[SecondaryColor]; + ss << "vec4 diffuseVertex;" << std::endl; + if (specularVertex) ss << "vec4 specularVertex;" << std::endl; ss << std::endl; if (desc.Lighting) { // Calculate lights - ss << "diffuseColor = 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 << "diffuseVertex = 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 specularLight;" << std::endl; 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) { ss << "getLight" << i << "Color(diffuseLight, specularLight);" << std::endl; - ss << "diffuseColor = diffuseColor + diffuseLight;" << std::endl; - ss << "specularColor = specularColor + specularLight;" << std::endl; + ss << "diffuseVertex = diffuseVertex + diffuseLight;" << std::endl; + ss << "specularVertex = specularVertex + specularLight;" << std::endl; } } - ss << "diffuseColor.a = 1.0;" << std::endl; // ... - ss << "specularColor.a = 1.0;" << std::endl; // ... - // Multiply with vertex colors - if (desc.VertexFormat & g_VertexFlags[PrimaryColor]) - ss << "diffuseColor = diffuseColor * vprimaryColor;" << std::endl; + ss << "diffuseVertex.a = 1.0;" << std::endl; // ... + ss << "specularVertex.a = 1.0;" << std::endl; // ... + + // Secondary color (lighted) if (desc.VertexFormat & g_VertexFlags[SecondaryColor]) - ss << "specularColor = specularColor * vsecondaryColor;" << std::endl; + { + ss << "specularVertex = specularVertex * vsecondaryColor;" << std::endl; + } } else { - if (desc.VertexFormat & g_VertexFlags[PrimaryColor]) - ss << "diffuseColor = vprimaryColor;" << std::endl; + // Unlit + ss << "diffuseVertex = materialColor;" << std::endl; + + // Secondary color (unlit) if (desc.VertexFormat & g_VertexFlags[SecondaryColor]) { - nlwarning("VP: Secondary color in vertex buffer without lighting"); - ss << "specularColor = vsecondaryColor;" << std::endl; + nlwarning("VP: Secondary color in vertex buffer using material without lighting"); + 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 - if (diffuseColor) - { - ss << "vertexColor = diffuseColor;" << std::endl; - 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); - } + ss << "vertexColor = diffuseVertex;" << std::endl; + if (specularVertex) + ss << "vertexColor.rgb = vertexColor.rgb + (specularVertex.rgb * specularVertex.a);" << std::endl; // Verify if (desc.Lighting) - { 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; for (int i = Weight; i < NumOffsets; i++) diff --git a/code/nel/src/3d/program.cpp b/code/nel/src/3d/program.cpp index f16840e2b..9eea17382 100644 --- a/code/nel/src/3d/program.cpp +++ b/code/nel/src/3d/program.cpp @@ -98,7 +98,7 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] = "fogColor", "materialColor", - "diffuseColor", + //"diffuseColor", "constant0", "constant1",