source: java/client_3D/static/shared/res/shaders/old_normal_mapping.glsl @ 65

Last change on this file since 65 was 65, checked in by Maciej Komosinski, 13 years ago

added sources of the 3D client for the Framsticks server

File size: 1.6 KB
Line 
1//vert
2       
3varying vec3 lightVec;
4varying vec3 eyeVec;
5varying vec2 texCoord;
6attribute vec3 tangent;
7                                         
8
9void main(void)
10{
11        gl_Position = ftransform();
12        texCoord = gl_MultiTexCoord0.xy * 0.4;
13       
14        vec3 n = normalize(gl_NormalMatrix * gl_Normal);
15        vec3 t = normalize(gl_NormalMatrix * tangent);
16        vec3 b = cross(n, t);
17       
18        vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
19        vec3 tmpVec = gl_LightSource[0].position.xyz - vVertex;
20
21        lightVec.x = dot(tmpVec, t);
22        lightVec.y = dot(tmpVec, b);
23        lightVec.z = dot(tmpVec, n);
24
25        tmpVec = -vVertex;
26        eyeVec.x = dot(tmpVec, t);
27        eyeVec.y = dot(tmpVec, b);
28        eyeVec.z = dot(tmpVec, n);
29}
30       
31//frag
32
33varying vec3 lightVec;
34varying vec3 eyeVec;
35varying vec2 texCoord;
36uniform sampler2D diffuseMap;
37uniform sampler2D normalMap;
38//uniform float invRadius;
39
40void main (void)
41{
42        float invRadius = 0.2;
43       
44        float distSqr = dot(lightVec, lightVec);
45        float att = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0);
46        vec3 lVec = lightVec * inversesqrt(distSqr);
47
48        vec3 vVec = normalize(eyeVec);
49       
50        vec4 base = texture2D(diffuseMap, texCoord);
51       
52        vec3 bump = normalize( texture2D(normalMap, texCoord).xyz * 2.0 - 1.0);
53
54        vec4 vAmbient = vec4(0.8, 0.5, 0.2, 0.0);//gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
55
56        float diffuse = max( dot(lVec, bump), 0.0 );
57       
58        vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * diffuse;
59
60        float specular = pow(clamp(dot(reflect(-lVec, bump), vVec), 0.0, 1.0), gl_FrontMaterial.shininess );
61       
62        vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular * specular;     
63       
64        gl_FragColor = ( vAmbient*base +
65                                         vDiffuse*base +
66                                         vSpecular) * att;
67}
Note: See TracBrowser for help on using the repository browser.