diff --git a/Shaders/transition.frag b/Shaders/transition.frag index da9935f38..99dbb38bb 100644 --- a/Shaders/transition.frag +++ b/Shaders/transition.frag @@ -1,10 +1,12 @@ // -*-C++-*- // Texture switching based on face slope and snow level // based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier. -// � Emilian Huminiuc 2011 +// © Emilian Huminiuc 2011 // Ambient term comes in gl_Color.rgb. -varying vec4 diffuse_term; + +#version 120 + varying vec4 RawPos; varying vec3 normal; varying vec3 Vnormal; @@ -14,11 +16,11 @@ uniform float Transitions; uniform float InverseSlope; uniform float RainNorm; -uniform float CloudCover0; -uniform float CloudCover1; -uniform float CloudCover2; -uniform float CloudCover3; -uniform float CloudCover4; +uniform float CloudCover0; +uniform float CloudCover1; +uniform float CloudCover2; +uniform float CloudCover3; +uniform float CloudCover4; uniform sampler2D BaseTex; uniform sampler2D SecondTex; @@ -64,7 +66,7 @@ void main() cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4); - Noise = texture3D(NoiseTex, RawPos.xyz*0.0011); + Noise = texture3D(NoiseTex, RawPos.xyz * 0.0011); MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary MixFactor *= 300.0; MixFactor = clamp(MixFactor, 0.0, 1.0); @@ -76,16 +78,6 @@ 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)); -// } - 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; @@ -99,15 +91,11 @@ void main() specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf; color = gl_FrontMaterial.emission + - gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient) + + vec4(1.0) * (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 // saturated. Clamping the color before modulating by the texture // is closer to what the OpenGL fixed function pipeline does. @@ -128,7 +116,6 @@ void main() //Do we do an intermediate transition if (Transitions >= 1.5) { if (slope >= L1) { - //texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L1, L1 + 0.03 * MixFactor, slope)); texel = baseTexel; } if (slope >= L2 && slope < L1){ diff --git a/Shaders/transition.vert b/Shaders/transition.vert index bd9261742..abf4861f6 100644 --- a/Shaders/transition.vert +++ b/Shaders/transition.vert @@ -1,65 +1,21 @@ // -*-C++-*- +// -*-C++-*- +// Texture switching based on face slope and snow level +// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier. +// © Emilian Huminiuc 2011 -// Shader that uses OpenGL state values to do per-pixel lighting -// -// The only light used is gl_LightSource[0], which is assumed to be -// directional. -// -// Diffuse colors come from the gl_Color, ambient from the material. This is -// equivalent to osg::Material::DIFFUSE. #version 120 -#define MODE_OFF 0 -#define MODE_DIFFUSE 1 -#define MODE_AMBIENT_AND_DIFFUSE 2 -// The constant term of the lighting equation that doesn't depend on -// the surface normal is passed in gl_{Front,Back}Color. The alpha -// component is set to 1 for front, 0 for back in order to work around -// bugs with gl_FrontFacing in the fragment shader. -varying vec4 diffuse_term, RawPos; -varying vec3 normal, Vnormal; -//varying float fogCoord; -uniform int colorMode; - -// ////fog "include"//////// -// uniform int fogType; -// -// void fog_Func(int type); -// ///////////////////////// +varying vec4 RawPos; +varying vec3 normal; +varying vec3 Vnormal; void main() { RawPos = gl_Vertex; - //vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; normal = normalize(gl_Normal); - Vnormal = gl_NormalMatrix * gl_Normal; - vec4 ambient_color, diffuse_color; - if (colorMode == MODE_DIFFUSE) { - diffuse_color = gl_Color; - ambient_color = gl_FrontMaterial.ambient; - } else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) { - diffuse_color = gl_Color; - ambient_color = gl_Color; - } else { - diffuse_color = gl_FrontMaterial.diffuse; - ambient_color = gl_FrontMaterial.ambient; - } - diffuse_term = diffuse_color * gl_LightSource[0].diffuse; - vec4 constant_term = gl_FrontMaterial.emission + ambient_color * - (gl_LightModel.ambient + gl_LightSource[0].ambient); - // Super hack: if diffuse material alpha is less than 1, assume a - // transparency animation is at work - if (gl_FrontMaterial.diffuse.a < 1.0) - diffuse_term.a = gl_FrontMaterial.diffuse.a; - else - diffuse_term.a = gl_Color.a; - // Another hack for supporting two-sided lighting without using - // gl_FrontFacing in the fragment shader. - gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; - gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; - //fogCoord = abs(ecPosition.z / ecPosition.w); - //fog_Func(fogType); + Vnormal = normalize(gl_NormalMatrix * gl_Normal); }