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 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(RenderTargetIdentifier colorSource, Material colorMaterial, Material fluidMaterial, float blurRadius, float thicknessCutoff)
        {
            // Copy settings;
            this.colorMaterial   = colorMaterial;
            this.fluidMaterial   = fluidMaterial;
            this.blurRadius      = blurRadius;
            this.thicknessCutoff = thicknessCutoff;

            // Setup render targets:
            target                    = colorSource;
            renderTargets             = new FluidRenderingUtils.FluidRenderTargets();
            renderTargets.refraction  = Shader.PropertyToID("_Refraction");
            renderTargets.foam        = Shader.PropertyToID("_Foam");
            renderTargets.depth       = Shader.PropertyToID("_FluidDepthTexture");
            renderTargets.thickness1  = Shader.PropertyToID("_FluidThickness1");
            renderTargets.thickness2  = Shader.PropertyToID("_FluidThickness2");
            renderTargets.smoothDepth = Shader.PropertyToID("_FluidSurface");
            renderTargets.normals     = Shader.PropertyToID("_FluidNormals");

            depth_BlurMaterial         = CreateMaterial(Shader.Find("Hidden/ScreenSpaceCurvatureFlow"));
            normal_ReconstructMaterial = CreateMaterial(Shader.Find("Hidden/NormalReconstruction"));
            thickness_Material         = CreateMaterial(Shader.Find("Hidden/FluidThickness"));

            bool shadersSupported = depth_BlurMaterial && normal_ReconstructMaterial && thickness_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 (!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)
        {
            // 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 Create()
        {
            renderTargets             = new FluidRenderingUtils.FluidRenderTargets();
            renderTargets.foam        = Shader.PropertyToID("_Foam");
            renderTargets.depth       = Shader.PropertyToID("_FluidDepthTexture");
            renderTargets.thickness1  = Shader.PropertyToID("_FluidThickness1");
            renderTargets.thickness2  = Shader.PropertyToID("_FluidThickness2");
            renderTargets.smoothDepth = Shader.PropertyToID("_FluidSurface"); //smoothed depth
            renderTargets.normals     = Shader.PropertyToID("_FluidNormals");

            m_ThicknessPass = new ThicknessBufferPass();
            m_ThicknessPass.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents + 1;

            m_SurfacePass = new SurfaceReconstruction();
            m_SurfacePass.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents + 1;

            m_FoamPass = new FoamPass();
            m_FoamPass.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents + 1;

            m_RenderFluidPass = new RenderFluidPass(RenderTargetHandle.CameraTarget);
            m_RenderFluidPass.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents + 1;
        }
Exemple #7
0
        protected override void Setup()
        {
            GetComponent <Camera>().depthTextureMode |= DepthTextureMode.Depth;

            if (depth_BlurMaterial == null)
            {
                depth_BlurMaterial = CreateMaterial(Shader.Find("Hidden/ScreenSpaceCurvatureFlow"));
            }

            if (normal_ReconstructMaterial == null)
            {
                normal_ReconstructMaterial = CreateMaterial(Shader.Find("Hidden/NormalReconstruction"));
            }

            if (thickness_Material == null)
            {
                thickness_Material = CreateMaterial(Shader.Find("Hidden/FluidThickness"));
            }

            if (color_Material == null)
            {
                color_Material = CreateMaterial(Shader.Find("Obi/Fluid/Colors/FluidColorsBlend"));
            }

            if (fluid_Material == null)
            {
                fluid_Material = CreateMaterial(Shader.Find("Obi/Fluid/FluidShading"));
            }

            bool shadersSupported = depth_BlurMaterial && normal_ReconstructMaterial && thickness_Material && color_Material && fluid_Material;

            if (!shadersSupported ||
                !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth) ||
                !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat) ||
                !SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)
                )
            {
                enabled = false;
                Debug.LogWarning("Obi Fluid Renderer not supported in this platform.");
                return;
            }

            renderTargets             = new FluidRenderingUtils.FluidRenderTargets();
            renderTargets.refraction  = Shader.PropertyToID("_Refraction");
            renderTargets.foam        = Shader.PropertyToID("_Foam");
            renderTargets.depth       = Shader.PropertyToID("_FluidDepthTexture");
            renderTargets.thickness1  = Shader.PropertyToID("_FluidThickness1");
            renderTargets.thickness2  = Shader.PropertyToID("_FluidThickness2");
            renderTargets.smoothDepth = Shader.PropertyToID("_FluidSurface"); //smoothed depth
            renderTargets.normals     = Shader.PropertyToID("_FluidNormals");

            Shader.SetGlobalMatrix("_Camera_to_World", currentCam.cameraToWorldMatrix);
            Shader.SetGlobalMatrix("_World_to_Camera", currentCam.worldToCameraMatrix);
            Shader.SetGlobalMatrix("_InvProj", currentCam.projectionMatrix.inverse);

            float fovY = currentCam.fieldOfView;
            float far  = currentCam.farClipPlane;
            float y    = currentCam.orthographic ? 2 * currentCam.orthographicSize: 2 * Mathf.Tan(fovY * Mathf.Deg2Rad * 0.5f) * far;
            float x    = y * currentCam.aspect;

            Shader.SetGlobalVector("_FarCorner", new Vector3(x, y, far));

            depth_BlurMaterial.SetFloat("_BlurScale", currentCam.orthographic ? 1 : currentCam.pixelWidth / currentCam.aspect * (1.0f / Mathf.Tan(fovY * Mathf.Deg2Rad * 0.5f)));
            depth_BlurMaterial.SetFloat("_BlurRadiusWorldspace", settings.blurRadius);
        }