public void Setup(FluidRenderingUtils.FluidRendererSettings settings, FluidRenderingUtils.FluidRenderTargets renderTargets, ObiParticleRenderer[] renderers) { // Copy settings; this.settings = settings; this.renderTargets = renderTargets; this.renderers = renderers; if (thickness_Material == null) { thickness_Material = FluidRenderingUtils.CreateMaterial(Shader.Find("Hidden/FluidThickness")); } if (color_Material == null) { color_Material = FluidRenderingUtils.CreateMaterial(Shader.Find("Obi/Fluid/Colors/FluidColorsBlend")); } bool shadersSupported = thickness_Material && color_Material; if (!shadersSupported || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { Debug.LogWarning("Obi Fluid Renderer not supported in this platform."); return; } }
public void Setup(FluidRenderingUtils.FluidRendererSettings settings, FluidRenderingUtils.FluidRenderTargets renderTargets, ObiParticleRenderer[] renderers) { // Copy settings; this.settings = settings; this.renderTargets = renderTargets; this.renderers = renderers; if (depth_BlurMaterial == null) { depth_BlurMaterial = FluidRenderingUtils.CreateMaterial(Shader.Find("Hidden/ScreenSpaceCurvatureFlow")); } if (normal_ReconstructMaterial == null) { normal_ReconstructMaterial = FluidRenderingUtils.CreateMaterial(Shader.Find("Hidden/NormalReconstruction")); } bool shadersSupported = depth_BlurMaterial && normal_ReconstructMaterial; if (!shadersSupported || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { Debug.LogWarning("Obi Fluid Renderer not supported in this platform."); return; } }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (color_Material == null) { return; } color_Material.SetInt("_BlendSrc", (int)settings.particleBlendSource); color_Material.SetInt("_BlendDst", (int)settings.particleBlendDestination); color_Material.SetInt("_ZWrite", settings.particleZWrite ? 1 : 0); CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag); using (new ProfilingScope(cmd, m_Thickness_Profile)) { // generate color / thickness buffer: FluidRenderingUtils.VolumeReconstruction(cmd, renderTargets, thickness_Material, color_Material, renderers); Blit(cmd, renderTargets.thickness1, renderTargets.thickness2, thickness_Material, 1); Blit(cmd, renderTargets.thickness2, renderTargets.thickness1, thickness_Material, 2); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (colorMaterial != null && fluidMaterial != null) { float blurScale = FluidRenderingUtils.SetupFluidCamera(renderingData.cameraData.camera); depth_BlurMaterial.SetFloat("_BlurScale", blurScale); depth_BlurMaterial.SetFloat("_BlurRadiusWorldspace", blurRadius); if (fluidMaterial != null) { fluidMaterial.SetFloat("_ThicknessCutoff", thicknessCutoff); } CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag); using (new ProfilingSample(cmd, k_RenderGrabPassTag)) { ObiParticleRenderer[] particleRenderers = GameObject.FindObjectsOfType <ObiParticleRenderer>(); FluidRenderingUtils.SetupCommandBuffer(cmd, target, renderTargets, depth_BlurMaterial, normal_ReconstructMaterial, thickness_Material, colorMaterial, fluidMaterial, particleRenderers); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } }
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); }
public void Setup(FluidRenderingUtils.FluidRendererSettings settings, FluidRenderingUtils.FluidRenderTargets renderTargets) { // Copy settings; this.settings = settings; this.renderTargets = renderTargets; if (fluid_Material == null) { fluid_Material = FluidRenderingUtils.CreateMaterial(Shader.Find("Obi/URP/Fluid/FluidShading")); } bool shadersSupported = fluid_Material; if (!shadersSupported || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat) || !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { Debug.LogWarning("Obi Fluid Renderer not supported in this platform."); return; } }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (depth_BlurMaterial == null || normal_ReconstructMaterial == null) { return; } float blurScale = FluidRenderingUtils.SetupFluidCamera(renderingData.cameraData.camera); depth_BlurMaterial.SetFloat("_BlurScale", blurScale); depth_BlurMaterial.SetFloat("_BlurRadiusWorldspace", settings.blurRadius); CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag); using (new ProfilingSample(cmd, k_RenderGrabPassTag)) { // surface reconstruction and dependant effects (lighting/reflection/refraction/foam) if (settings.generateSurface) { // normals/depth buffers: FluidRenderingUtils.SurfaceReconstruction(cmd, renderTargets, depth_BlurMaterial, normal_ReconstructMaterial, renderers); // blur fluid surface / reconstruct normals from smoothed depth: cmd.Blit(renderTargets.depth, renderTargets.smoothDepth, depth_BlurMaterial); cmd.Blit(renderTargets.smoothDepth, renderTargets.normals, normal_ReconstructMaterial); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
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); }