Skip to main content
added 1693 characters in body
Source Link
philB
  • 159
  • 9

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine for lights and directional shadows.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating, the shadowed part being not fully opaque (see picture). txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

Another option is a correct setting of the matrices used to render the cubemap but I don't see how to proceed. I've tried to pass view space data (Position, (View or inverseview)*gLightViewProjCube) to the geometry shader used for rendering cubemaps but the shadows are still not correct. enter image description here

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

Another option is a correct setting of the matrices used to render the cubemap but I don't see how to proceed. I've tried to pass view space data (Position, (View or inverseview)*gLightViewProjCube) to the geometry shader used for rendering cubemaps but the shadows are still not correct.

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine for lights and directional shadows.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating, the shadowed part being not fully opaque (see picture). txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

Another option is a correct setting of the matrices used to render the cubemap but I don't see how to proceed. I've tried to pass view space data (Position, (View or inverseview)*gLightViewProjCube) to the geometry shader used for rendering cubemaps but the shadows are still not correct. enter image description here

added 1693 characters in body
Source Link
philB
  • 159
  • 9

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

Another option is a correct setting of the matrices used to render the cubemap but I don't see how to proceed. I've tried to pass view space data (Position, (View or inverseview)*gLightViewProjCube) to the geometry shader used for rendering cubemaps but the shadows are still not correct.

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

Another option is a correct setting of the matrices used to render the cubemap but I don't see how to proceed. I've tried to pass view space data (Position, (View or inverseview)*gLightViewProjCube) to the geometry shader used for rendering cubemaps but the shadows are still not correct.

added 1693 characters in body
Source Link
philB
  • 159
  • 9

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I want to render shadows for point lights with a cubemap. My shader uses view space for lighting (directional and point). So I convert ligthposW/lightfocusW in world space to ligthposV/lightfocusV in view space by doing ligthposW x View and lightfocusW x view. ligthposV-lightfocusV gives me the direction of light and direction of pointlight to pixel in view space that I use for doting to normals in view space. Works fine.

I have difficulties to use the same idea for shadowcube mapping in view space. The idea is to use the same light to pixel direction calculated in viewspace to save some instructions.

Currently I'm falling back to world space for point lights shadows. Consequently the shadowcube is filled with depth of object in world space (World x LightViewProj)

so the goal is to do ShadowCubeMap.Sample(point, direction in view space).r.

I've tried to adapt the method I use for directional shadows in viewspace (Shadowmapping in view space) doing the following:

given:

 LPosR[n] the position of pointlight[n] in the world
 vLookDir[Face], vUpDir[Face] the usual vectors used to orient the projection in cubemaps
 gLightProjectionCube = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1, 0.5, 1000); the projection matrix for cubemap shadows

CPU settings

for (DWORD l = 0; l < cMaxLight; l++)
for (DWORD f = 0; f < 6; f++)
{
    XMVECTOR vEyePt = XMVectorSet(LPosR[l].x, LPosR[l].y, LPosR[l].z, 1);
    gLightViewProjCube[l][f] = XMMatrixLookAtLH(vEyePt, vEyePt + vLookDir[f], vUpDir[f])*gLightProjectionCube;
}

Use these matrices to render the cubemaps in world space

I’m also having some light data in view space:

LPosV[n] = LPosW[n]*View
InvViewLightViewProj[n][face]= Inverse(View of scene)* gLightViewProjCube[n][face]

At deferred pass

Get Posisition in view space PosV
Get direction of pos to light in view space txDirV = PosV – LPosV[n]
Use txDirV to sample the cubemap[n] to get Depth
Get Projected data dPS for shadow
float4 dPS = mul(PosV, InvViewLightViewProjCube[n][Face]);
Shadow*=( Depth *dPS.w < dPS.z )? 0.5:1;

What I see is a rotating shadow as my scene is rotating. txDirV is clearly not compatible with orientation in worldspace of my cubemaps. I can imagine multiplying txDirV by InverseView but I’m not sure it will work and it adds more instructions. Alternatively is it an option to change in view space the vLookDir[f], vUpDir[f] used for creating the cubemap matrices ?

added 1 character in body
Source Link
philB
  • 159
  • 9
Loading
Source Link
philB
  • 159
  • 9
Loading