Reduces code duplication of specular calculation in shaders.
Differential Revision: https://code.wildfiregames.com/D5178 This was SVN commit r27924.
This commit is contained in:
parent
84d935444f
commit
debbcba9a6
@ -15,6 +15,11 @@ vec3 calculateNormal(vec3 surfaceNormal, vec3 packedTextureNormal, mat3 tangentB
|
||||
return normal;
|
||||
}
|
||||
|
||||
vec3 calculateSpecular(vec3 normal, vec3 vhalf, vec3 sunColor, vec3 color, float power)
|
||||
{
|
||||
return sunColor * color * pow(max(0.001, dot(normal, vhalf)), power);
|
||||
}
|
||||
|
||||
vec3 calculateShading(vec3 albedo, vec3 sunDiffuse, vec3 specular, vec3 ambient, float shadow, float ao)
|
||||
{
|
||||
return (albedo * sunDiffuse + specular.rgb) * shadow + albedo * ambient * ao;
|
||||
|
@ -102,25 +102,24 @@ void main()
|
||||
vec3 sundiffuse = v_lighting;
|
||||
#endif
|
||||
|
||||
vec4 specular = vec4(0.0);
|
||||
vec3 specular = vec3(0.0);
|
||||
float emissionWeight = 0.0;
|
||||
#if USE_SPECULAR_MAP
|
||||
vec3 specCol;
|
||||
float specPow;
|
||||
#if USE_TRIPLANAR
|
||||
vec4 s = triplanar(GET_DRAW_TEXTURE_2D(specTex), v_tex);
|
||||
#else
|
||||
vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), v_tex);
|
||||
#endif
|
||||
specCol = s.rgb;
|
||||
specular.a = s.a;
|
||||
specPow = effectSettings.y;
|
||||
specular.rgb = sunColor * specCol * pow(max(0.001, dot(normalize(normal), v_half)), specPow);
|
||||
vec3 specCol = s.rgb;
|
||||
float specPow = effectSettings.y;
|
||||
specular = calculateSpecular(normal, normalize(v_half), sunColor, specCol, specPow);
|
||||
emissionWeight = s.a;
|
||||
#endif
|
||||
|
||||
vec3 color = calculateShading(texdiffuse, sundiffuse, specular.rgb, ambient, getShadowOnLandscape(), 1.0);
|
||||
vec3 color = calculateShading(texdiffuse, sundiffuse, specular, ambient, getShadowOnLandscape(), 1.0);
|
||||
|
||||
#if USE_SPECULAR_MAP && USE_SELF_LIGHT
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
color = mix(texdiffuse, color, emissionWeight);
|
||||
#endif
|
||||
|
||||
color = applyFog(color, fogColor, fogParams);
|
||||
|
@ -89,13 +89,14 @@ void main()
|
||||
vec3 sundiffuse = v_lighting.rgb;
|
||||
#endif
|
||||
|
||||
vec4 specular = vec4(0.0);
|
||||
vec3 specular = vec3(0.0);
|
||||
float emissionWeight = 0.0;
|
||||
#if USE_SPECULAR_MAP
|
||||
vec4 s = SAMPLE_2D(GET_DRAW_TEXTURE_2D(specTex), coord);
|
||||
vec3 specCol = s.rgb;
|
||||
specular.a = s.a;
|
||||
float specPow = effectSettings.y;
|
||||
specular.rgb = sunColor * specCol * pow(max(0.001, dot(normalize(normal), v_half)), specPow);
|
||||
specular = calculateSpecular(normal, normalize(v_half), sunColor, specCol, specPow);
|
||||
emissionWeight = s.a;
|
||||
#endif
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
@ -104,10 +105,10 @@ void main()
|
||||
float ao = 1.0;
|
||||
#endif
|
||||
|
||||
vec3 color = calculateShading(texdiffuse, sundiffuse, specular.rgb, ambient, getShadow(), ao);
|
||||
vec3 color = calculateShading(texdiffuse, sundiffuse, specular, ambient, getShadow(), ao);
|
||||
|
||||
#if USE_SPECULAR_MAP && USE_SELF_LIGHT
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
color = mix(texdiffuse, color, emissionWeight);
|
||||
#endif
|
||||
|
||||
color = applyFog(color, fogColor, fogParams);
|
||||
|
Loading…
Reference in New Issue
Block a user