source: trunk/tests/md5_test/md5.frag @ 352

Last change on this file since 352 was 321, checked in by epyon, 11 years ago
  • updated all tests to new nova
  • cleaned up tests paths
  • general cleanup of tests and test data
File size: 1.8 KB
Line 
1#version 120
2
3uniform sampler2D nv_t_diffuse;
4uniform sampler2D nv_t_specular;
5uniform sampler2D nv_t_normal;
6uniform vec4 light_diffuse;
7uniform vec4 light_specular;
8uniform mat4 nv_m_view_inv;
9
10varying vec2 v_texcoord;
11varying vec3 v_normal;
12varying vec3 v_light_vector;
13varying vec3 v_view_vector;
14varying vec4 v_position;
15varying mat3 v_m33_tangent;
16 
17void main(void) {
18        vec2 texcoord         = v_texcoord;
19        //
20        vec4 encoded_normal   = texture2D( nv_t_normal, texcoord );
21        encoded_normal.y      = 1 - encoded_normal.y;
22        vec3 local_coords     = 2.0 * encoded_normal.rgb - vec3(1.0);
23        vec3 normal_direction = normalize(v_m33_tangent * local_coords);
24        vec3 view_direction   = normalize(vec3(nv_m_view_inv * vec4(0.0, 0.0, 0.0, 1.0) - v_position));
25        vec3 nnormal         = normal_direction;
26        //
27
28//      vec3 nnormal         = normalize( v_normal );
29        vec3 nlight_vector   = normalize( v_light_vector );
30        vec3 nview_vector    = normalize( v_view_vector );
31        vec3 nreflect_vector = reflect( -nlight_vector, nnormal );
32
33        float specular_value = clamp( dot( nreflect_vector, nview_vector ), 0.0, 1.0 );
34        specular_value       = pow( specular_value, 6.0 );
35        float diffuse_value  = max( dot( nlight_vector, nnormal ), 0.0 );
36
37        vec3 diff_texel      = vec3( texture2D( nv_t_diffuse, texcoord ) );     
38        vec4 spec_texel      = texture2D( nv_t_specular, texcoord );
39       
40        float specular_amount = spec_texel.x;
41        float diffuse_amount  = 1.0 - specular_amount;
42
43        float final_specular = specular_amount * specular_value;
44        float final_diffuse  = diffuse_amount  * diffuse_value;
45
46        vec3 diffuse_color   = light_diffuse.xyz  * final_diffuse * diff_texel;
47        vec3 specular_color  = light_specular.xyz * final_specular;
48
49        gl_FragColor = vec4( diffuse_color + specular_color, 1.0 );
50}
Note: See TracBrowser for help on using the repository browser.