1
0
Fork 0

More transition.frag cleanups

Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
Emilian Huminiuc 2012-07-02 23:34:00 +03:00
parent a31dfa779e
commit 8174ea8593

View file

@ -37,79 +37,58 @@ vec3 fog_Func(vec3 color, int type);
void main()
{
float MixFactor;
float NdotL;
float NdotHV;
float fogFactor;
float cover;
float slope;
float L1;
float L2;
float wetness;
float pf;
float pf = 0.0;
vec3 n;
vec3 lightDir;
vec3 halfVector;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
vec4 color;
vec4 specular;
vec4 Noise;
vec4 texel = vec4(0.0);
vec4 specular = vec4(0.0);
lightDir = gl_LightSource[0].position.xyz;
halfVector = gl_LightSource[0].halfVector.xyz;
float cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
//color = gl_Color;
specular = vec4(0.0);
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
Noise = texture3D(NoiseTex, RawPos.xyz * 0.0011);
MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
vec4 Noise = texture3D(NoiseTex, RawPos.xyz * 0.0011);
float 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);
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
float L1 = 0.90 - 0.02 * MixFactor; //first transition slope
float L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
// If gl_Color.a == 0, this is a back-facing polygon and the
// Vnormal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * Vnormal;
vec3 n = (2.0 * gl_Color.a - 1.0) * Vnormal;
n = normalize(n);
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;
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
if (nDotVP > 0.0)
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 +
vec4(1.0) * (gl_LightModel.ambient + gl_LightSource[0].ambient) +
Diffuse * gl_FrontMaterial.diffuse;
vec4 diffuseColor = gl_FrontMaterial.emission +
vec4(1.0) * (gl_LightModel.ambient + gl_LightSource[0].ambient) +
Diffuse * gl_FrontMaterial.diffuse;
color += specular * gl_FrontMaterial.specular;
diffuseColor += specular * gl_FrontMaterial.specular;
// 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);
diffuseColor = clamp(diffuseColor, 0.0, 1.0);
//Select texture based on slope
slope = normalize(normal).z;
float slope = normalize(normal).z;
//pull the texture fetch outside flow control to fix aliasing artefacts :(
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
vec4 thirdTexel = texture2D(ThirdTex, gl_TexCoord[0].st);
vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st);
vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
vec4 thirdTexel = texture2D(ThirdTex, gl_TexCoord[0].st);
vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st);
//Normal transition. For more abrupt faces apply another texture (or 2).
if (InverseSlope == 0.0) {
@ -159,10 +138,10 @@ void main()
}
//darken textures with wetness
wetness = 1.0 - 0.3 * RainNorm;
float wetness = 1.0 - 0.3 * RainNorm;
texel.rgb = texel.rgb * wetness;
float altitude = RawPos.z;
float altitude = RawPos.z;
//Snow texture for areas higher than SnowLevel
if (altitude >= SnowLevel - (1000.0 * slope + 300.0 * MixFactor) && slope > L2 - 0.12) {
texel = mix(texel, mix(texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope)),
@ -172,7 +151,7 @@ void main()
);
}
fragColor = color * texel + specular;
vec4 fragColor = diffuseColor * texel + specular;
if(cover >= 2.5){
fragColor.rgb = fragColor.rgb * 1.2;
@ -181,7 +160,6 @@ void main()
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
}
//fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
fragColor.rgb *= 1.2 - 0.4 * MixFactor;
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor;