Bonjour !
Je travaille encore et toujours sur mon moteur 3D et j'éprouve actuellement quelques problèmes d'affichage, dont je n'arrive pas à trouver la source (cf. pièces jointes).
Sur les pièces jointes on voit donc qu'il arrive de drôles de choses à l'oeil de ce pauvre ducky (Capture1), artefacts qui disparaissent plus ou moins (oui je pense qu'ils ne disparaissent pas mais sont réduits) lorsqu'on s'approche dudit oeil (Capture2).
Pensant que ça pouvait venir des calculs sur flottants, je suis passé de float en double pour tous les calculs ainsi que les variables shaders (vertex buffers et matrices), mais sans changement.
Donc je viens vous demander si vous avez une idée de là où ça pourrait venir.
Je vous mets le code des shaders ayant servi au rendu de ce modèle :
Vertex shader :
Fragment shader :Code:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #version 140 precision highp float; in vec4 vertex; in vec3 normal; uniform vec4 c3d_AmbientLight; uniform vec4 c3d_MatAmbient; uniform vec4 c3d_MatDiffuse; uniform vec4 c3d_MatEmissive; uniform vec4 c3d_MatSpecular; uniform float c3d_MatShininess; uniform mat4 ProjectionModelViewMatrix; uniform mat4 ModelViewMatrix; uniform mat3 NormalMatrix; uniform vec4 c3d_LightsPosition[3]; uniform vec4 c3d_LightsDiffuse[3]; uniform vec4 c3d_LightsAmbient[3]; uniform vec4 c3d_LightsSpecular[3]; out vec3 vtx_normal; out vec3 vtx_vertex; out vec3 raw_normal; out vec3 vtx_positions[3]; out vec4 vtx_diffuses[3]; out vec4 vtx_speculars[3]; out vec4 vtx_ambient; out float vtx_shininess; void main() { vtx_normal = normalize( NormalMatrix * normal); raw_normal = normal; raw_normal.x = abs( raw_normal.x); raw_normal.y = abs( raw_normal.y); raw_normal.z = abs( raw_normal.z); vtx_vertex = normalize( (ModelViewMatrix * vertex).xyz); vtx_ambient = c3d_AmbientLight; int i; for (i = 0 ; i < 3 ; ++i) { vtx_positions[i] = normalize( (ModelViewMatrix * c3d_LightsPosition[i]).xyz); vtx_diffuses[i] = c3d_LightsDiffuse[i] * c3d_MatDiffuse; vtx_ambient += c3d_LightsAmbient[i]; vtx_speculars[i] = c3d_LightsSpecular[i] * c3d_MatSpecular; } vtx_ambient = (vtx_ambient * c3d_MatAmbient) + c3d_MatAmbient + c3d_MatEmissive; vtx_shininess = c3d_MatShininess; gl_Position = ProjectionModelViewMatrix * vertex; }
Code:
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 #version 140 precision highp float; in vec3 vtx_normal; in vec3 raw_normal; in vec3 vtx_vertex; in vec3 vtx_positions[3]; in vec4 vtx_diffuses[3]; in vec4 vtx_speculars[3]; in vec4 vtx_ambient; in float vtx_shininess; out vec4 out_FragColor; void main() { out_FragColor = vtx_ambient; int i; vec4 l_diffuse; vec4 l_specular; for (i = 0 ; i < 3 ; i++) { l_diffuse = vtx_diffuses[i] * max( dot( vtx_positions[i], vtx_normal), 0.0); l_specular = vtx_speculars[i] * pow( max( dot( normalize( vtx_positions[i] - vtx_vertex), vtx_normal), 0.0), vtx_shininess); out_FragColor += l_diffuse + l_specular; } out_FragColor /= float( i ); }