From a100975fb089985a7ef95e360e15cf9537d6e49e Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 4 Dec 2017 12:02:13 +0000 Subject: [PATCH] PSO format defs --- WickedEngine/DeferredRenderableComponent.cpp | 21 ++- WickedEngine/ForwardRenderableComponent.cpp | 4 +- WickedEngine/Renderable3DComponent.cpp | 22 +-- WickedEngine/wiDepthTarget.cpp | 7 +- WickedEngine/wiEmittedParticle.cpp | 2 + WickedEngine/wiFont.cpp | 2 +- WickedEngine/wiHairParticle.cpp | 30 ++++ WickedEngine/wiImage.cpp | 29 ++++ WickedEngine/wiLensFlare.cpp | 18 +-- WickedEngine/wiOcean.cpp | 3 + WickedEngine/wiRenderer.cpp | 142 ++++++++++++++++--- WickedEngine/wiRenderer.h | 27 ++++ 12 files changed, 248 insertions(+), 59 deletions(-) diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 33246fb4e..7d5c06438 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -52,28 +52,25 @@ void DeferredRenderableComponent::ResizeBuffers() rtGBuffer.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , true, FORMAT_R8G8B8A8_UNORM); - rtGBuffer.Add(FORMAT_R16G16B16A16_FLOAT); - rtGBuffer.Add(FORMAT_R8G8B8A8_UNORM); - rtGBuffer.Add(FORMAT_R8G8B8A8_UNORM); - - // NOTE: Light buffer precision seems OK when using FORMAT_R11G11B10_FLOAT format - // But the environmental light now also writes the AO to ALPHA so it has been changed to FORMAT_R16G16B16A16_FLOAT + , true, wiRenderer::RTFormat_gbuffer_0); + rtGBuffer.Add(wiRenderer::RTFormat_gbuffer_1); + rtGBuffer.Add(wiRenderer::RTFormat_gbuffer_2); + rtGBuffer.Add(wiRenderer::RTFormat_gbuffer_3); rtDeferred.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); rtLight.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); // diffuse - rtLight.Add(FORMAT_R16G16B16A16_FLOAT); // specular + , false, wiRenderer::RTFormat_deferred_lightbuffer); // diffuse + rtLight.Add(wiRenderer::RTFormat_deferred_lightbuffer); // specular rtSSS[0].Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); rtSSS[1].Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); } void DeferredRenderableComponent::Initialize() diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 39177927b..6a658737b 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -46,8 +46,8 @@ void ForwardRenderableComponent::ResizeBuffers() lastBufferFormat = defaultTextureFormat; } - rtMain.Initialize(wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y, true, FORMAT_R16G16B16A16_FLOAT, 1, getMSAASampleCount(), false); - rtMain.Add(FORMAT_R16G16B16A16_FLOAT); // thin gbuffer + rtMain.Initialize(wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y, true, wiRenderer::RTFormat_forward, 1, getMSAASampleCount(), false); + rtMain.Add(wiRenderer::RTFormat_gbuffer_1); // thin gbuffer } void ForwardRenderableComponent::Initialize() diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 884458129..71705019d 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -62,26 +62,26 @@ void Renderable3DComponent::ResizeBuffers() rtSSR.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); rtMotionBlur.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); rtLinearDepth.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R32_FLOAT); + , false, wiRenderer::RTFormat_lineardepth); rtParticle.Initialize( (UINT)(wiRenderer::GetInternalResolution().x*getAlphaParticleDownSample()), (UINT)(wiRenderer::GetInternalResolution().y*getAlphaParticleDownSample()) - , false, FORMAT_R16G16B16A16_FLOAT); + , false, wiRenderer::RTFormat_temp_hdr); rtWaterRipple.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R8G8B8A8_SNORM); + , false, wiRenderer::RTFormat_waterripple); rtSceneCopy.Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y - , false, FORMAT_R16G16B16A16_FLOAT, 8); + , false, wiRenderer::RTFormat_temp_hdr, 8); rtReflection.Initialize( (UINT)(wiRenderer::GetInternalResolution().x * getReflectionQuality()) , (UINT)(wiRenderer::GetInternalResolution().y * getReflectionQuality()) - , true, FORMAT_R16G16B16A16_FLOAT); + , true, wiRenderer::RTFormat_temp_hdr); rtFinal[0].Initialize( wiRenderer::GetInternalResolution().x, wiRenderer::GetInternalResolution().y , false, defaultTextureFormat); @@ -106,7 +106,7 @@ void Renderable3DComponent::ResizeBuffers() for (unsigned int i = 0; i 1) { depthDesc.SampleDesc.Count = 1; - depthDesc.Format = FORMAT_R32_FLOAT; + depthDesc.Format = wiRenderer::RTFormat_depthresolve; depthDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; wiRenderer::GetDevice()->CreateTexture2D(&depthDesc, nullptr, &texture_resolvedMSAA); } @@ -64,7 +63,7 @@ void wiDepthTarget::InitializeCube(int size, bool independentFaces) depthGPUBufferDesc.Height = size; depthGPUBufferDesc.MipLevels = 1; depthGPUBufferDesc.ArraySize = 6; - depthGPUBufferDesc.Format = FORMAT_R16_TYPELESS; + depthGPUBufferDesc.Format = wiRenderer::DSFormat_small_alias; depthGPUBufferDesc.SampleDesc.Count = 1; depthGPUBufferDesc.SampleDesc.Quality = 0; depthGPUBufferDesc.Usage = USAGE_DEFAULT; diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 5d9c5305a..862e762a7 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -552,6 +552,7 @@ void wiEmittedParticle::LoadShaders() desc.rs = &rasterizerState; desc.dss = &depthStencilState; desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_temp_hdr; device->CreateGraphicsPSO(&desc, &PSO[i]); } @@ -564,6 +565,7 @@ void wiEmittedParticle::LoadShaders() desc.rs = &wireFrameRS; desc.dss = &depthStencilState; desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_temp_hdr; device->CreateGraphicsPSO(&desc, &PSO_wire); } diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 8fb38cd87..947a0fcd4 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -147,7 +147,7 @@ void wiFont::LoadShaders() desc.rs = rasterizerState; desc.dss = depthStencilState; desc.numRTs = 1; - desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat(); + desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat(); SAFE_DELETE(PSO); PSO = new GraphicsPSO; wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO); diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index a65366961..e000e2796 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -147,6 +147,11 @@ void wiHairParticle::LoadShaders() for (int j = 0; j < 2; ++j) { + if ((i == SHADERTYPE_DEPTHONLY || i == SHADERTYPE_DEFERRED) && j == 1) + { + continue; + } + GraphicsPSODesc desc; desc.vs = vs; desc.ps = ps[i]; @@ -154,6 +159,30 @@ void wiHairParticle::LoadShaders() desc.rs = &ncrs; desc.dss = &dss_default; + desc.DSFormat = wiRenderer::DSFormat_full; + + switch (i) + { + case SHADERTYPE_TEXTURE: + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_forward; + break; + case SHADERTYPE_FORWARD: + case SHADERTYPE_TILEDFORWARD: + desc.numRTs = 2; + desc.RTFormats[0] = wiRenderer::RTFormat_forward; + desc.RTFormats[1] = wiRenderer::RTFormat_gbuffer_1; + break; + case SHADERTYPE_DEFERRED: + desc.numRTs = 4; + desc.RTFormats[0] = wiRenderer::RTFormat_gbuffer_0; + desc.RTFormats[1] = wiRenderer::RTFormat_gbuffer_1; + desc.RTFormats[2] = wiRenderer::RTFormat_gbuffer_2; + desc.RTFormats[3] = wiRenderer::RTFormat_gbuffer_3; + default: + break; + } + if (i == SHADERTYPE_TILEDFORWARD) { desc.dss = &dss_equal; // opaque @@ -162,6 +191,7 @@ void wiHairParticle::LoadShaders() if(j == 1) { desc.dss = &dss_rejectopaque_keeptransparent; // transparent + desc.numRTs = 1; } device->CreateGraphicsPSO(&desc, &PSO[i][j]); diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 1647ddeae..28171566b 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -112,6 +112,18 @@ void wiImage::LoadShaders() { desc.dss = &depthStencilStates[k]; + if (k == STENCILMODE_DISABLED) + { + desc.DSFormat = FORMAT_UNKNOWN; + } + else + { + desc.DSFormat = wiRenderer::DSFormat_full; + } + + desc.numRTs = 1; + desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat(); + device->CreateGraphicsPSO(&desc, &imagePSO[i][j][k]); } } @@ -129,10 +141,24 @@ void wiImage::LoadShaders() if (i == POSTPROCESS_DOWNSAMPLEDEPTHBUFFER || i == POSTPROCESS_REPROJECTDEPTHBUFFER) { desc.dss = &depthStencilStateDepthWrite; + desc.DSFormat = wiRenderer::DSFormat_small; + desc.numRTs = 0; } else if (i == POSTPROCESS_SSSS) { desc.dss = &depthStencilStates[STENCILMODE_LESS]; + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_deferred_lightbuffer; + } + else if (i == POSTPROCESS_SSAO) + { + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_ssao; + } + else + { + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_temp_hdr; } device->CreateGraphicsPSO(&desc, &postprocessPSO[i]); @@ -144,6 +170,9 @@ void wiImage::LoadShaders() desc.bs = &blendStates[BLENDMODE_OPAQUE]; desc.dss = &depthStencilStates[STENCILMODE_LESS]; desc.rs = &rasterizerState; + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_temp_hdr; + desc.DSFormat = wiRenderer::DSFormat_full; device->CreateGraphicsPSO(&desc, &deferredPSO); } diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index 6673022d2..c89c0c156 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -37,10 +37,8 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, std::v device->EventBegin("LensFlare", threadID); device->BindPrimitiveTopology(POINTLIST,threadID); - //device->BindVertexLayout(inputLayout,threadID); - //device->BindPS(pixelShader,threadID); - //device->BindVS(vertexShader,threadID); - //device->BindGS(geometryShader,threadID); + + device->BindGraphicsPSO(&PSO, threadID); ConstantBuffer cb; cb.mSunPos = lightPos / XMVectorSet((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 1, 1); @@ -49,10 +47,6 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, std::v device->UpdateBuffer(constantBuffer,&cb,threadID); device->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); - - //device->BindRasterizerState(rasterizerState,threadID); - //device->BindDepthStencilState(depthStencilState,1,threadID); - //device->BindBlendState(blendState,threadID); int i=0; for(Texture2D* x : rims){ @@ -68,10 +62,6 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, std::v device->Draw(i, 0, threadID); - - - - //device->BindGS(nullptr,threadID); device->EventEnd(threadID); } @@ -105,6 +95,10 @@ void wiLensFlare::LoadShaders(){ desc.bs = &blendState; desc.rs = &rasterizerState; desc.dss = &depthStencilState; + desc.ptt = PRIMITIVE_TOPOLOGY_TYPE_POINT; + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_temp_hdr; + device->CreateGraphicsPSO(&desc, &PSO); } void wiLensFlare::SetUpCB() { diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 46de7b8dc..f4c9f7503 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -402,6 +402,9 @@ void wiOcean::LoadShaders() desc.bs = &blendState; desc.rs = &rasterizerState; desc.dss = &depthStencilState; + desc.numRTs = 1; + desc.RTFormats[0] = wiRenderer::RTFormat_forward; + desc.DSFormat = wiRenderer::DSFormat_full; device->CreateGraphicsPSO(&desc, &PSO); desc.ps = g_pWireframePS; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 0fc1674ac..12a1d2848 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -245,7 +245,7 @@ void wiRenderer::SetUpStaticComponents() normalMapRT.Initialize( GetInternalResolution().x , GetInternalResolution().y - ,false,FORMAT_R8G8B8A8_SNORM + ,false, RTFormat_normalmaps ); imagesRTAdd.Initialize( GetInternalResolution().x @@ -1530,6 +1530,9 @@ void wiRenderer::LoadShaders() case SHADERTYPE_ENVMAPCAPTURE: desc.dss = depthStencils[DSSTYPE_ENVMAP]; break; + case SHADERTYPE_VOXELIZE: + desc.dss = depthStencils[DSSTYPE_XRAY]; + break; default: desc.dss = depthStencils[DSSTYPE_DEFAULT]; break; @@ -1549,6 +1552,55 @@ void wiRenderer::LoadShaders() break; } + switch (shaderType) + { + case SHADERTYPE_TEXTURE: + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_forward; + desc.DSFormat = DSFormat_full; + break; + case SHADERTYPE_DEFERRED: + desc.numRTs = 4; + desc.RTFormats[0] = RTFormat_gbuffer_0; + desc.RTFormats[1] = RTFormat_gbuffer_1; + desc.RTFormats[2] = RTFormat_gbuffer_2; + desc.RTFormats[3] = RTFormat_gbuffer_3; + desc.DSFormat = DSFormat_full; + break; + case SHADERTYPE_FORWARD: + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[1] = RTFormat_gbuffer_1; + desc.DSFormat = DSFormat_full; + break; + case SHADERTYPE_TILEDFORWARD: + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[1] = RTFormat_gbuffer_1; + desc.DSFormat = DSFormat_full; + break; + case SHADERTYPE_DEPTHONLY: + desc.numRTs = 0; + desc.DSFormat = DSFormat_full; + break; + case SHADERTYPE_ENVMAPCAPTURE: + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_envprobe; + desc.DSFormat = DSFormat_small; + break; + case SHADERTYPE_SHADOW: + desc.numRTs = 0; + desc.DSFormat = DSFormat_small; + break; + case SHADERTYPE_SHADOWCUBE: + desc.numRTs = 0; + desc.DSFormat = DSFormat_small; + break; + case SHADERTYPE_VOXELIZE: + desc.numRTs = 0; + break; + } + if (tessellation) { desc.ptt = PRIMITIVE_TOPOLOGY_TYPE_PATCH; @@ -1577,6 +1629,11 @@ void wiRenderer::LoadShaders() desc.dss = depthStencils[DSSTYPE_DEFAULT]; desc.il = vertexLayouts[VLTYPE_OBJECT_POS_TEX]; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[1] = RTFormat_gbuffer_1; + desc.DSFormat = DSFormat_full; + desc.ps = pixelShaders[PSTYPE_OBJECT_FORWARD_DIRLIGHT_WATER]; PSO_object_water[SHADERTYPE_FORWARD] = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_object_water[SHADERTYPE_FORWARD]); @@ -1594,6 +1651,10 @@ void wiRenderer::LoadShaders() desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; desc.il = vertexLayouts[VLTYPE_OBJECT_POS_TEX]; + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_forward; + desc.DSFormat = DSFormat_full; + PSO_object_wire = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_object_wire); } @@ -1605,6 +1666,10 @@ void wiRenderer::LoadShaders() desc.bs = blendStates[BSTYPE_DECAL]; desc.dss = depthStencils[DSSTYPE_DECAL]; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_gbuffer_0; + desc.RTFormats[1] = RTFormat_gbuffer_1; + PSO_decal = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_decal); } @@ -1614,6 +1679,8 @@ void wiRenderer::LoadShaders() desc.rs = rasterizers[RSTYPE_OCCLUDEE]; desc.bs = blendStates[BSTYPE_COLORWRITEDISABLE]; desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; + + desc.DSFormat = DSFormat_small; PSO_occlusionquery = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_occlusionquery); @@ -1642,20 +1709,34 @@ void wiRenderer::LoadShaders() { case SHADERTYPE_DEFERRED: realPS = PSTYPE_OBJECT_DEFERRED_NORMALMAP; + desc.numRTs = 4; + desc.RTFormats[0] = RTFormat_gbuffer_0; + desc.RTFormats[1] = RTFormat_gbuffer_1; + desc.RTFormats[2] = RTFormat_gbuffer_2; + desc.RTFormats[3] = RTFormat_gbuffer_3; break; case SHADERTYPE_FORWARD: realPS = PSTYPE_OBJECT_FORWARD_DIRLIGHT_NORMALMAP; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[1] = RTFormat_gbuffer_1; break; case SHADERTYPE_TILEDFORWARD: realPS = PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[1] = RTFormat_gbuffer_1; break; case SHADERTYPE_DEPTHONLY: realPS = PSTYPE_OBJECT_ALPHATESTONLY; break; default: realPS = PSTYPE_OBJECT_TEXTUREONLY; + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_forward; break; } + desc.DSFormat = DSFormat_full; desc.vs = vertexShaders[realVS]; desc.il = vertexLayouts[realVL]; @@ -1674,12 +1755,12 @@ void wiRenderer::LoadShaders() desc.il = vertexLayouts[VLTYPE_OBJECT_ALL]; desc.numRTs = 5; - desc.RTFormats[0] = FORMAT_R8G8B8A8_UNORM; - desc.RTFormats[1] = FORMAT_R8G8B8A8_UNORM; - desc.RTFormats[2] = FORMAT_R8_UNORM; - desc.RTFormats[3] = FORMAT_R8_UNORM; - desc.RTFormats[4] = FORMAT_R8_UNORM; - desc.DSFormat = FORMAT_D32_FLOAT_S8X24_UINT; + desc.RTFormats[0] = RTFormat_impostor_albedo; + desc.RTFormats[1] = RTFormat_impostor_normal; + desc.RTFormats[2] = RTFormat_impostor_roughness; + desc.RTFormats[3] = RTFormat_impostor_metalness; + desc.RTFormats[4] = RTFormat_impostor_reflectance; + desc.DSFormat = DSFormat_full; PSO_captureimpostor = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_captureimpostor); @@ -1733,6 +1814,11 @@ void wiRenderer::LoadShaders() break; } + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_deferred_lightbuffer; + desc.RTFormats[1] = RTFormat_deferred_lightbuffer; + desc.DSFormat = DSFormat_full; + PSO_deferredlight[type] = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_deferredlight[type]); @@ -1781,6 +1867,10 @@ void wiRenderer::LoadShaders() break; } + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_temp_hdr; + desc.DSFormat = DSFormat_full; + PSO_volumelight[type] = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_volumelight[type]); } @@ -1792,6 +1882,11 @@ void wiRenderer::LoadShaders() desc.bs = blendStates[BSTYPE_ENVIRONMENTALLIGHT]; desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_deferred_lightbuffer; + desc.RTFormats[1] = RTFormat_deferred_lightbuffer; + desc.DSFormat = DSFormat_full; + PSO_enviromentallight = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_enviromentallight); } @@ -1807,17 +1902,27 @@ void wiRenderer::LoadShaders() desc.bs = blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_SKY]; desc.ps = pixelShaders[PSTYPE_SKY]; + desc.numRTs = 2; + desc.RTFormats[0] = RTFormat_forward; + desc.RTFormats[0] = RTFormat_gbuffer_1; + desc.DSFormat = DSFormat_full; break; case SKYRENDERING_SUN: desc.bs = blendStates[BSTYPE_ADDITIVE]; desc.vs = vertexShaders[VSTYPE_SKY]; desc.ps = pixelShaders[PSTYPE_SUN]; + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_forward; + desc.DSFormat = DSFormat_full; break; case SKYRENDERING_ENVMAPCAPTURE: desc.bs = blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_ENVMAP_SKY]; desc.ps = pixelShaders[PSTYPE_ENVMAP_SKY]; desc.gs = geometryShaders[GSTYPE_ENVMAP_SKY]; + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_forward; + desc.DSFormat = DSFormat_small; break; } @@ -1923,6 +2028,9 @@ void wiRenderer::LoadShaders() break; } + desc.numRTs = 1; + desc.RTFormats[0] = RTFormat_temp_hdr; + desc.DSFormat = DSFormat_full; PSO_debug[debug] = new GraphicsPSO; device->CreateGraphicsPSO(&desc, PSO_debug[debug]); @@ -4231,7 +4339,7 @@ void wiRenderer::SetShadowProps2D(int resolution, int count, int softShadowQuali desc.Height = SHADOWRES_2D; desc.MipLevels = 1; desc.ArraySize = SHADOWCOUNT_2D; - desc.Format = FORMAT_R16_TYPELESS; + desc.Format = DSFormat_small_alias; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = USAGE_DEFAULT; @@ -4256,7 +4364,7 @@ void wiRenderer::SetShadowPropsCube(int resolution, int count) desc.Height = SHADOWRES_CUBE; desc.MipLevels = 1; desc.ArraySize = 6 * SHADOWCOUNT_CUBE; - desc.Format = FORMAT_R16_TYPELESS; + desc.Format = DSFormat_small_alias; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = USAGE_DEFAULT; @@ -5192,7 +5300,7 @@ void wiRenderer::VoxelRadiance(GRAPHICSTHREAD threadID) desc.Height = voxelSceneData.res; desc.Depth = voxelSceneData.res; desc.MipLevels = 0; - desc.Format = FORMAT_R16G16B16A16_FLOAT; + desc.Format = RTFormat_voxelradiance; desc.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE; desc.Usage = USAGE_DEFAULT; desc.CPUAccessFlags = 0; @@ -5401,7 +5509,7 @@ void wiRenderer::ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID desc.ArraySize = 1; desc.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; - desc.Format = FORMAT_R16G16B16A16_FLOAT; + desc.Format = RTFormat_deferred_lightbuffer; desc.Width = (UINT)_width; desc.Height = (UINT)_height; desc.MipLevels = 1; @@ -6470,7 +6578,7 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) { EnvironmentProbe* probe = new EnvironmentProbe; probe->transform(position); - probe->cubeMap.InitializeCube(resolution, true, FORMAT_R16G16B16A16_FLOAT, 0); + probe->cubeMap.InitializeCube(resolution, true, RTFormat_envprobe, 0); scene->environmentProbes.push_back(probe); } @@ -6486,11 +6594,11 @@ void wiRenderer::CreateImpostor(Mesh* mesh) const XMFLOAT3 extents = bbox.getHalfWidth(); if (!mesh->impostorTarget.IsInitialized()) { - mesh->impostorTarget.Initialize(res * 6, res, true, FORMAT_R8G8B8A8_UNORM, 0); - mesh->impostorTarget.Add(FORMAT_R8G8B8A8_UNORM); // normal - mesh->impostorTarget.Add(FORMAT_R8_UNORM); // roughness - mesh->impostorTarget.Add(FORMAT_R8_UNORM); // reflectance - mesh->impostorTarget.Add(FORMAT_R8_UNORM); // metalness + mesh->impostorTarget.Initialize(res * 6, res, true, RTFormat_impostor_albedo, 0); + mesh->impostorTarget.Add(RTFormat_impostor_normal); // normal + mesh->impostorTarget.Add(RTFormat_impostor_roughness); // roughness + mesh->impostorTarget.Add(RTFormat_impostor_reflectance); // reflectance + mesh->impostorTarget.Add(RTFormat_impostor_metalness); // metalness } Camera savedCam = *cam; diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index adbad4517..17512c11b 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -77,6 +77,33 @@ public: static wiGraphicsTypes::Sampler *customsamplers[SSTYPE_LAST]; static wiGraphicsTypes::GPURingBuffer *dynamicVertexBufferPool; + + static const wiGraphicsTypes::FORMAT RTFormat_forward = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_gbuffer_0 = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_gbuffer_1 = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_gbuffer_2 = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_gbuffer_3 = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_temp_hdr = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + // NOTE: Light buffer precision seems OK when using FORMAT_R11G11B10_FLOAT format + // But the environmental light now also writes the AO to ALPHA so it has been changed to FORMAT_R16G16B16A16_FLOAT + static const wiGraphicsTypes::FORMAT RTFormat_deferred_lightbuffer = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_lineardepth = wiGraphicsTypes::FORMAT_R32_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_ssao = wiGraphicsTypes::FORMAT_R8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_waterripple = wiGraphicsTypes::FORMAT_R8G8B8A8_SNORM; + static const wiGraphicsTypes::FORMAT RTFormat_normalmaps = wiGraphicsTypes::FORMAT_R8G8B8A8_SNORM; + static const wiGraphicsTypes::FORMAT RTFormat_depthresolve = wiGraphicsTypes::FORMAT_R32_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_voxelradiance = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_envprobe = wiGraphicsTypes::FORMAT_R16G16B16A16_FLOAT; + static const wiGraphicsTypes::FORMAT RTFormat_impostor_albedo = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_impostor_normal = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_impostor_roughness = wiGraphicsTypes::FORMAT_R8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_impostor_metalness = wiGraphicsTypes::FORMAT_R8_UNORM; + static const wiGraphicsTypes::FORMAT RTFormat_impostor_reflectance = wiGraphicsTypes::FORMAT_R8_UNORM; + + static const wiGraphicsTypes::FORMAT DSFormat_full = wiGraphicsTypes::FORMAT_D32_FLOAT_S8X24_UINT; + static const wiGraphicsTypes::FORMAT DSFormat_full_alias = wiGraphicsTypes::FORMAT_R32G8X24_TYPELESS; + static const wiGraphicsTypes::FORMAT DSFormat_small = wiGraphicsTypes::FORMAT_D16_UNORM; + static const wiGraphicsTypes::FORMAT DSFormat_small_alias = wiGraphicsTypes::FORMAT_R16_TYPELESS; static float GAMMA; static int SHADOWRES_2D, SHADOWRES_CUBE, SHADOWCOUNT_2D, SHADOWCOUNT_CUBE, SOFTSHADOWQUALITY_2D;