Ati compliance fixes to transition / water shaders, made under the direction of i4dnf on IRC. Makes Ati+mac drivers happy.
This commit is contained in:
parent
dc3d2b5b49
commit
6fb93dbf96
3 changed files with 74 additions and 63 deletions
|
@ -3,6 +3,7 @@
|
|||
// default.frag (c) 2010 ??
|
||||
// (c)2011 - Emilian Huminiuc, with ideas from crop.frag, forest.frag
|
||||
// Ambient term comes in gl_Color.rgb.
|
||||
#version 120
|
||||
varying vec4 diffuse_term, RawPos;
|
||||
varying vec3 Vnormal, normal;
|
||||
varying float fogCoord;
|
||||
|
@ -28,7 +29,7 @@ void main()
|
|||
|
||||
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;
|
||||
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
|
||||
|
@ -58,74 +59,82 @@ void main()
|
|||
//Select texture based on slope
|
||||
slope = normalize(normal).z;
|
||||
|
||||
//Normal transition. For more abrupt faces apply another texture (or 2).
|
||||
if (InverseSlope == 0.0) {
|
||||
//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 = texture2D(BaseTex, gl_TexCoord[0].st);
|
||||
}
|
||||
if (slope >= L2 && slope < L1){
|
||||
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2, L1 - 0.06 * MixFactor, slope));
|
||||
}
|
||||
if (slope < L2){
|
||||
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), smoothstep(L2 - 0.13 * MixFactor, L2, slope));
|
||||
}
|
||||
// Just one transition
|
||||
} else if (Transitions < 1.5) {
|
||||
if (slope >= L1) {
|
||||
texel = texture2D(BaseTex, gl_TexCoord[0].st);
|
||||
}
|
||||
if (slope < L1) {
|
||||
texel = mix(texture2D(ThirdTex, gl_TexCoord[0].st), texture2D(BaseTex, gl_TexCoord[0].st), smoothstep(L2 - 0.13 * MixFactor, L1, slope));
|
||||
}
|
||||
}
|
||||
//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 * 2.0);
|
||||
//Normal transition. For more abrupt faces apply another texture (or 2).
|
||||
if (InverseSlope == 0.0) {
|
||||
//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){
|
||||
texel = mix(secondTexel, baseTexel, smoothstep(L2, L1 - 0.06 * MixFactor, slope));
|
||||
}
|
||||
if (slope < L2){
|
||||
texel = mix(thirdTexel, secondTexel, smoothstep(L2 - 0.13 * MixFactor, L2, slope));
|
||||
}
|
||||
// Just one transition
|
||||
} else if (Transitions < 1.5) {
|
||||
if (slope >= L1) {
|
||||
texel = baseTexel;
|
||||
}
|
||||
if (slope < L1) {
|
||||
texel = mix(thirdTexel, baseTexel, smoothstep(L2 - 0.13 * MixFactor, L1, slope));
|
||||
}
|
||||
}
|
||||
|
||||
//Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
|
||||
} else if (InverseSlope > 0.0) {
|
||||
//Interemdiate transition ?
|
||||
if (Transitions >= 1.5) {
|
||||
if (slope >= L1 + 0.1) {
|
||||
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
||||
}
|
||||
if (slope >= L2 && slope < L1 + 0.1){
|
||||
texel = mix(texture2D(SecondTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
|
||||
}
|
||||
if (slope <= L2){
|
||||
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(SecondTex, gl_TexCoord[0].st), smoothstep(L2 - 0.06 * MixFactor, L2, slope));
|
||||
}
|
||||
//just one
|
||||
} else if (Transitions < 1.5) {
|
||||
if (slope > L1 + 0.1) {
|
||||
texel = texture2D(ThirdTex, gl_TexCoord[0].st);
|
||||
}
|
||||
if (slope <= L1 + 0.1){
|
||||
texel = mix(texture2D(BaseTex, gl_TexCoord[0].st), texture2D(ThirdTex, gl_TexCoord[0].st), smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
|
||||
}
|
||||
}
|
||||
}
|
||||
//Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
|
||||
} else if (InverseSlope > 0.0) {
|
||||
//Interemdiate transition ?
|
||||
if (Transitions >= 1.5) {
|
||||
if (slope >= L1 + 0.1) {
|
||||
texel = thirdTexel;
|
||||
}
|
||||
if (slope >= L2 && slope < L1 + 0.1){
|
||||
texel = mix(secondTexel, thirdTexel, smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
|
||||
}
|
||||
if (slope <= L2){
|
||||
texel = mix(baseTexel, secondTexel, smoothstep(L2 - 0.06 * MixFactor, L2, slope));
|
||||
}
|
||||
//just one
|
||||
} else if (Transitions < 1.5) {
|
||||
if (slope > L1 + 0.1) {
|
||||
texel = thirdTexel;
|
||||
}
|
||||
if (slope <= L1 + 0.1){
|
||||
texel = mix(baseTexel, thirdTexel, smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//darken textures with wetness
|
||||
wetness = 1.0 - 0.3 * RainNorm;
|
||||
texel.rgb = texel.rgb * wetness;
|
||||
//darken textures with wetness
|
||||
wetness = 1.0 - 0.3 * RainNorm;
|
||||
texel.rgb = texel.rgb * wetness;
|
||||
|
||||
|
||||
|
||||
//Snow texture for areas higher than SnowLevel
|
||||
if (RawPos.z >= SnowLevel - (1000.0 * slope + 300 * MixFactor) && slope > L2 - 0.12) {
|
||||
texel = mix(texel, mix(texel, texture2D(SnowTex, gl_TexCoord[0].st * 2), smoothstep(L2 - 0.09 * MixFactor, L2, slope)), smoothstep(SnowLevel - (1000.0 * slope + 300 * MixFactor), SnowLevel - (1000 * slope - 150 * MixFactor), RawPos.z));
|
||||
}
|
||||
//Snow texture for areas higher than SnowLevel
|
||||
if (RawPos.z >= SnowLevel - (1000.0 * slope + 300 * MixFactor) && slope > L2 - 0.12) {
|
||||
texel = mix(texel, mix(texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope)), smoothstep(SnowLevel - (1000.0 * slope + 300 * MixFactor), SnowLevel - (1000 * slope - 150 * MixFactor), RawPos.z));
|
||||
}
|
||||
|
||||
fragColor = color * texel + specular;
|
||||
fragColor = color * texel + specular;
|
||||
|
||||
if(cover >= 2.5){
|
||||
fragColor.rgb = fragColor.rgb * 1.2;
|
||||
} else {
|
||||
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
|
||||
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
||||
}
|
||||
if(cover >= 2.5){
|
||||
fragColor.rgb = fragColor.rgb * 1.2;
|
||||
} else {
|
||||
fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
|
||||
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
||||
}
|
||||
|
||||
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
||||
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// 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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
|
||||
// © Michael Horsch - 2005
|
||||
|
||||
#version 120
|
||||
uniform sampler2D water_normalmap;
|
||||
uniform sampler2D water_reflection;
|
||||
uniform sampler2D water_dudvmap;
|
||||
|
@ -37,7 +38,7 @@ void main(void)
|
|||
const float water_shininess = 240.0;
|
||||
|
||||
// approximate cloud cover
|
||||
float cover = 0;
|
||||
float cover = 0.0;
|
||||
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
|
||||
|
||||
vec4 viewt = normalize(waterTex4);
|
||||
|
|
Loading…
Add table
Reference in a new issue