1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00

Improve color mode handling in shaders

This commit is contained in:
Capostrophic 2020-05-09 16:00:00 +03:00
parent 4a1e27ac21
commit c0b322b264
4 changed files with 38 additions and 23 deletions

View file

@ -263,15 +263,21 @@ namespace Shader
case osg::Material::OFF: case osg::Material::OFF:
colorMode = 0; colorMode = 0;
break; break;
case GL_AMBIENT: case osg::Material::EMISSION:
colorMode = 3; colorMode = 1;
break; break;
default: default:
case GL_AMBIENT_AND_DIFFUSE: case osg::Material::AMBIENT_AND_DIFFUSE:
colorMode = 2; colorMode = 2;
break; break;
case GL_EMISSION: case osg::Material::AMBIENT:
colorMode = 1; colorMode = 3;
break;
case osg::Material::DIFFUSE:
colorMode = 4;
break;
case osg::Material::SPECULAR:
colorMode = 5;
break; break;
} }

View file

@ -2,6 +2,13 @@
uniform int colorMode; uniform int colorMode;
const int ColorMode_None = 0;
const int ColorMode_Emission = 1;
const int ColorMode_AmbientAndDiffuse = 2;
const int ColorMode_Ambient = 3;
const int ColorMode_Diffuse = 4;
const int ColorMode_Specular = 5;
void perLight(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 viewPos, vec3 viewNormal, vec4 diffuse, vec3 ambient) void perLight(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 viewPos, vec3 viewNormal, vec4 diffuse, vec3 ambient)
{ {
vec3 lightDir; vec3 lightDir;
@ -22,22 +29,25 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, float shadowing
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadowDiffuse) vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadowDiffuse)
#endif #endif
{ {
vec4 diffuse; vec4 diffuse = gl_FrontMaterial.diffuse;
vec3 ambient; vec3 ambient = gl_FrontMaterial.ambient.xyz;
if (colorMode == 3) vec3 emission = gl_FrontMaterial.emission.xyz;
{ if (colorMode == ColorMode_AmbientAndDiffuse)
diffuse = gl_FrontMaterial.diffuse;
ambient = vertexColor.xyz;
}
else if (colorMode == 2)
{ {
diffuse = vertexColor; diffuse = vertexColor;
ambient = vertexColor.xyz; ambient = vertexColor.xyz;
} }
else else if (colorMode == ColorMode_Ambient)
{ {
diffuse = gl_FrontMaterial.diffuse; ambient = vertexColor.xyz;
ambient = gl_FrontMaterial.ambient.xyz; }
else if (colorMode == ColorMode_Diffuse)
{
diffuse = vertexColor;
}
else if (colorMode == ColorMode_Emission)
{
emission = vertexColor.xyz;
} }
vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a); vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a);
@ -55,12 +65,7 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor, out vec3 shadow
lightResult.xyz += ambientLight + diffuseLight; lightResult.xyz += ambientLight + diffuseLight;
} }
lightResult.xyz += gl_LightModel.ambient.xyz * ambient; lightResult.xyz += gl_LightModel.ambient.xyz * ambient + emission;
if (colorMode == 1)
lightResult.xyz += vertexColor.xyz;
else
lightResult.xyz += gl_FrontMaterial.emission.xyz;
#if @clamp #if @clamp
lightResult = clamp(lightResult, vec4(0.0), vec4(1.0)); lightResult = clamp(lightResult, vec4(0.0), vec4(1.0));

View file

@ -178,6 +178,8 @@ void main()
#else #else
float shininess = gl_FrontMaterial.shininess; float shininess = gl_FrontMaterial.shininess;
vec3 matSpec = gl_FrontMaterial.specular.xyz; vec3 matSpec = gl_FrontMaterial.specular.xyz;
if (colorMode == ColorMode_Specular)
matSpec = passColor.xyz;
#endif #endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing; gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos.xyz), shininess, matSpec) * shadowing;

View file

@ -83,10 +83,12 @@ void main()
#if @specularMap #if @specularMap
float shininess = 128.0; // TODO: make configurable float shininess = 128.0; // TODO: make configurable
vec3 matSpec = vec3(diffuseTex.a, diffuseTex.a, diffuseTex.a); vec3 matSpec = vec3(diffuseTex.a);
#else #else
float shininess = gl_FrontMaterial.shininess; float shininess = gl_FrontMaterial.shininess;
vec3 matSpec = gl_FrontMaterial.specular.xyz; vec3 matSpec = gl_FrontMaterial.specular.xyz;
if (colorMode == ColorMode_Specular)
matSpec = passColor.xyz;
#endif #endif
gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec) * shadowing; gl_FragData[0].xyz += getSpecular(normalize(viewNormal), normalize(passViewPos), shininess, matSpec) * shadowing;