Bonjour à tous,
J'essaie d'implémenter le bump mapping en utilisant GLSL. Je pense y etre presque mais il se trouve que lorsque je lance mon programme, la colorisation ne se fait pas. J'ai peur que ca soit du au fait que je calcule la tangent d'une manière un peu trop simpliste. La lumiere est une lumiere blanche (1.0,1.0,1.0).
Voici le code de mon shader.
bump.vs:
bump.fs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 varying vec3 position; varying vec3 lightvec; void main() { vec3 tangent; vec3 binormal; vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); if(length(c1)>length(c2)) { tangent = c1; } else { tangent = c2; } tangent = normalize(tangent); binormal = cross(gl_Normal, tangent); binormal = normalize(binormal); //---------------------------------------------------------- gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; position = gl_Vertex.xyz; mat3 TBNMatrix = mat3(tangent, binormal, gl_Normal); lightvec = gl_LightSource[0].position.xyz - position; lightvec *= TBNMatrix; }
Voici un screen de ce que ca donne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 uniform sampler2D base; uniform sampler2D normalMap; uniform vec3 CAMERA_POSITION; varying vec3 position; varying vec3 lightvec; void main() { vec3 norm = texture2D(normalMap, gl_TexCoord[0].st).rgb * 2.0 - 1.0; vec3 baseColor = texture2D(base, gl_TexCoord[0].st).rgb; float dist = length(lightvec); vec3 lightVector = normalize(lightvec); float nxDir = max(0.0, dot(norm, lightVector)); vec4 diffuse = gl_LightSource[0].diffuse * nxDir; float specularPower = 0.0; if(nxDir != 0.0) { vec3 cameraVector = normalize(CAMERA_POSITION - position.xyz); vec3 halfVector = normalize(lightVector + cameraVector); float nxHalf = max(0.0,dot(norm, halfVector)); specularPower = pow(nxHalf, gl_FrontMaterial.shininess); } vec4 specular = gl_LightSource[0].specular * specularPower; gl_FragColor = gl_LightSource[0].ambient + (diffuse * vec4(baseColor.rgb,1.0)) + specular; }
![]()
Partager