Bonjour à tous,

voilà je me suis mis au shadow mapping (version sans shader vu que j'en ai jamais fait pour l'instant).

Les trois passes fonctionnent assez bien : la depth map OK, la shadow map OK et la scene final presque OK.

En fait pour la scene finale, mon ombre est complètement noire... Je n'ai pas de grisé. Je travaille avec les glActiveTextureARB, et mon problème doit surement venir de là. J'ai l'impression qu'il n'utilise pas la shadow map mais tout simplement un rendu noir.

J'ai une unité de texture pour la shadow texture (GL_TEXTURE2_ARB) et une unité de texture pour mes textures classiques de modélisation (GL_TEXTURE1_ARB). J'active seulement l'unité de mes textures classiques (GL_TEXTURE1_ARB) lorsque je fais un rendu de ma scene. Voici le code de la deuxième et troisième passes :


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
            GLfloat lowAmbient[4] = {0.0f, 0.0f, 0.0f, 1.0f};
            GLfloat lowDiffuse[4] = {0.0f, 0.0f, 0.0f, 1.0f};
 
            // Because there is no support for an "ambient"
            // shadow compare fail value, we'll have to
            // draw an ambient pass first...
            glLightfv(GL_LIGHT0, GL_AMBIENT, lowAmbient);
            glLightfv(GL_LIGHT0, GL_DIFFUSE, lowDiffuse);
 
            glEnable(GL_TEXTURE_2D);
            // Draw objects in the scene
            glActiveTextureARB(GL_TEXTURE1_ARB);
            drawScene(x,y);
 
 
            // Enable alpha test so that shadowed fragments are discarded
            glAlphaFunc(GL_GREATER, 0.99f);
            glEnable(GL_ALPHA_TEST);
et

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
 
    // Hidden surface removal
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
 
    // Set up texture matrix for shadow map projection,
    // which will be rolled into the eye linear
    // texture coordinate generation plane equations
    M3DMatrix44f tempMatrix;
    m3dLoadIdentity44(tempMatrix);
    m3dTranslateMatrix44(tempMatrix, 0.5f, 0.5f, 0.5f);
    m3dScaleMatrix44(tempMatrix, 0.5f, 0.5f, 0.5f);
    m3dMatrixMultiply44(textureMatrix, tempMatrix, lightProjection);
    m3dMatrixMultiply44(tempMatrix, textureMatrix, lightModelview);
    // transpose to get the s, t, r, and q rows for plane equations
    m3dTransposeMatrix44(textureMatrix, tempMatrix);
 
 
    //Set up texture coordinate generation.
    glActiveTextureARB(GL_TEXTURE2_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
 
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_S, GL_EYE_PLANE, &textureMatrix[0]);
	glEnable(GL_TEXTURE_GEN_S);
 
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_T, GL_EYE_PLANE, &textureMatrix[4]);
	glEnable(GL_TEXTURE_GEN_T);
 
	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_R, GL_EYE_PLANE, &textureMatrix[8]);
	glEnable(GL_TEXTURE_GEN_R);
 
	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_Q, GL_EYE_PLANE, &textureMatrix[12]);
	glEnable(GL_TEXTURE_GEN_Q);
 
	//Bind & enable shadow map texture
	glBindTexture(GL_TEXTURE_2D, shadowTextureID);
	glEnable(GL_TEXTURE_2D);
 
 
    /*glActiveTextureARB(GL_TEXTURE1_ARB);
 
	//Enable shadow comparison
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
 
	//Shadow comparison should be true (ie not in shadow) if r<=texture
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
 
	//Shadow comparison should generate an INTENSITY result
	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);*/
 
    glActiveTextureARB(GL_TEXTURE1_ARB);
	drawScene(x,y);
 
    //Disable textures and texgen
	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);
	glDisable(GL_TEXTURE_GEN_R);
	glDisable(GL_TEXTURE_GEN_Q);
    glDisable(GL_TEXTURE_2D);
	//Restore other states
	glDisable(GL_ALPHA_TEST);
Dans la troisième passe, on voit que j'ai mis en commentaire un autre code provenant d'un autre tuto mais qui donne le même résultat.

Il y a surement quelque chose que je n'ai pas compris avec les différentes unités de texture avec le shadow mapping. Si avez des conseils (voir même la solution), je vous en remercie d'avance.

Bonne soirée !