sebban

Untitled

Apr 3rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. bool ShadowShaderClass::initializeDepthStencil(ID3D11Device* gDevice)
  2. {
  3. HRESULT resultHandler;
  4. bool result = false;
  5.  
  6. D3D11_TEXTURE2D_DESC textureDepthDesc;
  7. textureDepthDesc.Width = 640.0f;
  8. textureDepthDesc.Height = 480.0f;
  9. textureDepthDesc.MipLevels = 1;
  10. textureDepthDesc.ArraySize = 1;
  11. textureDepthDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  12.  
  13. textureDepthDesc.SampleDesc.Count = 4; //must match the swap chain
  14. textureDepthDesc.SampleDesc.Quality = 0;
  15.  
  16. textureDepthDesc.Usage = D3D11_USAGE_DEFAULT;
  17. textureDepthDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  18. textureDepthDesc.CPUAccessFlags = 0;
  19. textureDepthDesc.MiscFlags = 0;
  20.  
  21. //create the texture for depthmap?
  22. resultHandler = gDevice->CreateTexture2D
  23. (
  24. &textureDepthDesc,
  25. NULL,
  26. &(this->shadowmapDepthtexture)
  27. );
  28.  
  29. //create another texture for the render target view
  30. D3D11_TEXTURE2D_DESC textureDescRTV;
  31.  
  32. ZeroMemory(&textureDescRTV, sizeof(textureDescRTV));
  33.  
  34. //setup the render target texture description
  35. textureDescRTV.Width = 640.0f;
  36. textureDescRTV.Height = 480.0f;
  37. textureDescRTV.MipLevels = 1;
  38. textureDescRTV.ArraySize = 1;
  39. textureDescRTV.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
  40.  
  41. textureDescRTV.SampleDesc.Count = 4; //must match swapchain
  42. textureDescRTV.SampleDesc.Quality = 0;
  43.  
  44. textureDescRTV.Usage = D3D11_USAGE_DEFAULT;
  45. textureDescRTV.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
  46. textureDescRTV.CPUAccessFlags = 0;
  47. textureDescRTV.MiscFlags = 0;
  48.  
  49. resultHandler = gDevice->CreateTexture2D(&textureDescRTV, NULL, &this->shadowmapRenderTargetViewTexture);
  50.  
  51. //create render target view
  52. D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourseViewDesc;
  53.  
  54. ZeroMemory(&shaderResourseViewDesc, sizeof(shaderResourseViewDesc));
  55.  
  56. //setup the description of the render target view
  57. //didn't work, but with null it does, no questions asked
  58.  
  59. //Create the render target view using the depthbuffer?
  60.  
  61. //resultHandler = gDevice->CreateRenderTargetView(this->shadowmapRenderTargetViewTexture, &renderTargetViewDesc, &this->shadowMapRTV);
  62. //http://www.rastertek.com/dx11tut22.html <--- here
  63. resultHandler = gDevice->CreateRenderTargetView(this->shadowmapRenderTargetViewTexture, NULL, &this->shadowMapRTV);
  64.  
  65. //set upp description to the shader resource view
  66. shaderResourseViewDesc.Format = DXGI_FORMAT_D32_FLOAT; //textureDescRTV.Format;
  67. shaderResourseViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
  68. shaderResourseViewDesc.Texture2D.MostDetailedMip = 0;
  69. shaderResourseViewDesc.Texture2D.MipLevels = 0;
  70.  
  71. //create the shader resourse view
  72. resultHandler = gDevice->CreateShaderResourceView(this->shadowmapRenderTargetViewTexture, NULL, &this->shaderResourceView);
  73.  
  74. //create depthStencilView
  75. resultHandler = gDevice->CreateDepthStencilView(
  76. this->shadowmapDepthtexture, //resorse we want to create a view to
  77. 0,
  78. &(this->shadowDepthStencilView) //the depthStencilView
  79. );
Advertisement
Add Comment
Please, Sign In to add comment