public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag);

            using (new ProfilingScope(cmd, m_Thickness_Profile))
            {
                // TODO: DrawRenderer does not seem to work in URP, so switch to DrawRenderers().
                FluidRenderingUtils.Foam(cmd, renderTargets, renderers);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
Exemple #2
0
        public override void UpdateFluidRenderingCommandBuffer()
        {
            renderFluid.Clear();

            if (particleRenderers == null || fluid_Material == null || color_Material == null)
            {
                return;
            }

            fluid_Material.SetInt("_BlendSrc", (int)settings.blendSource);
            fluid_Material.SetInt("_BlendDst", (int)settings.blendDestination);
            fluid_Material.SetFloat("_ThicknessCutoff", settings.thicknessCutoff);

            color_Material.SetInt("_BlendSrc", (int)settings.particleBlendSource);
            color_Material.SetInt("_BlendDst", (int)settings.particleBlendDestination);
            color_Material.SetInt("_ZWrite", settings.particleZWrite?1:0);

            // generate color / thickness buffer:
            renderFluid.GetTemporaryRT(renderTargets.thickness1, -settings.thicknessDownsample, -settings.thicknessDownsample, 16, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);
            renderFluid.GetTemporaryRT(renderTargets.thickness2, -settings.thicknessDownsample, -settings.thicknessDownsample, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

            renderFluid.SetRenderTarget(renderTargets.thickness1);
            renderFluid.ClearRenderTarget(true, true, FluidRenderingUtils.thicknessBufferClear);

            FluidRenderingUtils.VolumeReconstruction(renderFluid,
                                                     renderTargets,
                                                     thickness_Material,
                                                     color_Material,
                                                     particleRenderers);

            renderFluid.Blit(renderTargets.thickness1, renderTargets.thickness2, thickness_Material, 1);
            renderFluid.Blit(renderTargets.thickness2, renderTargets.thickness1, thickness_Material, 2);

            // surface reconstruction and dependant effects (lighting/reflection/refraction/foam)
            if (settings.generateSurface)
            {
                // normals/depth buffers:
                renderFluid.GetTemporaryRT(renderTargets.depth, -settings.surfaceDownsample, -settings.surfaceDownsample, 24, FilterMode.Point, RenderTextureFormat.Depth);
                renderFluid.GetTemporaryRT(renderTargets.smoothDepth, -settings.surfaceDownsample, -settings.surfaceDownsample, 0, FilterMode.Bilinear, RenderTextureFormat.RFloat);
                renderFluid.GetTemporaryRT(renderTargets.normals, -settings.surfaceDownsample, -settings.surfaceDownsample, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

                renderFluid.SetRenderTarget(renderTargets.depth);       // fluid depth
                renderFluid.ClearRenderTarget(true, true, Color.clear); //clear

                FluidRenderingUtils.SurfaceReconstruction(renderFluid,
                                                          renderTargets,
                                                          depth_BlurMaterial,
                                                          normal_ReconstructMaterial,
                                                          particleRenderers);

                // blur fluid surface / reconstruct normals from smoothed depth:
                renderFluid.Blit(renderTargets.depth, renderTargets.smoothDepth, depth_BlurMaterial);
                renderFluid.Blit(renderTargets.smoothDepth, renderTargets.normals, normal_ReconstructMaterial);

                fluid_Material.SetInt("_ZTest", (int)CompareFunction.LessEqual);

                if (settings.lighting)
                {
                    fluid_Material.EnableKeyword("FLUID_LIGHTING");
                    fluid_Material.SetFloat("_Smoothness", settings.smoothness);
                    fluid_Material.SetFloat("_AmbientMultiplier", settings.ambientMultiplier);
                }
                else
                {
                    fluid_Material.DisableKeyword("FLUID_LIGHTING");
                }

                if (settings.generateReflection)
                {
                    fluid_Material.EnableKeyword("FLUID_REFLECTION");
                    fluid_Material.SetFloat("_ReflectionCoeff", settings.reflection);
                    fluid_Material.SetFloat("_Metalness", settings.metalness);
                }
                else
                {
                    fluid_Material.DisableKeyword("FLUID_REFLECTION");
                }

                if (settings.generateRefraction)
                {
                    renderFluid.GetTemporaryRT(renderTargets.refraction, -settings.refractionDownsample, -settings.refractionDownsample, 0, FilterMode.Bilinear);
                    FluidRenderingUtils.Refraction(renderFluid, BuiltinRenderTextureType.CameraTarget, renderTargets);
                    fluid_Material.EnableKeyword("FLUID_REFRACTION");
                    fluid_Material.SetFloat("_Transparency", settings.transparency);
                    fluid_Material.SetFloat("_AbsorptionCoeff", settings.absorption);
                    fluid_Material.SetFloat("_RefractionCoeff", settings.refraction);
                }
                else
                {
                    fluid_Material.DisableKeyword("FLUID_REFRACTION");
                }
            }
            else
            {
                // no depth buffer, so always pass ztest.
                fluid_Material.SetInt("_ZTest", (int)CompareFunction.Always);

                fluid_Material.DisableKeyword("FLUID_LIGHTING");
                fluid_Material.DisableKeyword("FLUID_REFLECTION");
                fluid_Material.DisableKeyword("FLUID_REFRACTION");
            }

            if (settings.generateFoam)
            {
                renderFluid.GetTemporaryRT(renderTargets.foam, -settings.foamDownsample, -settings.foamDownsample, 0, FilterMode.Bilinear);

                renderFluid.SetRenderTarget(renderTargets.foam);
                renderFluid.ClearRenderTarget(true, true, Color.clear);

                FluidRenderingUtils.Foam(renderFluid, renderTargets, particleRenderers);
                fluid_Material.EnableKeyword("FLUID_FOAM");
            }
            else
            {
                fluid_Material.DisableKeyword("FLUID_FOAM");
            }

            // final pass (shading):
            renderFluid.Blit(renderTargets.thickness1, BuiltinRenderTextureType.CameraTarget, fluid_Material);
        }