   [XNA] Quick cubemap question (how to create view matrix)
  Hi, I'm trying to render a shadowmap for a pointlight using a cube target.My problem is that when I render my shadowmap for PositiveX and/or PositiveZ I get the results mirrored. This makes sense since I use Matrix.CreateLookAt(lightpos, lightpos + Vector3.Backward, Vector3.Up).So, I know why it happens, but how do I fix it? I tried to just scale that matrix by (-1,1,1) but it doesn't work (why?).Any ideas?   
  Along which axis is it mirrored? What happens if you use -Vector3.Up for instance?   ;  In one case it's mirrored over the plane formed by the z and y axises and in the other case it's mirrored over the x-y plane.Here is a picture of what it looks like, standing at the pointlight position looking along towards positive z with a FOV of 90 degrees:Maybe this image explains what happens. It's the frustums for the positive and negative z faces seen from above. Red dot means it's -1 x and blue dot means it's +1 x. On both sides, the upper frustum is correct. In the left image it's mirrored correctly, but in the right image, it's instead rotated 180 degrees which is what I have.;  Maybe you have an incorrect up vector in one of your view matrices?Here are mine, which I use in SlimDX DX10 with a righthanded system (so does xna, right?)View[0] = Matrix.LookAtRH(Position, Position + Vector3.UnitX, Vector3.UnitY);View[1] = Matrix.LookAtRH(Position, Position - Vector3.UnitX, Vector3.UnitY);View[2] = Matrix.LookAtRH(Position, Position + Vector3.UnitY, Vector3.UnitZ);View[3] = Matrix.LookAtRH(Position, Position - Vector3.UnitY, -Vector3.UnitZ);View[4] = Matrix.LookAtRH(Position, Position - Vector3.UnitZ, Vector3.UnitY);View[5] = Matrix.LookAtRH(Position, Position + Vector3.UnitZ, Vector3.UnitY);You may need to invert the Z value of your cubemap lookup vector when sampling from this cubemap.   ;  Are you absolutely sure that gives you the correct cube? That's pretty much exactly how I setup my view matrices for the various planes. When I do that, my +X and +Z sides are mirrored over YZ and XY planes respectively.I need a workaround similar to this:float3 tmp_positive = normalize(float3(1,1,1));float3 tmp_positiveX = float3(1,0,0);float3 tmp_positiveY = float3(0,1,0);float3 tmp_positiveZ = float3(0,0,1);float dotx = dot(tmp_positiveX, samplePos); float doty = dot(tmp_positiveY, samplePos); float dotz = dot(tmp_positiveZ, samplePos); if(dot(tmp_positive, samplePos) > 0){if(dotz > dotx && dotz > doty)samplePos.x = -samplePos.x;else if(dotx > doty)samplePos.z = -samplePos.z;}float storedDepth = texCUBE(ShadowCubeMapSampler, samplePos).x;;  Yes, I copypasted this from my pointlight shadowmap code.I use a geometryshader to render the cube texture in a single pass, but that shouldn't make any difference?You shouldn't need such a workaround... the only thing that can happened is that you may need to invert Z during cubemap sampling:float3 lookup = float3(lightToSurface.x, lightToSurface.y, -lightToSurface.z);I think this is related to using a RH system, but I'm not sure, maybe I just messed something up elsewhere, but this is working the way I want it to, so I'm not touching it anymore :)   ;As I recall XNA uses a lefthanded coordinate system by default. Don't ask me why or how to fix it [smile] ;Quote:Original post by remigiusAs I recall XNA uses a lefthanded coordinate system by default. Don't ask me why or how to fix it [smile]Nah, it uses a right-handed coordinate system. Which is why cubemap lookups come out wrong.;Quote:Original post by MJPNah, it uses a right-handed coordinate system. Which is why cubemap lookups come out wrong.Ah right, my bad... I'm out of touch [smile] ;  Can anyone point me to a working shadowmap system for pointlights using XNA?I really can't figure this out.   