Skip to main content
In my original answer I was considering that theposition of light was necessary. But As we use a float3x3 this information is not needed. So only the inverse(View) of the scene is necessary.
Source Link
philB
  • 333
  • 2
  • 11

Finally the idea of transforming the direction was ok. I had search for an equivalent of converting normals to view space to reorient my cubemap projection direction.

so: Define for each pointlight n its world matrix using its position

 LPWorld[n] = Identity();
 LPWorld.r[3]  = XMVectorSet(LPos[n].x, LPos[n].y, LPos[n].z, 1);

Get the inverse of LPWorld * View, view being the scene view matrix.

 I_LPWorldView[n]I_View[n] = Inverse(LPWorld[n] * View);

pass it to the constant buffer,

TI_LPWorldView[n]TI_View[n] = Transpose(I_LPWorldView[n]I_View[n]);//transpose for directx

in the shader get the direction of point to light in view space, PosV being the position in viewspace of the pixel and LPosV the position of light in view space, convert back to world space, and sample

txDirV = PosV - LPosV[n];
txDirV = mul (txDirV, (float3x3)TI_LPWorldView[n]TI_View[n]);//not necessary to normalize, we just want the direction
float D = txShadowCubeMap[n].SampleLevel(samLinear, txDirV, 0).r;

not a big boost but a couple of instruction removed compared to calculcalculating the shadow in world space when your deferred pipeline is all in view space.

Finally the idea of transforming the direction was ok. I had search for an equivalent of converting normals to view space to reorient my cubemap projection direction.

so: Define for each pointlight n its world matrix using its position

 LPWorld[n] = Identity();
 LPWorld.r[3]  = XMVectorSet(LPos[n].x, LPos[n].y, LPos[n].z, 1);

Get the inverse of LPWorld * View, view being the scene view matrix.

 I_LPWorldView[n] = Inverse(LPWorld[n] * View);

pass it to the constant buffer,

TI_LPWorldView[n] = Transpose(I_LPWorldView[n]);//transpose for directx

in the shader get the direction of point to light in view space, PosV being the position in viewspace of the pixel and LPosV the position of light in view space, convert back to world space, and sample

txDirV = PosV - LPosV[n];
txDirV = mul (txDirV, (float3x3)TI_LPWorldView[n]);//not necessary to normalize, we just want the direction
float D = txShadowCubeMap[n].SampleLevel(samLinear, txDirV, 0).r;

not a big boost but a couple of instruction removed compared to calcul in world space.

Finally the idea of transforming the direction was ok. I had search for an equivalent of converting normals to view space to reorient my cubemap projection direction.

so:

Get the inverse of View, view being the scene view matrix.

 I_View[n] = Inverse(View);

pass it to the constant buffer,

TI_View[n] = Transpose(I_View[n]);//transpose for directx

in the shader get the direction of point to light in view space, PosV being the position in viewspace of the pixel and LPosV the position of light in view space, convert back to world space, and sample

txDirV = PosV - LPosV[n];
txDirV = mul (txDirV, (float3x3)TI_View[n]);//not necessary to normalize, we just want the direction
float D = txShadowCubeMap[n].SampleLevel(samLinear, txDirV, 0).r;

not a big boost but a couple of instruction removed compared to calculating the shadow in world space when your deferred pipeline is all in view space.

Source Link
philB
  • 333
  • 2
  • 11

Finally the idea of transforming the direction was ok. I had search for an equivalent of converting normals to view space to reorient my cubemap projection direction.

so: Define for each pointlight n its world matrix using its position

 LPWorld[n] = Identity();
 LPWorld.r[3]  = XMVectorSet(LPos[n].x, LPos[n].y, LPos[n].z, 1);

Get the inverse of LPWorld * View, view being the scene view matrix.

 I_LPWorldView[n] = Inverse(LPWorld[n] * View);

pass it to the constant buffer,

TI_LPWorldView[n] = Transpose(I_LPWorldView[n]);//transpose for directx

in the shader get the direction of point to light in view space, PosV being the position in viewspace of the pixel and LPosV the position of light in view space, convert back to world space, and sample

txDirV = PosV - LPosV[n];
txDirV = mul (txDirV, (float3x3)TI_LPWorldView[n]);//not necessary to normalize, we just want the direction
float D = txShadowCubeMap[n].SampleLevel(samLinear, txDirV, 0).r;

not a big boost but a couple of instruction removed compared to calcul in world space.