From c001b6d6793ca045cf93b3c8feec983bae210efe Mon Sep 17 00:00:00 2001 From: Emilian Huminiuc Date: Thu, 28 Jun 2012 14:37:45 +0300 Subject: [PATCH] transition.frag: fix shading ubershader.frag: fix ambient Signed-off-by: Emilian Huminiuc --- Shaders/transition.frag | 42 +++++++++++++++++++++++++++++++---------- Shaders/ubershader.frag | 3 ++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Shaders/transition.frag b/Shaders/transition.frag index 01c3872b7..da9935f38 100644 --- a/Shaders/transition.frag +++ b/Shaders/transition.frag @@ -44,6 +44,7 @@ void main() float L1; float L2; float wetness; + float pf; vec3 n; vec3 lightDir; @@ -58,7 +59,7 @@ void main() lightDir = gl_LightSource[0].position.xyz; halfVector = gl_LightSource[0].halfVector.xyz; - color = gl_Color; + //color = gl_Color; specular = vec4(0.0); cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4); @@ -75,15 +76,36 @@ void main() n = (2.0 * gl_Color.a - 1.0) * Vnormal; n = normalize(n); - NdotL = dot(n, lightDir); - if (NdotL > 0.0) { - color += diffuse_term * NdotL; - 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)); - } +// NdotL = dot(n, lightDir); +// if (NdotL > 0.0) { +// color += diffuse_term * NdotL; +// 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)); +// } + + float nDotVP = max(0.0, dot(n, normalize(gl_LightSource[0].position.xyz))); + float nDotHV = max(0.0, dot(n, normalize(gl_LightSource[0].halfVector.xyz))); + vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; + + if (nDotVP == 0.0) + pf = 0.0; + else + pf = pow(nDotHV, gl_FrontMaterial.shininess); + + if (gl_FrontMaterial.shininess > 0.0) + specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf; + + color = gl_FrontMaterial.emission + + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient) + + Diffuse * gl_FrontMaterial.diffuse; + + color += specular * gl_FrontMaterial.specular; + + + color.a = diffuse_term.a; // This shouldn't be necessary, but our lighting becomes very diff --git a/Shaders/ubershader.frag b/Shaders/ubershader.frag index f674f9d1b..6e135e8aa 100644 --- a/Shaders/ubershader.frag +++ b/Shaders/ubershader.frag @@ -167,7 +167,8 @@ void main (void) // set ambient adjustment to remove bluiness with user input float ambient_offset = clamp(amb_correction, -1.0, 1.0); - vec4 ambient_Correction = vec4(gl_LightSource[0].ambient.rg, gl_LightSource[0].ambient.b * 0.6, 0.5) + vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient; + vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0) * ambient_offset ; ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);