Untitled

 avatar
unknown
plain_text
5 months ago
1.4 kB
5
Indexable
water_shader.frag

#version 330

uniform sampler2D texture_map;
uniform sampler2D normal_map;

uniform vec3 light_pos;
uniform vec3 view_pos;

in vec3 frag_pos;
in vec3 normal;
in vec2 texcoord;

out vec4 frag_color;

void main() {
    vec3 base_color = texture(texture_map, texcoord).rgb;

    vec3 normal_map_color = texture(normal_map, texcoord).rgb;
    vec3 perturbed_normal = normalize(normal_map_color * 2.0 - 1.0);

    vec3 light_dir = normalize(light_pos - frag_pos);

    float diff = max(dot(perturbed_normal, light_dir), 0.0);

    vec3 view_dir = normalize(view_pos - frag_pos);
    vec3 reflect_dir = reflect(-light_dir, perturbed_normal);
    float spec = pow(max(dot(view_dir, reflect_dir), 0.0), 32.0);

    vec3 lighting = diff * base_color + spec * vec3(1.0);

    frag_color = vec4(lighting, 1.0);
}


water_shader.ver

#version 330

uniform mat4 p3d_ModelViewProjectionMatrix;
uniform mat4 p3d_ModelMatrix;
uniform float time_elapsed; // Tempo decorrido para deslocar a textura

in vec4 p3d_Vertex;
in vec3 p3d_Normal;
in vec2 p3d_MultiTexCoord0;

out vec3 frag_pos;
out vec3 normal;
out vec2 texcoord;

void main() {
    frag_pos = vec3(p3d_ModelMatrix * p3d_Vertex);
    normal = mat3(p3d_ModelMatrix) * p3d_Normal;

    vec2 wave_offset = vec2(0.1 * time_elapsed, 0.05 * time_elapsed); 
    texcoord = p3d_MultiTexCoord0 + wave_offset;

    gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
}
Editor is loading...
Leave a Comment