Salut !
J'ai un probème mon shader marche sous renderMonkey mais quand je l'intègre à mon programme opengl le model n'a aucun éclairage...
j'ai fait un fichier dans lequel je redirige l'info log et il me dis :
" Link successful. The GLSL vertex shader will run in hardware. The GLSL fragment shader will run in hardware."
mon programme marche avec un autre shader mais pas avec le mien qui fait de l'éclairage au pixel près :-/
J'ai même pris une méthode dont je suis sur qu'elle marche pour charger les shaders mais ça fait la même chose qu'avec me méthode à moi.
Pouvez vous m'aider car personne n'a réussi sur les autres forum,
voici le code du vertex puis du fragment shader :
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 varying vec3 normal ; varying vec4 ambientLight ; varying vec4 diffuseLight ; varying vec4 specularLight ; varying float dist ; varying vec4 lightVector ; void main(void) { normal = gl_NormalMatrix * gl_Normal;//to trasform in eye coordinates //ambient component ambientLight = gl_FrontMaterial.ambient * gl_LightSource[0].ambient ; //diffuse component diffuseLight = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse ; //specular component specularLight=gl_FrontMaterial.specular * gl_LightSource[0].specular *pow(max(dot(gl_LightSource[0].halfVector.xyz, normal), 0.0), gl_FrontMaterial.shininess); vec4 coordinate = gl_ModelViewMatrix * gl_Vertex; lightVector = vec4(gl_LightSource[0].position - coordinate) ; dist = distance(gl_LightSource[0].position, coordinate) ; gl_Position = ftransform();//gl_ModelViewProjectionMatrix * gl_Vertex ; }
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 varying vec3 normal ; varying vec4 ambientLight ; varying vec4 diffuseLight ; varying vec4 specularLight ; varying float dist ; varying vec4 lightVector ; void main(void) { vec3 normalizedNormal = normalize(normal) ; //diffuse component float intensity = max(dot (normalizedNormal, normalize(lightVector.xyz)), 0.0); vec4 diffuseLightDotI = diffuseLight * intensity ; //attenuation float attenuation = 1.0/ (gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * dist + gl_LightSource[0].quadraticAttenuation * pow(dist, 2.0)) ; //color computation gl_FragColor = gl_FrontMaterial.emission + (ambientLight + diffuseLightDotI + specularLight) *attenuation ; }
Partager