source: trunk/tests/md2_test/obj.frag @ 239

Last change on this file since 239 was 239, checked in by epyon, 11 years ago
  • massive update of mesh handling
  • universal mesh handling routines
  • removed a lot of legacy code
  • significantly streamlined MD5 loading
  • all tests updated to new features
File size: 1.3 KB
RevLine 
[189]1#version 120
2
[239]3uniform sampler2D nv_t_diffuse;
[189]4uniform vec4 light_diffuse;
5uniform vec4 light_specular;
6
7varying vec2 v_texcoord;
8varying vec3 v_normal;
9varying vec3 v_light_vector;
10varying vec3 v_view_vector;
[239]11
[189]12void main(void) {
[239]13        vec3 diff_texel      = vec3( texture2D( nv_t_diffuse, v_texcoord ) );   
14
[189]15        vec3 nnormal         = normalize( v_normal );
16        vec3 nlight_vector   = normalize( v_light_vector );
17        vec3 nreflect_vector = reflect( -nlight_vector, nnormal );
18
[239]19        float specular_amount = 0.2;
20        float diffuse_amount  = 1.0 - specular_amount;
[189]21
[239]22        float dot_prod_specular = dot( nreflect_vector, normalize( v_view_vector ) );
23        float dot_prod_diffuse  = dot( nlight_vector, nnormal );
[189]24
[239]25        float diffuse_factor  = max( dot_prod_diffuse, 0.0 );
26        float specular_factor = pow( max( dot_prod_specular, 0.0 ), 16.0 ); // 100.0
27
28        float final_diffuse  = diffuse_amount * diffuse_factor * 0.5;
29        float final_specular = specular_amount * specular_factor;
30
31        vec3 diffuse_color   = light_diffuse.xyz  * final_diffuse * diff_texel;
[189]32        vec3 specular_color  = light_specular.xyz * final_specular;
[239]33        vec3 self_ilum_color = vec3 (0.0, 0.0, 0.0);
34        vec3 ambient_color   = vec3 (0.0, 0.0, 0.0);
[189]35
[239]36        gl_FragColor = vec4( max( self_ilum_color, diffuse_color + specular_color + ambient_color ), 1.0 );
37}
Note: See TracBrowser for help on using the repository browser.