1
0
Fork 0

Cleanup a bit the transition shaders

Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
Emilian Huminiuc 2012-07-02 23:12:24 +03:00
parent 7eb2e158cd
commit a31dfa779e
2 changed files with 19 additions and 76 deletions

View file

@ -1,10 +1,12 @@
// -*-C++-*- // -*-C++-*-
// Texture switching based on face slope and snow level // Texture switching based on face slope and snow level
// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier. // based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier.
// <EFBFBD> Emilian Huminiuc 2011 // © Emilian Huminiuc 2011
// Ambient term comes in gl_Color.rgb. // Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
#version 120
varying vec4 RawPos; varying vec4 RawPos;
varying vec3 normal; varying vec3 normal;
varying vec3 Vnormal; varying vec3 Vnormal;
@ -14,11 +16,11 @@ uniform float Transitions;
uniform float InverseSlope; uniform float InverseSlope;
uniform float RainNorm; uniform float RainNorm;
uniform float CloudCover0; uniform float CloudCover0;
uniform float CloudCover1; uniform float CloudCover1;
uniform float CloudCover2; uniform float CloudCover2;
uniform float CloudCover3; uniform float CloudCover3;
uniform float CloudCover4; uniform float CloudCover4;
uniform sampler2D BaseTex; uniform sampler2D BaseTex;
uniform sampler2D SecondTex; uniform sampler2D SecondTex;
@ -64,7 +66,7 @@ void main()
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4); 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 = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
MixFactor *= 300.0; MixFactor *= 300.0;
MixFactor = clamp(MixFactor, 0.0, 1.0); MixFactor = clamp(MixFactor, 0.0, 1.0);
@ -76,16 +78,6 @@ void main()
n = (2.0 * gl_Color.a - 1.0) * Vnormal; n = (2.0 * gl_Color.a - 1.0) * Vnormal;
n = normalize(n); 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 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))); float nDotHV = max(0.0, dot(n, normalize(gl_LightSource[0].halfVector.xyz)));
vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
@ -99,15 +91,11 @@ void main()
specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf; specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf;
color = gl_FrontMaterial.emission + 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; Diffuse * gl_FrontMaterial.diffuse;
color += specular * gl_FrontMaterial.specular; color += specular * gl_FrontMaterial.specular;
color.a = diffuse_term.a;
// This shouldn't be necessary, but our lighting becomes very // This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture // saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does. // is closer to what the OpenGL fixed function pipeline does.
@ -128,7 +116,6 @@ void main()
//Do we do an intermediate transition //Do we do an intermediate transition
if (Transitions >= 1.5) { if (Transitions >= 1.5) {
if (slope >= L1) { 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; texel = baseTexel;
} }
if (slope >= L2 && slope < L1){ if (slope >= L2 && slope < L1){

View file

@ -1,65 +1,21 @@
// -*-C++-*- // -*-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 #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 varying vec4 RawPos;
// the surface normal is passed in gl_{Front,Back}Color. The alpha varying vec3 normal;
// component is set to 1 for front, 0 for back in order to work around varying vec3 Vnormal;
// 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);
// /////////////////////////
void main() void main()
{ {
RawPos = gl_Vertex; RawPos = gl_Vertex;
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform(); gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = normalize(gl_Normal); normal = normalize(gl_Normal);
Vnormal = gl_NormalMatrix * gl_Normal; Vnormal = normalize(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);
} }