Bonjour,
Je cherche à implémenter les shadow maps dans mon progamme.
A chaque trame, je fais un premier rendu du point de vue de la lampe, et je sauvegarde la texture de profondeur et la matrice de la lampe:
Dans un second temps, j'effectue un rendu classique avec finalMat passé en uniform.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 const glm::mat4 bias( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0); const glm::mat4& lightProj = m_cameras[m_currentCamera].getProjectionMatrix(); const glm::mat4& lightView = m_cameras[m_currentCamera].getViewMatrix(); const glm::mat4& lightModel = m_lights[0]->getTransform().getMatrix(); const glm::mat4& finalMat = bias * lightProj * lightView * lightModel;
Dans le vertex shader (la matrice précédente s'appelle "bias"):
et dans le pixelShader:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 void main() { //Compute position mat4 mvpMatrix = viewProjMat * modelMat; gl_Position = mvpMatrix * vec4(vData.position, 1.0); fFragmentData.pixPos = (modelMat * vec4(vData.position, 1.0)).xyz; fFragmentData.shadowCoord = bias * modelMat * vec4(vData.position, 1.0); fFragmentData.pixNorm = normalize(modelMat * vec4(vData.normal, 1.0)).xyz; fFragmentData.texCoord = vData.uv; }
En faisant ainsi (en affichant que la valeur de la map), l'image est complètement noire.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 uniform sampler2DShadow shadowMap; void main(void) { vec4 texColor = texture(fMaterial.diffuseTexture, fFragmentData.texCoord); vec3 shadeColor = shade(fFragmentData.pixPos, fFragmentData.pixNorm, eyePos, (fMaterial.diffuseColor/PI), ((fMaterial.shininess+8)/(8*PI))*fMaterial.specularColor, fMaterial.shininess, fLightsData.nbLights, fLightsData.lightsPositions, fLightsData.lightsColors); float shadowValue = textureProj(map,vec4(fFragmentData.pixPos, 1.0)); //fragColor = vec4(shadeColor, 1.0) * texColor * shadowValue; fragColor = vec4(shadowValue, shadowValue, shadowValue, 1.0); //fragColor = fFragmentData.shadowCoord; }
Après vérification dans gdebugger, la depth map de la passe précédente existe, et la texture est bien valide.
Je pense que mon erreur vient de ma matrice de transformation de la lampe ou de l'utilisation que j'en fait.
Merci d'avance pour vos idées.
Seeme;
Partager