use world coordinates for noise texture lookup
Signed-off-by: Emilian Huminiuc <emilianh@gmail.com>
This commit is contained in:
parent
72c876aec6
commit
d098796d46
4 changed files with 40 additions and 25 deletions
|
@ -4,7 +4,8 @@
|
|||
// <20> Emilian Huminiuc 2011
|
||||
|
||||
|
||||
varying vec4 RawPos;
|
||||
varying float RawPosZ;
|
||||
varying vec3 WorldPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 Vnormal;
|
||||
|
||||
|
@ -32,7 +33,6 @@ void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shin
|
|||
|
||||
void main()
|
||||
{
|
||||
float MixFactor;
|
||||
float NdotL;
|
||||
float NdotHV;
|
||||
float fogFactor;
|
||||
|
@ -50,14 +50,17 @@ void main()
|
|||
vec4 texel;
|
||||
vec4 fragColor;
|
||||
vec4 color;
|
||||
vec4 Noise;
|
||||
|
||||
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, WorldPos.xyz*0.0011);
|
||||
vec4 Noise2 = texture3D(NoiseTex, WorldPos.xyz * 0.00008);
|
||||
float MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
|
||||
float MixFactor2 = Noise2.r * Noise2.g * Noise2.b;
|
||||
MixFactor *= 300.0;
|
||||
MixFactor2 *= 300.0;
|
||||
MixFactor = clamp(MixFactor, 0.0, 1.0);
|
||||
MixFactor2 = clamp(MixFactor2, 0.0, 1.0);
|
||||
L1 = 0.90 - 0.02 * MixFactor; //first transition slope
|
||||
L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
|
||||
|
||||
|
@ -128,7 +131,7 @@ void main()
|
|||
wetness = 1.0 - 0.3 * RainNorm;
|
||||
texel.rgb = texel.rgb * wetness;
|
||||
|
||||
float altitude = RawPos.z;
|
||||
float altitude = RawPosZ;
|
||||
//Snow texture for areas higher than SnowLevel
|
||||
if (altitude >= SnowLevel - (1000.0 * slope + 300.0 * MixFactor) && slope > L2 - 0.12) {
|
||||
texel = mix( texel,
|
||||
|
@ -149,7 +152,7 @@ void main()
|
|||
}
|
||||
|
||||
|
||||
fragColor.rgb *= 1.2 - 0.4 * MixFactor;
|
||||
fragColor.rgb *= 1.2 - 0.6 * MixFactor * MixFactor2;
|
||||
|
||||
float specular = dot( gl_FrontMaterial.specular.rgb, vec3( 0.3, 0.59, 0.11 ) );
|
||||
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
// Authors: Frederic Bouvier, Emilian Huminiuc
|
||||
//
|
||||
|
||||
varying vec4 RawPos;
|
||||
|
||||
varying float RawPosZ;
|
||||
varying vec3 WorldPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 Vnormal;
|
||||
|
||||
uniform mat4 osg_ViewMatrixInverse;
|
||||
|
||||
void main() {
|
||||
RawPos = gl_Vertex;
|
||||
RawPosZ = gl_Vertex.z;
|
||||
WorldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
normal = normalize(gl_Normal);
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
#version 120
|
||||
|
||||
varying vec4 RawPos;
|
||||
varying float RawPosZ;
|
||||
varying vec3 WorldPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 Vnormal;
|
||||
|
||||
|
@ -45,10 +46,14 @@ void main()
|
|||
|
||||
float cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
|
||||
|
||||
vec4 Noise = texture3D(NoiseTex, RawPos.xyz * 0.0011);
|
||||
vec4 Noise = texture3D(NoiseTex, WorldPos.xyz*0.0011);
|
||||
vec4 Noise2 = texture3D(NoiseTex, WorldPos.xyz * 0.00008);
|
||||
float MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
|
||||
float MixFactor2 = Noise2.r * Noise2.g * Noise2.b;
|
||||
MixFactor *= 300.0;
|
||||
MixFactor2 *= 300.0;
|
||||
MixFactor = clamp(MixFactor, 0.0, 1.0);
|
||||
MixFactor2 = clamp(MixFactor2, 0.0, 1.0);
|
||||
float L1 = 0.90 - 0.02 * MixFactor; //first transition slope
|
||||
float L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
|
||||
|
||||
|
@ -65,7 +70,7 @@ void main()
|
|||
pf = pow(nDotHV, gl_FrontMaterial.shininess);
|
||||
|
||||
if (gl_FrontMaterial.shininess > 0.0)
|
||||
specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf;
|
||||
specular = gl_FrontMaterial.specular * gl_LightSource[0].diffuse * pf;
|
||||
|
||||
// vec4 diffuseColor = gl_FrontMaterial.emission +
|
||||
// vec4(1.0) * (gl_LightModel.ambient + gl_LightSource[0].ambient) +
|
||||
|
@ -141,7 +146,7 @@ void main()
|
|||
float wetness = 1.0 - 0.3 * RainNorm;
|
||||
texel.rgb = texel.rgb * wetness;
|
||||
|
||||
float altitude = RawPos.z;
|
||||
float altitude = RawPosZ;
|
||||
//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)),
|
||||
|
@ -160,7 +165,7 @@ void main()
|
|||
fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
|
||||
}
|
||||
|
||||
fragColor.rgb *= 1.2 - 0.4 * MixFactor;
|
||||
fragColor.rgb *= 1.2 - 0.6 * MixFactor * MixFactor2;
|
||||
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
|
||||
gl_FragColor = fragColor;
|
||||
}
|
||||
|
|
|
@ -7,13 +7,17 @@
|
|||
|
||||
#version 120
|
||||
|
||||
varying vec4 RawPos;
|
||||
varying float RawPosZ;
|
||||
varying vec3 WorldPos;
|
||||
varying vec3 normal;
|
||||
varying vec3 Vnormal;
|
||||
|
||||
uniform mat4 osg_ViewMatrixInverse;
|
||||
|
||||
void main()
|
||||
{
|
||||
RawPos = gl_Vertex;
|
||||
RawPosZ = gl_Vertex.z;
|
||||
WorldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
normal = normalize(gl_Normal);
|
||||
|
|
Loading…
Reference in a new issue