mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Use diffuse.a / vertex.a, use material emission
This commit is contained in:
parent
5fd84074c5
commit
456816f707
3 changed files with 22 additions and 13 deletions
|
@ -120,7 +120,7 @@ namespace Shader
|
|||
case GL_AMBIENT_AND_DIFFUSE:
|
||||
defineMap["colorMode"] = "2";
|
||||
break;
|
||||
case GL_AMBIENT:
|
||||
case GL_EMISSION:
|
||||
defineMap["colorMode"] = "1";
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ varying vec2 emissiveMapUV;
|
|||
|
||||
varying float depth;
|
||||
|
||||
varying vec3 lighting;
|
||||
varying vec4 lighting;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ void main()
|
|||
gl_FragData[0].xyz *= texture2D(darkMap, darkMapUV).xyz;
|
||||
#endif
|
||||
|
||||
gl_FragData[0].xyz *= lighting;
|
||||
gl_FragData[0] *= lighting;
|
||||
|
||||
#if @emissiveMap
|
||||
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||
|
|
|
@ -18,24 +18,24 @@ varying vec2 emissiveMapUV;
|
|||
|
||||
varying float depth;
|
||||
|
||||
varying vec3 lighting;
|
||||
varying vec4 lighting;
|
||||
|
||||
#define MAX_LIGHTS 8
|
||||
|
||||
vec3 doLighting(vec3 viewPos, vec3 viewNormal, vec3 vertexColor)
|
||||
vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor)
|
||||
{
|
||||
vec3 lightDir;
|
||||
float d;
|
||||
|
||||
#if @colorMode == 2
|
||||
vec3 diffuse = vertexColor;
|
||||
vec3 ambient = vertexColor;
|
||||
vec4 diffuse = vertexColor;
|
||||
vec3 ambient = vertexColor.xyz;
|
||||
#else
|
||||
vec3 diffuse = gl_FrontMaterial.diffuse.xyz;
|
||||
vec4 diffuse = gl_FrontMaterial.diffuse;
|
||||
vec3 ambient = gl_FrontMaterial.ambient.xyz;
|
||||
#endif
|
||||
vec4 lightResult = vec4(0.0, 0.0, 0.0, diffuse.a);
|
||||
|
||||
vec3 lightResult = vec3(0.0, 0.0, 0.0);
|
||||
for (int i=0; i<MAX_LIGHTS; ++i)
|
||||
{
|
||||
lightDir = gl_LightSource[i].position.xyz - (viewPos.xyz * gl_LightSource[i].position.w);
|
||||
|
@ -43,11 +43,17 @@ vec3 doLighting(vec3 viewPos, vec3 viewNormal, vec3 vertexColor)
|
|||
lightDir = normalize(lightDir);
|
||||
|
||||
lightResult.xyz += ambient * gl_LightSource[i].ambient.xyz;
|
||||
lightResult.xyz += diffuse * gl_LightSource[i].diffuse.xyz * clamp(1.0 / (gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d), 0.0, 1.0)
|
||||
lightResult.xyz += diffuse.xyz * gl_LightSource[i].diffuse.xyz * clamp(1.0 / (gl_LightSource[i].constantAttenuation + gl_LightSource[i].linearAttenuation * d + gl_LightSource[i].quadraticAttenuation * d * d), 0.0, 1.0)
|
||||
* max(dot(viewNormal.xyz, lightDir), 0.0);
|
||||
}
|
||||
|
||||
lightResult += gl_LightModel.ambient.xyz * ambient;
|
||||
lightResult.xyz += gl_LightModel.ambient.xyz * ambient;
|
||||
|
||||
#if @colorMode == 1
|
||||
lightResult.xyz += vertexColor.xyz;
|
||||
#else
|
||||
lightResult.xyz += gl_FrontMaterial.emission.xyz;
|
||||
#endif
|
||||
|
||||
return lightResult;
|
||||
}
|
||||
|
@ -78,6 +84,9 @@ void main(void)
|
|||
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
|
||||
#endif
|
||||
|
||||
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color.xyz);
|
||||
lighting = clamp(lighting, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));
|
||||
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color);
|
||||
|
||||
// TODO: make clamp configurable
|
||||
// the following produces fixed-function compatible lighting, w/o clamp arguably looks better
|
||||
//lighting = clamp(lighting, vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue