Example #1
0
        static void TraceVolumetricClouds_Sky_Low(CommandBuffer cmd, VolumetricCloudsSkyLowPassData passData, MaterialPropertyBlock mpb)
        {
            // Compute the number of tiles to evaluate
            int traceTX = (passData.traceWidth + (8 - 1)) / 8;
            int traceTY = (passData.traceHeight + (8 - 1)) / 8;

            // Bind the sampling textures
            BlueNoise.BindDitheredTextureSet(cmd, passData.commonData.ditheredTextureSet);

            // Bind the constant buffer
            ConstantBuffer.Push(cmd, passData.commonData.cloudsCB, passData.commonData.volumetricCloudsCS, HDShaderIDs._ShaderVariablesClouds);

            CoreUtils.SetKeyword(cmd, "LOCAL_VOLUMETRIC_CLOUDS", false);

            // 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.intermediateLightingBuffer);
            cmd.SetComputeTextureParam(passData.commonData.volumetricCloudsCS, passData.renderKernel, HDShaderIDs._CloudsDepthTextureRW, passData.intermediateDepthBuffer);

            cmd.DispatchCompute(passData.commonData.volumetricCloudsCS, passData.renderKernel, traceTX, traceTY, 1);
            CoreUtils.SetKeyword(cmd, "PHYSICALLY_BASED_SUN", false);

            mpb.SetTexture(HDShaderIDs._VolumetricCloudsUpscaleTextureRW, passData.intermediateLightingBuffer);
            CoreUtils.SetRenderTarget(cmd, passData.output, ClearFlag.None, miplevel: 2, cubemapFace: passData.cubemapFace);
            CoreUtils.DrawFullScreen(cmd, passData.cloudCombinePass, mpb, 3);
        }
Example #2
0
        void PrepareVolumetricCloudsSkyLowPassData(RenderGraph renderGraph, RenderGraphBuilder builder, HDCamera hdCamera, int width, int height, Matrix4x4[] pixelCoordToViewDir, CubemapFace cubemapFace, VolumetricClouds settings, VolumetricCloudsSkyLowPassData data)
        {
            // Compute the cloud model data
            CloudModelData cloudModelData = GetCloudModelData(settings);

            // Fill the common data
            FillVolumetricCloudsCommonData(false, settings, TVolumetricCloudsCameraType.Sky, in cloudModelData, ref data.commonData);

            // We need to make sure that the allocated size of the history buffers and the dispatch size are perfectly equal.
            // The ideal approach would be to have a function for that returns the converted size from a viewport and texture size.
            // but for now we do it like this.
            // Final resolution at which the effect should be exported
            data.finalWidth  = width;
            data.finalHeight = height;
            // Intermediate resolution at which the effect is accumulated
            data.intermediateWidth  = Mathf.RoundToInt(0.5f * width);
            data.intermediateHeight = Mathf.RoundToInt(0.5f * height);
            // Resolution at which the effect is traced
            data.traceWidth  = Mathf.RoundToInt(0.25f * width);
            data.traceHeight = Mathf.RoundToInt(0.25f * height);

            // Sky
            data.cubemapFace      = cubemapFace;
            data.cloudCombinePass = m_CloudCombinePass;

            // Kernels
            data.renderKernel       = m_CloudRenderKernel;
            data.preUpscaleKernel   = m_PreUpscaleCloudsSkyKernel;
            data.finalUpscaleKernel = m_UpscaleAndCombineCloudsSkyKernel;

            data.pixelCoordToViewDir = pixelCoordToViewDir;

            // Update the constant buffer
            VolumetricCloudsCameraData cameraData;

            cameraData.cameraType            = data.commonData.cameraType;
            cameraData.traceWidth            = data.traceWidth;
            cameraData.traceHeight           = data.traceHeight;
            cameraData.intermediateWidth     = data.intermediateWidth;
            cameraData.intermediateHeight    = data.intermediateHeight;
            cameraData.finalWidth            = data.finalWidth;
            cameraData.finalHeight           = data.finalHeight;
            cameraData.viewCount             = 1;
            cameraData.enableExposureControl = data.commonData.enableExposureControl;
            cameraData.lowResolution         = true;
            cameraData.enableIntegration     = false;
            UpdateShaderVariableslClouds(ref data.commonData.cloudsCB, hdCamera, settings, cameraData, cloudModelData, false);

            int skyResolution = (int)m_Asset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize;

            data.intermediateLightingBuffer = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateLightingBufferDesc());
            data.intermediateDepthBuffer    = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateDepthBufferDesc());
            data.output             = builder.WriteTexture(renderGraph.CreateTexture(GetVolumetricCloudsIntermediateCubeTextureDesc()));
            data.maxZMask           = builder.ReadTexture(renderGraph.defaultResources.blackTextureXR);
            data.ambientProbeBuffer = builder.ReadComputeBuffer(renderGraph.ImportComputeBuffer(m_CloudsProbeBuffer));
        }