Bonjour,

Cela fait déjà quelques jours que je bloque dessus et pas moyen de trouver une solution, j'ai cherché partout. Je suis désespéré.
J'ai lu l'article de Nvidia sur les PSSM et je n'arrive pas à faire la partie "Scene-Dependent Projection", a priori la "Scene-Independent Projection" se passe sans soucis mais c'est peut-être une coïncidence.

En gros mon ombre est "bien" sans la matrice Crop :
Nom : javaw 2014-10-13 13-41-44-07.png
Affichages : 300
Taille : 702,6 Ko

et avec c'est le bazar...
Nom : javaw 2014-10-13 13-42-18-39.png
Affichages : 293
Taille : 647,2 Ko

Je vous passe ma méthode calcCropMatrix (attention c'est du java ^^) :
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
69
70
71
72
public void calcCropMatrix(ArrayList<OBJMesh> shadowReceivers)
	{
 
		// Merge all bounding boxes of casters into a bigger "casterBB".
		BoundingBox casterBB = new BoundingBox();
		for(int i = 0; i < _shadowCasters.size(); i++) {
			BoundingBox bb = BoundingBox.mulByMatrix4f(_shadowCasters.get(i).getAABB(), _MVP);
		    casterBB.union(bb);
		}
 
		// Merge all bounding boxes of receivers into a bigger "receiverBB".
		BoundingBox receiverBB = new BoundingBox();
		for(int i = 0; i < shadowReceivers.size(); i++) {
			BoundingBox bb = BoundingBox.mulByMatrix4f(shadowReceivers.get(i).getAABB(), _MVP);
			receiverBB.union(bb);
		}
 
		// Find the bounding box of the current split  
		// in the light's clip space.  
 
		// transf = bounds dans light's clip space
 
		Vector4f transf = _MVP.mulVector4f(new Vector4f(_bounds[0], 1));
		Vector3f transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		BoundingBox splitBB = new BoundingBox(transf3, transf3); // init crop BB avec le premier bound
		for(Vector3f bound : _bounds) {
			transf = _MVP.mulVector4f(new Vector4f(bound, 1));
 
			transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
 
			if(transf3.x() > splitBB.max.x()) splitBB.max.x(transf3.x());
			if(transf3.x() < splitBB.min.x()) splitBB.min.x(transf3.x());
			if(transf3.y() > splitBB.max.y()) splitBB.max.y(transf3.y());
			if(transf3.y() < splitBB.min.y()) splitBB.min.y(transf3.y());
			if(transf3.z() > splitBB.max.z()) splitBB.max.z(transf3.z());
			if(transf3.z() < splitBB.min.z()) splitBB.min.z(transf3.z());
		}
 
 
		BoundingBox cropBB = new BoundingBox();
 
		cropBB.min.x( Math.max(Math.max(casterBB.min.x(), receiverBB.min.x()), splitBB.min.x()) );
		cropBB.max.x( Math.min(Math.min(casterBB.max.x(), receiverBB.max.x()), splitBB.max.x()) );
		cropBB.min.y( Math.max(Math.max(casterBB.min.y(), receiverBB.min.y()), splitBB.min.y()) );
		cropBB.max.y( Math.min(Math.min(casterBB.max.y(), receiverBB.max.y()), splitBB.max.y()) );
		cropBB.min.z( Math.min(casterBB.min.z(), splitBB.min.z()) );  
		cropBB.max.z( Math.min(receiverBB.max.z(), splitBB.max.z()) );
 
		//cropBB = splitBB;
		//cropBB.min.z(0);
		//System.out.println(cropBB);
 
		// Nous avons notre cropBB, calcul de la matrice crop
		float scaleX, scaleY, scaleZ;
		float offsetX, offsetY, offsetZ;
		scaleX = 2.0f / (cropBB.max.x() - cropBB.min.x());  
		scaleY = 2.0f / (cropBB.max.y() - cropBB.min.y());  
		offsetX = -0.5f * (cropBB.max.x() + cropBB.min.x()) * scaleX;  
		offsetY = -0.5f * (cropBB.max.y() + cropBB.min.y()) * scaleY;  
		scaleZ = 1.0f / (cropBB.max.z() - cropBB.min.z());  
		offsetZ = -cropBB.min.z() * scaleZ;  
		_crop.identity();
		_crop.set(0, 0, scaleX);
		_crop.set(1, 1, scaleY);
		_crop.set(2, 2, scaleZ);
		_crop.set(3, 0, offsetX);
		_crop.set(3, 1, offsetY);
		_crop.set(3, 2, offsetZ);
 
		_MVPC = _crop.clone().mul(_MVP);
		_MVPCB = _MVPC.toBias();
	}
Ma méthode statique BoundingBox.mulByMatrix4f qui peut aider :
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
 
public static BoundingBox mulByMatrix4f(BoundingBox aabb, Matrix4f m)
	{
 
		Vector4f transf = m.mulVector4f(new Vector4f(aabb.min, 1));
		Vector3f transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		BoundingBox bb = new BoundingBox(transf3, transf3); // init avec le premier vertex
 
		transf = m.mulVector4f(new Vector4f(aabb.max.x(), aabb.min.y(), aabb.min.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
		transf = m.mulVector4f(new Vector4f(aabb.min.x(), aabb.max.y(), aabb.min.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
		transf = m.mulVector4f(new Vector4f(aabb.max.x(), aabb.max.y(), aabb.min.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
 
		transf = m.mulVector4f(new Vector4f(aabb.min.x(), aabb.min.y(), aabb.max.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
		transf = m.mulVector4f(new Vector4f(aabb.max.x(), aabb.min.y(), aabb.max.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
		transf = m.mulVector4f(new Vector4f(aabb.min.x(), aabb.max.y(), aabb.max.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
		transf = m.mulVector4f(new Vector4f(aabb.max.x(), aabb.max.y(), aabb.max.z(), 1));
		transf3 = new Vector3f(transf.x() / transf.w(), transf.y() / transf.w(), transf.z() / transf.w());
		compareBB(transf3, bb);
 
 
		return bb;
	}
	private static void compareBB(Vector3f transf, BoundingBox bb)
	{
		if(transf.x() > bb.max.x()) bb.max.x(transf.x());
		if(transf.x() < bb.min.x()) bb.min.x(transf.x());
		if(transf.y() > bb.max.y()) bb.max.y(transf.y());
		if(transf.y() < bb.min.y()) bb.min.y(transf.y());
		if(transf.z() > bb.max.z()) bb.max.z(transf.z());
		if(transf.z() < bb.min.z()) bb.min.z(transf.z());
	}
Merci d'avance pour votre aide.