mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Convert colorMode shader define to a uniform
This commit is contained in:
parent
0124be5713
commit
ce15369bbd
4 changed files with 47 additions and 42 deletions
|
@ -23,8 +23,6 @@ namespace Shader
|
|||
|
||||
ShaderVisitor::ShaderRequirements::ShaderRequirements()
|
||||
: mShaderRequired(false)
|
||||
, mColorMaterial(false)
|
||||
, mVertexColorMode(GL_AMBIENT_AND_DIFFUSE)
|
||||
, mMaterialOverridden(false)
|
||||
, mNormalHeight(false)
|
||||
, mTexStageRequiringTangents(-1)
|
||||
|
@ -230,8 +228,29 @@ namespace Shader
|
|||
mRequirements.back().mMaterialOverridden = true;
|
||||
|
||||
const osg::Material* mat = static_cast<const osg::Material*>(it->second.first.get());
|
||||
mRequirements.back().mColorMaterial = (mat->getColorMode() != osg::Material::OFF);
|
||||
mRequirements.back().mVertexColorMode = mat->getColorMode();
|
||||
|
||||
if (!writableStateSet)
|
||||
writableStateSet = getWritableStateSet(node);
|
||||
|
||||
int colorMode;
|
||||
switch (mat->getColorMode())
|
||||
{
|
||||
case osg::Material::OFF:
|
||||
colorMode = 0;
|
||||
break;
|
||||
case GL_AMBIENT:
|
||||
colorMode = 3;
|
||||
break;
|
||||
default:
|
||||
case GL_AMBIENT_AND_DIFFUSE:
|
||||
colorMode = 2;
|
||||
break;
|
||||
case GL_EMISSION:
|
||||
colorMode = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
writableStateSet->addUniform(new osg::Uniform("colorMode", colorMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,25 +291,6 @@ namespace Shader
|
|||
defineMap[texIt->second + std::string("UV")] = std::to_string(texIt->first);
|
||||
}
|
||||
|
||||
if (!reqs.mColorMaterial)
|
||||
defineMap["colorMode"] = "0";
|
||||
else
|
||||
{
|
||||
switch (reqs.mVertexColorMode)
|
||||
{
|
||||
case GL_AMBIENT:
|
||||
defineMap["colorMode"] = "3";
|
||||
break;
|
||||
default:
|
||||
case GL_AMBIENT_AND_DIFFUSE:
|
||||
defineMap["colorMode"] = "2";
|
||||
break;
|
||||
case GL_EMISSION:
|
||||
defineMap["colorMode"] = "1";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
defineMap["forcePPL"] = mForcePerPixelLighting ? "1" : "0";
|
||||
defineMap["clamp"] = mClampLighting ? "1" : "0";
|
||||
|
||||
|
|
|
@ -81,9 +81,6 @@ namespace Shader
|
|||
|
||||
bool mShaderRequired;
|
||||
|
||||
bool mColorMaterial;
|
||||
// osg::Material::ColorMode
|
||||
int mVertexColorMode;
|
||||
bool mMaterialOverridden;
|
||||
bool mNormalHeight; // true if normal map has height info in alpha channel
|
||||
|
||||
|
|
|
@ -218,7 +218,6 @@ namespace Terrain
|
|||
defineMap["clamp"] = clampLighting ? "1" : "0";
|
||||
defineMap["normalMap"] = (it->mNormalMap) ? "1" : "0";
|
||||
defineMap["blendMap"] = !firstLayer ? "1" : "0";
|
||||
defineMap["colorMode"] = "2";
|
||||
defineMap["specularMap"] = it->mSpecular ? "1" : "0";
|
||||
defineMap["parallax"] = (it->mNormalMap && it->mParallax) ? "1" : "0";
|
||||
|
||||
|
@ -231,6 +230,7 @@ namespace Terrain
|
|||
}
|
||||
|
||||
stateset->setAttributeAndModes(shaderManager->getProgram(vertexShader, fragmentShader));
|
||||
stateset->addUniform(new osg::Uniform("colorMode", 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#define MAX_LIGHTS 8
|
||||
|
||||
uniform int colorMode;
|
||||
|
||||
void perLight(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 viewPos, vec3 viewNormal, vec4 diffuse, vec3 ambient)
|
||||
{
|
||||
vec3 lightDir;
|
||||
|
@ -20,16 +22,23 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, float shadowing
|
|||
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadowDiffuse)
|
||||
#endif
|
||||
{
|
||||
#if @colorMode == 3
|
||||
vec4 diffuse = gl_FrontMaterial.diffuse;
|
||||
vec3 ambient = vertexColor.xyz;
|
||||
#elif @colorMode == 2
|
||||
vec4 diffuse = vertexColor;
|
||||
vec3 ambient = vertexColor.xyz;
|
||||
#else
|
||||
vec4 diffuse = gl_FrontMaterial.diffuse;
|
||||
vec3 ambient = gl_FrontMaterial.ambient.xyz;
|
||||
#endif
|
||||
vec4 diffuse;
|
||||
vec3 ambient;
|
||||
if (colorMode == 3)
|
||||
{
|
||||
diffuse = gl_FrontMaterial.diffuse;
|
||||
ambient - vertexColor.xyz;
|
||||
}
|
||||
else if (colorMode == 2)
|
||||
{
|
||||
diffuse = vertexColor;
|
||||
ambient = vertexColor.xyz;
|
||||
}
|
||||
else
|
||||
{
|
||||
diffuse = gl_FrontMaterial.diffuse;
|
||||
ambient = gl_FrontMaterial.ambient.xyz;
|
||||
}
|
||||
vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a);
|
||||
|
||||
vec3 diffuseLight, ambientLight;
|
||||
|
@ -48,11 +57,10 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadow
|
|||
|
||||
lightResult.xyz += gl_LightModel.ambient.xyz * ambient;
|
||||
|
||||
#if @colorMode == 1
|
||||
lightResult.xyz += vertexColor.xyz;
|
||||
#else
|
||||
lightResult.xyz += gl_FrontMaterial.emission.xyz;
|
||||
#endif
|
||||
if (colorMode == 1)
|
||||
lightResult.xyz += vertexColor.xyz;
|
||||
else
|
||||
lightResult.xyz += gl_FrontMaterial.emission.xyz;
|
||||
|
||||
#if @clamp
|
||||
lightResult = clamp(lightResult, vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
|
||||
|
|
Loading…
Reference in a new issue