static void RenderVolumetricClouds_Sky_High(CommandBuffer cmd, VolumetricCloudsSkyHighPassData passData, MaterialPropertyBlock mpb) { // Compute the number of tiles to evaluate int finalTX = (passData.finalWidth + (8 - 1)) / 8; int finalTY = (passData.finalHeight + (8 - 1)) / 8; // Bind the sampling textures BlueNoise.BindDitheredTextureSet(cmd, passData.commonData.ditheredTextureSet); // Set the multi compile CoreUtils.SetKeyword(cmd, "LOCAL_VOLUMETRIC_CLOUDS", false); // Bind the constant buffer ConstantBuffer.Push(cmd, passData.commonData.cloudsCB, passData.commonData.volumetricCloudsCS, HDShaderIDs._ShaderVariablesClouds); // Ray-march the clouds for this frame CoreUtils.SetKeyword(cmd, "PHYSICALLY_BASED_SUN", passData.commonData.cloudsCB._PhysicallyBasedSun == 1); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._MaxZMaskTexture, passData.maxZMask); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._Worley128RGBA, passData.commonData.worley128RGBA); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._ErosionNoise, passData.commonData.erosionNoise); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._CloudMapTexture, passData.commonData.cloudMapTexture); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._CloudLutTexture, passData.commonData.cloudLutTexture); cmd.SetComputeBufferParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._VolumetricCloudsAmbientProbeBuffer, passData.ambientProbeBuffer); // Output buffers cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._CloudsLightingTextureRW, passData.intermediateLightingBuffer0); cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._CloudsDepthTextureRW, passData.intermediateDepthBuffer); // Trace the clouds cmd.DispatchCompute(passData.commonData.volumetricCloudsCS, passData.renderKernel, finalTX, finalTY, 1); // Reset the multi compile CoreUtils.SetKeyword(cmd, "PHYSICALLY_BASED_SUN", false); if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal) { // On Intel GPUs on OSX, due to the fact that we cannot always rely on pre-exposure the hardware blending fails and turns into Nans when // the values are close to the max fp16 value. We do the blending manually on metal to avoid that behavior. // Copy the target face of the cubemap into a temporary texture cmd.CopyTexture(passData.output, (int)passData.cubemapFace, 0, passData.intermediateLightingBuffer1, 0, 0); // Output the result into the output buffer mpb.SetTexture(HDShaderIDs._CameraColorTexture, passData.intermediateLightingBuffer1); mpb.SetTexture(HDShaderIDs._VolumetricCloudsUpscaleTextureRW, passData.intermediateLightingBuffer0); CoreUtils.SetRenderTarget(cmd, passData.output, ClearFlag.None, 0, passData.cubemapFace); CoreUtils.DrawFullScreen(cmd, passData.cloudCombinePass, mpb, 1); } else { // Output the result into the output buffer mpb.SetTexture(HDShaderIDs._VolumetricCloudsUpscaleTextureRW, passData.intermediateLightingBuffer0); CoreUtils.SetRenderTarget(cmd, passData.output, ClearFlag.None, 0, passData.cubemapFace); CoreUtils.DrawFullScreen(cmd, passData.cloudCombinePass, mpb, 2); } }
void PrepareVolumetricCloudsSkyHighPassData(RenderGraph renderGraph, RenderGraphBuilder builder, HDCamera hdCamera, int width, int height, Matrix4x4[] pixelCoordToViewDir, CubemapFace cubemapFace, VolumetricClouds settings, TextureHandle output, VolumetricCloudsSkyHighPassData data) { // Compute the cloud model data CloudModelData cloudModelData = GetCloudModelData(settings); // Fill the common data FillVolumetricCloudsCommonData(false, settings, TVolumetricCloudsCameraType.Sky, in cloudModelData, ref data.commonData); // If this is a baked reflection, we run everything at full res data.finalWidth = width; data.finalHeight = height; // Sky data.cubemapFace = cubemapFace; data.cloudCombinePass = m_CloudCombinePass; // Compute shader and kernels data.renderKernel = m_CloudRenderKernel; data.combineKernel = m_CombineCloudsSkyKernel; data.pixelCoordToViewDir = pixelCoordToViewDir; // Update the constant buffer VolumetricCloudsCameraData cameraData; cameraData.cameraType = data.commonData.cameraType; cameraData.traceWidth = data.finalWidth; cameraData.traceHeight = data.finalHeight; cameraData.intermediateWidth = data.finalWidth; cameraData.intermediateHeight = data.finalHeight; cameraData.finalWidth = data.finalWidth; cameraData.finalHeight = data.finalHeight; cameraData.viewCount = 1; cameraData.enableExposureControl = data.commonData.enableExposureControl; cameraData.lowResolution = false; cameraData.enableIntegration = false; UpdateShaderVariableslClouds(ref data.commonData.cloudsCB, hdCamera, settings, cameraData, cloudModelData, false); int skyResolution = (int)m_Asset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize; data.intermediateLightingBuffer0 = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateLightingBufferDesc()); data.intermediateDepthBuffer = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateDepthBufferDesc()); if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal) { data.intermediateLightingBuffer1 = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateLightingBufferDesc()); data.output = builder.ReadWriteTexture(output); } else { data.output = builder.WriteTexture(output); } data.maxZMask = builder.ReadTexture(renderGraph.defaultResources.blackTextureXR); data.ambientProbeBuffer = builder.ReadComputeBuffer(renderGraph.ImportComputeBuffer(m_CloudsProbeBuffer)); }