Jump to content
  • Advertisement
AlexWIN32

DX11 Problem with Point light shadows

This topic is 394 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

Hello!
 

A have an issue with my point light shadows realisation.

Capture.PNG.3af9f51e1bde08501f21893411aa8a47.PNG

 

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.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
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){

  D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
  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;
}

D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
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.SetPos(pl.GetPos());
	edgesCameras.SetTarget(pl.GetPos() + camDirs);
	edgesCameras.SetUp(camUps);
	edgesCameras.SetProjMatrix(projMat);
  } 

 

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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!