ABOOL Light::VInitialize(INPUT_LAYOUT * pLayout) { //Initialize default light shaders m_pShaders = new ShaderBunch(); m_pShaders->VSetVertexShader(m_vertexShaderFile, DEFAULT_VERTEX_SHADER_NAME, pLayout, 2, TOPOLOGY_TRIANGLELIST); m_pShaders->VSetPixelShader(m_pixelShaderFile, DEFAULT_PIXEL_SHADER_NAME); //Initialize textures for shadow mapping Texture2DParams tex2DParams; tex2DParams.Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, DXGI_FORMAT_R32_TYPELESS, true, false, false, true, 1, 0, 1, true, false, false); m_pShadowMapTex->Create(&tex2DParams); //create shader resource and render target view for the texture ShaderResourceViewParams srvParams; srvParams.InitForTexture2D(DXGI_FORMAT_R32_FLOAT, 0, 0); m_pShadowMapTex->CreateShaderResourceView(&m_pShadowMapSRV->m_pView, &srvParams); DepthStencilViewParams dsvParams; dsvParams.InitForTexture2D(DXGI_FORMAT_D32_FLOAT, 0); if (!m_pShadowMapTex->CreateDepthStencilView(&m_pShadowMapDSV->m_pView, &dsvParams)) return false; /*** Initialize texture for varianbce shadow mapping ***/ tex2DParams.Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, true, true, true, false, 1, 0, 8, true, false, false, true); m_pVarianceShadowTex->Create(&tex2DParams); m_pTempTexture->Create(&tex2DParams); //create shadow resource view srvParams.InitForTexture2D(DXGI_FORMAT_R32G32B32A32_FLOAT, 8, 0); m_pVarianceShadowTex->CreateShaderResourceView(&m_pVarianceShadowSRV->m_pView, &srvParams); m_pTempTexture->CreateShaderResourceView(&m_pTempSRV->m_pView, &srvParams); RenderTargetViewParams rtvParams; rtvParams.InitForTexture2D(DXGI_FORMAT_R32G32B32A32_FLOAT, 0); m_pVarianceShadowTex->CreateRenderTargetView(&m_pVarianceShadowRTV->m_pView, &rtvParams); UnorderedAccessViewParams uavParams; uavParams.InitForTexture2D(DXGI_FORMAT_R32G32B32A32_FLOAT, 0); m_pVarianceShadowTex->CreateUnorderedAccessView(&m_pVarianceShadowUAV->m_pView, &uavParams); m_pTempTexture->CreateUnorderedAccessView(&m_pTempUAV->m_pView, &uavParams); m_bInitialized = true; return true; }
ABOOL DeferredRenderer::VInitialize(HWND hWnd, AUINT32 width, AUINT32 height) { if (!Renderer::VInitialize(hWnd, width, height)) { assert(0 && "Some problem initializing Renderer occured"); } //initialize gbuffer m_gbuffer.VInitialize(); //initialize data for light pass BufferParams matBufferParams; matBufferParams.FillConstantBufferParams(sizeof(Mat4x4), true, false, false); m_pMatrixBuffer->Create(&matBufferParams, NULL); //initialize data for light rendering BufferParams params; params.FillVertexBufferParams(sizeof(float3), 6, true, false, false, false); //position data SubresourceData data; AREAL32 left = (AREAL32)(SCREEN_WIDTH / 2 * -1); AREAL32 right = left + SCREEN_WIDTH; AREAL32 top = (AREAL32)(SCREEN_HEIGHT / 2); AREAL32 bottom = top - SCREEN_HEIGHT; float3 pos [] = { float3(left, top, 0.0f), //left top float3(right, top, 0.0f), //right top float3(left, bottom, 0.0f), //left bottom float3(left, bottom, 0.0f), //left bottom float3(right, top, 0.0f), //right top float3(right, bottom, 0.0f), //right bottom }; data.SetData(pos); if (!m_pVertices->Create(¶ms, &data, 6, sizeof(float3))) { assert(0 && "Error creating vertex buffer in Deferred Renderer initialization!"); } //texture coordinates params.SetSize(sizeof(float2) * 6); float2 texCoords [] = { float2(0.0f, 0.0f), //left top float2(1.0f, 0.0f), //right top float2(0.0f, 1.0f), //left bottom float2(0.0f, 1.0f), //left bottom float2(1.0f, 0.0f), //right top float2(1.0f, 1.0f), //right bottom }; data.SetData(texCoords); if (!m_pTexCoords->Create(¶ms, &data, 6, sizeof(float2))) { assert(0 && "Error creating vertex buffer with texture coordinates in Deferred Renderer initialization!"); } //initialize input layout m_pDefaultLayout = new INPUT_LAYOUT[5]; m_pDefaultLayout[0].SemanticName = "POSITION"; m_pDefaultLayout[1].SemanticName = "TEXCOORDS"; m_pDefaultLayout[0].SemanticIndex = 0; m_pDefaultLayout[1].SemanticIndex = 0; m_pDefaultLayout[0].Format = TEX_R32G32B32_FLOAT; m_pDefaultLayout[1].Format = TEX_R32G32_FLOAT; m_pDefaultLayout[0].InputSlot = 0; m_pDefaultLayout[1].InputSlot = 1; m_pDefaultLayout[0].AlignedByteOffset = 0; m_pDefaultLayout[1].AlignedByteOffset = 0; m_pDefaultLayout[0].InputSlotClass = IA_PER_VERTEX_DATA; m_pDefaultLayout[1].InputSlotClass = IA_PER_VERTEX_DATA; m_pDefaultLayout[0].InstanceDataStepRate = 0; m_pDefaultLayout[1].InstanceDataStepRate = 0; m_pDefaultLayout[2].SemanticName = "NORMAL"; m_pDefaultLayout[3].SemanticName = "TANGENT"; m_pDefaultLayout[2].SemanticIndex = 0; m_pDefaultLayout[3].SemanticIndex = 0; m_pDefaultLayout[2].Format = TEX_R32G32B32_FLOAT; m_pDefaultLayout[3].Format = TEX_R32G32B32_FLOAT; m_pDefaultLayout[2].InputSlot = 2; m_pDefaultLayout[3].InputSlot = 2; m_pDefaultLayout[2].AlignedByteOffset = 0; m_pDefaultLayout[3].AlignedByteOffset = 12; m_pDefaultLayout[2].InputSlotClass = IA_PER_VERTEX_DATA; m_pDefaultLayout[3].InputSlotClass = IA_PER_VERTEX_DATA; m_pDefaultLayout[2].InstanceDataStepRate = 0; m_pDefaultLayout[3].InstanceDataStepRate = 0; m_pDefaultLayout[4].SemanticName = "BINORMAL"; m_pDefaultLayout[4].SemanticIndex = 0; m_pDefaultLayout[4].Format = TEX_R32G32B32_FLOAT; m_pDefaultLayout[4].InputSlot = 2; m_pDefaultLayout[4].AlignedByteOffset = 24; m_pDefaultLayout[4].InputSlotClass = IA_PER_VERTEX_DATA; m_pDefaultLayout[4].InstanceDataStepRate = 0; //Initialize shaders m_pDefaultGBufferShaders->VSetVertexShader(L"GBufferShader.hlsl", "VS", m_pDefaultLayout, 5, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pDefaultGBufferShaders->VSetPixelShader(L"GBufferShader.hlsl", "PS", "ps_5_0"); //input layout m_pLayout = new INPUT_LAYOUT[2]; m_pLayout[0].SemanticName = "POSITION"; m_pLayout[1].SemanticName = "TEXCOORDS"; m_pLayout[0].SemanticIndex = 0; m_pLayout[1].SemanticIndex = 0; m_pLayout[0].Format = TEX_R32G32B32_FLOAT; m_pLayout[1].Format = TEX_R32G32_FLOAT; m_pLayout[0].InputSlot = 0; m_pLayout[1].InputSlot = 1; m_pLayout[0].AlignedByteOffset = 0; m_pLayout[1].AlignedByteOffset = 0; m_pLayout[0].InputSlotClass = IA_PER_VERTEX_DATA; m_pLayout[1].InputSlotClass = IA_PER_VERTEX_DATA; m_pLayout[0].InstanceDataStepRate = 0; m_pLayout[1].InstanceDataStepRate = 0; //////////////////////////////////////////////////////// //Shadow mapping m_pShadowsLayout = new INPUT_LAYOUT(); m_pShadowsLayout->SemanticName = "POSITION"; m_pShadowsLayout->SemanticIndex = 0; m_pShadowsLayout->Format = TEX_R32G32B32_FLOAT; m_pShadowsLayout->InputSlot = 0; m_pShadowsLayout->AlignedByteOffset = 0; m_pShadowsLayout->InputSlotClass = IA_PER_VERTEX_DATA; m_pShadowsLayout->InstanceDataStepRate = 0; m_pShadowsShaders->VSetVertexShader(L"Resources\\Shaders\\Shadows\\ShadowMap_VS.hlsl", "Shadows_VS", m_pShadowsLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pShadowsShaders->VSetPixelShader(L"Resources\\Shaders\\Shadows\\ShadowMap_PS.hlsl", "Shadows_PS", "ps_5_0"); m_pShadowCubeShaders->VSetVertexShader(L"Shaders\\CubeShadowMap_VS.hlsl", "CubeShadowMap_VS", m_pShadowsLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pShadowCubeShaders->VSetGeometryShader(L"Shaders\\CubeShadowMap_GS.hlsl", "CubeShadowMap_GS", "gs_5_0"); m_pShadowCubeShaders->VSetPixelShader(L"Shaders\\CubeShadowMap_PS.hlsl", "CubeShadowMap_PS", "gs_5_0"); m_pVarianceShadowsShaders->VSetVertexShader(L"Resources\\Shaders\\Shadows\\VarianceShadows_DepthVS.hlsl", "VarianceShadows_DepthVS", m_pShadowsLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pVarianceShadowsShaders->VSetPixelShader(L"Resources\\Shaders\\Shadows\\VarianceShadows_DepthPS.hlsl", "VarianceShadows_DepthPS", "ps_5_0"); //////////////////////////////////////////////////////// //Motion Blur m_pMotionBlurLayout = new INPUT_LAYOUT[2]; m_pMotionBlurLayout[0].SemanticName = "POSITION"; m_pMotionBlurLayout[1].SemanticName = "TEXCOORD"; m_pMotionBlurLayout[0].SemanticIndex = 0; m_pMotionBlurLayout[1].SemanticIndex = 0; m_pMotionBlurLayout[0].Format = TEX_R32G32B32_FLOAT; m_pMotionBlurLayout[1].Format = TEX_R32G32_FLOAT; m_pMotionBlurLayout[0].InputSlot = 0; m_pMotionBlurLayout[1].InputSlot = 1; m_pMotionBlurLayout[0].AlignedByteOffset = 0; m_pMotionBlurLayout[1].AlignedByteOffset = 0; m_pMotionBlurLayout[0].InputSlotClass = IA_PER_VERTEX_DATA; m_pMotionBlurLayout[1].InputSlotClass = IA_PER_VERTEX_DATA; m_pMotionBlurLayout[0].InstanceDataStepRate = 0; m_pMotionBlurLayout[1].InstanceDataStepRate = 0; m_pVelocityMapShaders->VSetVertexShader(L"Resources\\Shaders\\PostProcessing\\VelocityMap_VS.hlsl", "GenerateVelocityMap_VS", m_pMotionBlurLayout, 2, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pVelocityMapShaders->VSetPixelShader(L"Resources\\Shaders\\PostProcessing\\VelocityMap_PS.hlsl", "GenerateVelocityMap_PS", "ps_5_0"); m_pMotionBlurShaders->VSetVertexShader(L"Resources\\Shaders\\PostProcessing\\MotionBlur_VS.hlsl", "MotionBlur_VS", m_pMotionBlurLayout, 2, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pMotionBlurShaders->VSetPixelShader(L"Resources\\Shaders\\PostProcessing\\MotionBlur_PS.hlsl", "MotionBlur_PS", "ps_5_0"); //////////////////////////////////////////////////////// //resourece copying m_pSRVtoRTVLayout = new INPUT_LAYOUT(); m_pSRVtoRTVLayout->SemanticName = "POSITION"; m_pSRVtoRTVLayout->SemanticIndex = 0; m_pSRVtoRTVLayout->Format = TEX_R32G32B32_FLOAT; m_pSRVtoRTVLayout->InputSlot = 0; m_pSRVtoRTVLayout->AlignedByteOffset = 0; m_pSRVtoRTVLayout->InputSlotClass = IA_PER_VERTEX_DATA; m_pSRVtoRTVLayout->InstanceDataStepRate = 0; m_pSRVtoRTVShaders->VSetVertexShader(L"Resources\\Shaders\\Other\\FromSRVtoRTV_VS.hlsl", "SRVtoRTV_VS", m_pSRVtoRTVLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pSRVtoRTVShaders->VSetPixelShader(L"Resources\\Shaders\\Other\\FromSRVtoRTV_PS.hlsl", "SRVtoRTV_PS", "ps_5_0"); //////////////////////////////////////////////////////// //Ambient occlusion m_pSSAOLayout = new INPUT_LAYOUT(); m_pSSAOLayout->SemanticName = "POSITION"; m_pSSAOLayout->SemanticIndex = 0; m_pSSAOLayout->Format = TEX_R32G32B32_FLOAT; m_pSSAOLayout->InputSlot = 0; m_pSSAOLayout->AlignedByteOffset = 0; m_pSSAOLayout->InputSlotClass = IA_PER_VERTEX_DATA; m_pSSAOLayout->InstanceDataStepRate = 0; m_pSSAOShaders->VSetVertexShader(L"SSAO_Vertex.hlsl", "SSAO_VS", m_pSSAOLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pSSAOShaders->VSetPixelShader(L"SSAO_Pixel.hlsl", "SSAO_PS", "ps_5_0"); Texture2DParams tex2DParams; tex2DParams.Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, TEX_R32G32B32A32_FLOAT, true, true, true, false, 1, 0, 1, true, false, false); m_pSSAOTexture->Create(&tex2DParams); //create shader resource and render target view for the texture ShaderResourceViewParams srvSSAOParams; srvSSAOParams.InitForTexture2D(tex2DParams.Format, 0, 0, false); m_pSSAOTexture->CreateShaderResourceView(&m_pSSAOSRV->m_pView, &srvSSAOParams); UnorderedAccessViewParams uavSSAOParams; uavSSAOParams.InitForTexture2D(tex2DParams.Format, 0); m_pSSAOTexture->CreateUnorderedAccessView(&m_pSSAOUAV->m_pView, &uavSSAOParams); RenderTargetViewParams rtvSSAOParams; rtvSSAOParams.InitForTexture2D(tex2DParams.Format, 0, false); m_pSSAOTexture->CreateRenderTargetView(&m_pSSAORTV->m_pView, &rtvSSAOParams); /////////////////////////////////////////////// //Initialize sky resources /////////////////////////////////////////////// tex2DParams.InitCubeTexture(1024, 1024, 1, TEX_R8G8B8A8_UNORM, true, false, false, false, 1, 0, 1, true, false, false); //m_pSkyTexture->CreateFromFile(L"church_cubemap.dds"); m_pSkyTexture->CreateFromFile(L"space_cubemap.dds"); ShaderResourceViewParams srvSkyParams; srvSkyParams.InitForCubeTexture(TEX_R8G8B8A8_UNORM, 1, 0); m_pSkyTexture->CreateShaderResourceView(&m_pSkySRV->m_pView, &srvSkyParams); m_pSkyLayout = new INPUT_LAYOUT(); //m_pSkyLayout[0].SemanticName = "POSITION"; //m_pSkyLayout[1].SemanticName = "TEXCOORD"; //m_pSkyLayout[0].SemanticIndex = 0; //m_pSkyLayout[1].SemanticIndex = 0; //m_pSkyLayout[0].Format = TEX_R32G32B32_FLOAT; //m_pSkyLayout[1].Format = TEX_R32G32_FLOAT; //m_pSkyLayout[0].InputSlot = 0; //m_pSkyLayout[1].InputSlot = 1; //m_pSkyLayout[0].AlignedByteOffset = 0; //m_pSkyLayout[1].AlignedByteOffset = 0; //m_pSkyLayout[0].InputSlotClass = IA_PER_VERTEX_DATA; //m_pSkyLayout[1].InputSlotClass = IA_PER_VERTEX_DATA; //m_pSkyLayout[0].InstanceDataStepRate = 0; //m_pSkyLayout[1].InstanceDataStepRate = 0; m_pSkyLayout->SemanticName = "POSITION"; m_pSkyLayout->SemanticIndex = 0; m_pSkyLayout->Format = TEX_R32G32B32_FLOAT; m_pSkyLayout->InputSlot = 0; m_pSkyLayout->AlignedByteOffset = 0; m_pSkyLayout->InputSlotClass = IA_PER_VERTEX_DATA; m_pSkyLayout->InstanceDataStepRate = 0; m_pSkyShaders->VSetVertexShader(L"Source\\Shaders\\SkyBox.hlsl", "SkyBox_VS", m_pSkyLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); m_pSkyShaders->VSetPixelShader(L"Source\\Shaders\\SkyBox.hlsl", "SkyBox_PS", "ps_5_0"); //m_pAtmoShaders->VSetVertexShader(L"Shaders\\Atmosphere\\SkyFromAtmosphere_vs.hlsl", "SkyFromAtmosphere_vs", m_pSkyLayout, 1, TOPOLOGY_TRIANGLELIST, "vs_5_0"); //m_pAtmoShaders->VSetPixelShader(L"Shaders\\Atmosphere\\SkyFromAtmosphere_ps.hlsl", "SkyFromAtmosphere_ps", "ps_5_0"); Resource meshResource("sphere.obj"); shared_ptr<ResHandle> pMeshes = Anubis::SafeGetHandle(&meshResource); std::shared_ptr<MeshResourceExtraData> pData = static_pointer_cast<MeshResourceExtraData>(pMeshes->GetExtra()); m_pSphereMesh = pData->m_pMeshes[0]; /////////////////////////////////////////////// //Antialiasing /////////////////////////////////////////////// m_pNullLayout = nullptr; struct EmptyVertex {}; EmptyVertex verts [] = { EmptyVertex(), EmptyVertex(), EmptyVertex(), }; params.FillVertexBufferParams(0, 3, true, false, false, false); SubresourceData emptydata; data.SetData(verts); // m_pFullscreenEmpty->Create(¶ms, &emptydata, 3, 0); //m_pFXAAShaders->VSetVertexShader(L"Shaders\\FXAA.hlsl", "FXAA_VS", m_pLayout, 0, TOPOLOGY_TRIANGLELIST); //m_pFXAAShaders->VSetPixelShader(L"Shaders\\FXAA.hlsl", "FXAA_PS"); m_pFXAAShaders->VSetVertexShader(L"Shaders\\FXAA_orig.hlsl", "FxaaVS", m_pLayout, 0, TOPOLOGY_TRIANGLESTRIP, "vs_5_0"); m_pFXAAShaders->VSetPixelShader(L"Shaders\\FXAA_orig.hlsl", "FxaaPS", "ps_5_0"); /////////////////////////////////////////////// //Initialize data for blurring /////////////////////////////////////////////// tex2DParams.Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, TEX_R32G32B32A32_FLOAT, true, true, false, false, 1, 0, 1, true, false, false); m_pSSAOBlurredTexture->Create(&tex2DParams); srvSSAOParams.InitForTexture2D(tex2DParams.Format, 0, 0, false); m_pSSAOBlurredTexture->CreateShaderResourceView(&m_pSSAOBlurredSRV->m_pView, &srvSSAOParams); uavSSAOParams.InitForTexture2D(tex2DParams.Format, 0); m_pSSAOBlurredTexture->CreateUnorderedAccessView(&m_pSSAOBlurredUAV->m_pView, &uavSSAOParams); return true; }