From f53283be1251e0e14dd5d0ab34d9dd7140ebe8bc Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sat, 6 Nov 2021 15:29:22 +0000 Subject: [PATCH] WS30: Correct orthophoto texture coordinates --- Shaders/ws30-photo.frag | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Shaders/ws30-photo.frag diff --git a/Shaders/ws30-photo.frag b/Shaders/ws30-photo.frag new file mode 100644 index 000000000..a707c362c --- /dev/null +++ b/Shaders/ws30-photo.frag @@ -0,0 +1,68 @@ +// -*-C++-*- + +// Ambient term comes in gl_Color.rgb. +#version 120 + +varying vec4 diffuse_term; +varying vec3 normal; +varying vec2 orthoTexCoord; +varying vec4 ecPosition; + +uniform sampler2D texture; + +////fog "include" ///// +uniform int fogType; + +uniform bool orthophotoAvailable; + +vec3 fog_Func(vec3 color, int type); +////////////////////// + +float getShadowing(); +vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel); + +float luminance(vec3 color) +{ + return dot(vec3(0.212671, 0.715160, 0.072169), color); +} + +void main() +{ + vec3 n; + float NdotL, NdotHV, fogFactor; + vec4 color = gl_Color; + vec3 lightDir = gl_LightSource[0].position.xyz; + vec3 halfVector = gl_LightSource[0].halfVector.xyz; + vec4 texel; + vec4 fragColor; + vec4 specular = vec4(0.0); + + // If gl_Color.a == 0, this is a back-facing polygon and the + // normal should be reversed. + n = (2.0 * gl_Color.a - 1.0) * normal; + n = normalize(n); + + NdotL = dot(n, lightDir); + if (NdotL > 0.0) { + float shadowmap = getShadowing(); + color += diffuse_term * NdotL * shadowmap; + NdotHV = max(dot(n, halfVector), 0.0); + if (gl_FrontMaterial.shininess > 0.0) + specular.rgb = (gl_FrontMaterial.specular.rgb + * gl_LightSource[0].specular.rgb + * pow(NdotHV, gl_FrontMaterial.shininess) + * shadowmap); + } + color.a = diffuse_term.a; + // This shouldn't be necessary, but our lighting becomes very + // saturated. Clamping the color before modulating by the texture + // is closer to what the OpenGL fixed function pipeline does. + color = clamp(color, 0.0, 1.0); + texel = texture2D(texture, vec2(gl_TexCoord[0].s, 1.0 - gl_TexCoord[0].t)); + + fragColor = color * texel + specular; + fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, texel.rgb); + + fragColor.rgb = fog_Func(fragColor.rgb, fogType); + gl_FragColor = fragColor; +}