| 59 | using namespace donut::render; |
| 60 | |
| 61 | LightProbeProcessingPass::LightProbeProcessingPass( |
| 62 | nvrhi::IDevice* device, |
| 63 | std::shared_ptr<ShaderFactory> shaderFactory, |
| 64 | std::shared_ptr<CommonRenderPasses> commonPasses, |
| 65 | uint32_t intermediateTextureSize, |
| 66 | nvrhi::Format intermediateTextureFormat) |
| 67 | : m_Device(device) |
| 68 | , m_IntermediateTextureSize(intermediateTextureSize) |
| 69 | , m_CommonPasses(commonPasses) |
| 70 | { |
| 71 | m_GeometryShader = shaderFactory->CreateAutoShader("donut/passes/light_probe.hlsl", "cubemap_gs", DONUT_MAKE_PLATFORM_SHADER(g_light_probe_cubemap_gs), nullptr, nvrhi::ShaderType::Geometry); |
| 72 | m_MipPixelShader = shaderFactory->CreateAutoShader("donut/passes/light_probe.hlsl", "mip_ps", DONUT_MAKE_PLATFORM_SHADER(g_light_probe_mip_ps), nullptr, nvrhi::ShaderType::Pixel); |
| 73 | m_DiffusePixelShader = shaderFactory->CreateAutoShader("donut/passes/light_probe.hlsl", "diffuse_probe_ps", DONUT_MAKE_PLATFORM_SHADER(g_light_probe_diffuse_probe_ps), nullptr, nvrhi::ShaderType::Pixel); |
| 74 | m_SpecularPixelShader = shaderFactory->CreateAutoShader("donut/passes/light_probe.hlsl", "specular_probe_ps", DONUT_MAKE_PLATFORM_SHADER(g_light_probe_specular_probe_ps), nullptr, nvrhi::ShaderType::Pixel); |
| 75 | m_EnvironmentBrdfPixelShader = shaderFactory->CreateAutoShader("donut/passes/light_probe.hlsl", "environment_brdf_ps", DONUT_MAKE_PLATFORM_SHADER(g_light_probe_environment_brdf_ps), nullptr, nvrhi::ShaderType::Pixel); |
| 76 | |
| 77 | nvrhi::BindingLayoutDesc layoutDesc; |
| 78 | layoutDesc.visibility = nvrhi::ShaderType::Pixel; |
| 79 | layoutDesc.bindings = { |
| 80 | nvrhi::BindingLayoutItem::VolatileConstantBuffer(0), |
| 81 | nvrhi::BindingLayoutItem::Sampler(0), |
| 82 | nvrhi::BindingLayoutItem::Texture_SRV(0), |
| 83 | }; |
| 84 | m_BindingLayout = device->createBindingLayout(layoutDesc); |
| 85 | |
| 86 | nvrhi::BufferDesc constantBufferDesc; |
| 87 | constantBufferDesc.byteSize = sizeof(LightProbeProcessingConstants); |
| 88 | constantBufferDesc.debugName = "LightProbeProcessingConstants"; |
| 89 | constantBufferDesc.isConstantBuffer = true; |
| 90 | constantBufferDesc.isVolatile = true; |
| 91 | constantBufferDesc.maxVersions = 64; |
| 92 | m_LightProbeCB = device->createBuffer(constantBufferDesc); |
| 93 | |
| 94 | assert(intermediateTextureSize > 0); |
| 95 | |
| 96 | nvrhi::TextureDesc cubemapDesc; |
| 97 | cubemapDesc.arraySize = 6; |
| 98 | cubemapDesc.width = intermediateTextureSize; |
| 99 | cubemapDesc.height = intermediateTextureSize; |
| 100 | cubemapDesc.mipLevels = static_cast<uint32_t>(floor(dm::log2f(static_cast<float>(intermediateTextureSize)))) + 1; |
| 101 | cubemapDesc.dimension = nvrhi::TextureDimension::TextureCube; |
| 102 | cubemapDesc.isRenderTarget = true; |
| 103 | cubemapDesc.format = intermediateTextureFormat; |
| 104 | cubemapDesc.initialState = nvrhi::ResourceStates::RenderTarget; |
| 105 | cubemapDesc.keepInitialState = true; |
| 106 | cubemapDesc.clearValue = nvrhi::Color(0.f); |
| 107 | cubemapDesc.useClearValue = true; |
| 108 | |
| 109 | m_IntermediateTexture = m_Device->createTexture(cubemapDesc); |
| 110 | |
| 111 | m_EnvironmentBrdfTextureSize = 64; |
| 112 | |
| 113 | nvrhi::TextureDesc brdfTextureDesc; |
| 114 | brdfTextureDesc.width = m_EnvironmentBrdfTextureSize; |
| 115 | brdfTextureDesc.height = m_EnvironmentBrdfTextureSize; |
| 116 | brdfTextureDesc.format = nvrhi::Format::RG16_FLOAT; |
| 117 | brdfTextureDesc.initialState = nvrhi::ResourceStates::ShaderResource; |
| 118 | brdfTextureDesc.keepInitialState = true; |
nothing calls this directly
no test coverage detected