Jump to content
  • Advertisement

DX11 Problem with Point light shadows

This topic is 783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


A have an issue with my point light shadows realisation.



First of all, the pixel shader path:


float3 toLight = plPosW.xyz - input.posW;

float3 fromLight = -toLight;


float depthL = abs(fromLight.x);

if(depthL < abs(fromLight.y))
  depthL = abs(fromLight.y);

if(depthL < abs(fromLight.z))
  depthL = abs(fromLight.z);

float4 pH = mul(float4(0.0f, 0.0f, depthL, 1.0f), lightProj);
pH /= pH.w;

isVisible = lightDepthTex.SampleCmpLevelZero(lightDepthSampler, normalize(fromLight), pH.z).x;

lightProj matrix creation

Matrix4x4 projMat = Matrix4x4::PerspectiveFovLH(0.5f * Pi, 0.01f, 1000.0f, 1.0f);


thats how i create Depth cube texture

viewport->TopLeftX = 0.0f;
viewport->TopLeftY = 0.0f;
viewport->Width    = static_cast<float>(1024);
viewport->Height   = static_cast<float>(1024);
viewport->MinDepth = 0.0f;
viewport->MaxDepth = 1.0f;

D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = 1024;
textureDesc.Height = 1024;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 6;
textureDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;

ID3D11Texture2D* texturePtr;
HR(DeviceKeeper::GetDevice()->CreateTexture2D(&textureDesc, NULL, &texturePtr));

for(int i = 0; i < 6; ++i){

  dsvDesc.Flags = 0;
  dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
  dsvDesc.Texture2DArray = D3D11_TEX2D_ARRAY_DSV{0, i, 1};

  ID3D11DepthStencilView *outDsv;
  HR(DeviceKeeper::GetDevice()->CreateDepthStencilView(texturePtr, &dsvDesc, &outDsv));

  edgeDsv = outDsv;

srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
srvDesc.TextureCube = D3D11_TEXCUBE_SRV{0, 1};

ID3D11ShaderResourceView *outSRV;
HR(DeviceKeeper::GetDevice()->CreateShaderResourceView(texturePtr, &srvDesc, &outSRV)); 


then i create six target oriented cameras and finally draw scene to cube depth according to each camera

Cameras creation code:  

std::vector<Vector3> camDirs = {
  { 1.0f,  0.0f,  0.0f},
  {-1.0f,  0.0f,  0.0f},
  { 0.0f,  1.0f,  0.0f},
  { 0.0f, -1.0f,  0.0f},
  { 0.0f,  0.0f,  1.0f},
  { 0.0f,  0.0f, -1.0f},

  std::vector<Vector3> camUps = {
  {0.0f, 1.0f, 0.0f},  // +X
  {0.0f, 1.0f, 0.0f},  // -X
  {0.0f, 0.0f, -1.0f}, // +Y
  {0.0f, 0.0f, 1.0f},  // -Y
  {0.0f, 1.0f, 0.0f},  // +Z
  {0.0f, 1.0f, 0.0f}   // -Z

  for(size_t b = 0; b < camDirs.size(); b++){
	edgesCameras.SetTarget(pl.GetPos() + camDirs);


I will be very gratefull for any help!

P.s sorry for my poor English)


Edited by AlexWIN32

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!