| Next entry » Browse > Images

Skip to comments (2) Pixelshader water
Posted by Erik on Oct 15 2005 @ 16:26  :: 4220 unique visits

Developer images



The terrain shader:
CODE: C
varying float ln;
varying float slope;
varying float hight;

uniform sampler2D texture0;
uniform sampler2D texture1;

uniform vec3 lightPosition;

[vertex]

void main(void) {
    hight  = gl_Vertex.y;

    vec3 up     = normalize(gl_NormalMatrix * vec3(0, 1, 0));
    vec3 vector = vec3(gl_ModelViewMatrix * gl_Vertex);
    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);

    // vector pointing to the light position
    vec3  l = normalize(lightPosition - vector);

    // take the dot product between the vector to the light and the normal
    ln = max(dot(normal, l), 0.5);

    // calculate the slope of the terrain
    slope = min(max(dot(normal, up), 0.0) * 2.0, 1.0);

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position    = ftransform();
}

[fragment]

void main(void) {
    // 2d texture coordinates
    vec2 texcoord = vec2(gl_TexCoord[0]);

    vec3  color;
    float alpha = 1.0;
    float slp = slope;

    vec3 dirt = vec3(texture2D(texture1, texcoord));
    vec3 gras = vec3(texture2D(texture0, texcoord));

    if (hight < 1.0) { // just above the water level
        // let the texture flow from gras to dirt
        slp = min(hight, slope);
       
        if (hight < 0.5)
            alpha = hight * 2.0;
    }

    // calculate the final color
    color = (gras * slp) + (dirt * (1.0 - slp));

    // write the final color + alpha component
    gl_FragColor = vec4(color * ln, alpha);
}

2 comments posted so far
Add your own »

1. On Oct 17 2005 @ 19:46 Chrizz wrote:

Yeah, like you said Erik, it looks much nicer in movement! :-)

2. On Apr 15 2009 @ 09:43 Steve wrote:

Yeah it looks natural and nice as pixel showed water its nice i would try it after my 70-620 Configuring Windows Vista Client exam that i had prepared already from reliable IT services provider as i have previously pass my N10-003 CompTIA certification exam along with 70-270 latest MCSA Installing, Configuring and Administering Microsoft Windows XP Professional exams with high score as i will be free from all this i must return on your page to see what new things you are sharing.

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: