1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
FarAwayShader.name (OCEAN::FAR_AWAY)
FarAwayShader.vertex
{
uniform mat4 ProjectionMatrix ;
uniform vec4 CameraPos ;
void main ()
{
gl_Position = ProjectionMatrix * gl_Vertex ;
gl_TexCoord[0] = CameraPos - gl_Vertex ;
gl_TexCoord[1].xy = gl_Vertex.xy * 0.025 ;
}
}
FarAwayShader.fragment
{
uniform sampler2D ReflectionRender ;
uniform sampler2D NormalMap1 ;
uniform vec2 ResolutionCoefs ;
uniform vec3 SunPos ;
uniform vec3 SunSpecular ;
uniform vec2 TextureDelta ;
uniform vec3 WaterColor ;
void main ()
{
const float WaveMaxDistance = 120.0f ;
vec3 Direction = normalize (gl_TexCoord[0].xyz);
vec3 Normal1 = texture2D (NormalMap1, gl_TexCoord[1].xy + TextureDelta.xy).rgb * 2.0 - 1.0 ;
vec3 Normal2 = texture2D (NormalMap1, gl_TexCoord[1].xy + 0.5 * TextureDelta.xy).rgb * 2.0 - 1.0 ;
vec3 Normal = normalize (Normal1 + Normal2) ;
vec3 ReflectColor = texture2D (ReflectionRender, gl_FragCoord.xy * ResolutionCoefs).rgb;
float FromCamera = length (gl_TexCoord[0].xyz) ;
float ReflectCoef = max (dot (Normal, Direction), 0.0) * max (1.0 - FromCamera /WaveMaxDistance, 0.0) ;
float SpecularCoef = min (exp ((WaveMaxDistance - FromCamera) * 0.02), 1.0);
vec3 Specular = SunSpecular * clamp (dot (reflect (-SunPos, Normal), Direction) * 24.0 - 23.0, 0.0, 1.0);
gl_FragColor.rgb = mix (ReflectColor, WaterColor, ReflectCoef) + Specular * SpecularCoef ;
gl_FragColor.a = 1.0f ;
}
} |
Partager