Ejemplo n.º 1
0
        public override void AddRenderPasses(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, ref UnityEngine.Rendering.Universal.RenderingData renderingData)
        {
            if (renderingData.cameraData.camera.cameraType == CameraType.Preview)
            {
                return;
            }

            myCam = renderingData.cameraData.camera;

            if (EnviroSky.instance != null && EnviroSky.instance.useFog && EnviroSky.instance.PlayerCamera != null)
            {
                var src  = renderer.cameraColorTarget;
                var dest = UnityEngine.Rendering.Universal.RenderTargetHandle.CameraTarget;

                if (renderingData.cameraData.isSceneViewCamera && !EnviroSky.instance.showFogInEditor)
                {
                    return;
                }

                UpdateMatrix();

                RenderFog();

                if (blitPass == null)
                {
                    Create();
                }

                blitPass.Setup(src, dest);

                renderer.EnqueuePass(blitPass);
            }
        }
Ejemplo n.º 2
0
        public override void AddRenderPasses(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, ref UnityEngine.Rendering.Universal.RenderingData renderingData)
        {
            if (renderingData.cameraData.camera.cameraType == CameraType.Preview)
            {
                return;
            }

            myCam = renderingData.cameraData.camera;

            if (EnviroSkyLite.instance != null && EnviroSkyLite.instance.usePostEffectFog)
            {
                var src  = renderer.cameraColorTarget;
                var dest = UnityEngine.Rendering.Universal.RenderTargetHandle.CameraTarget;

                if (!renderingData.cameraData.isSceneViewCamera && renderingData.cameraData.camera == EnviroSkyLite.instance.PlayerCamera)
                {
                    UpdateMatrix();

                    if (currentSimpleFog != EnviroSkyLite.instance.fogSettings.useSimpleFog)
                    {
                        CreateFogMaterial();
                        blitPass         = new EnviroBlitPass(UnityEngine.Rendering.Universal.RenderPassEvent.BeforeRenderingTransparents, material, 0, name);
                        currentSimpleFog = EnviroSkyLite.instance.fogSettings.useSimpleFog;
                    }

                    RenderFog();

                    if (blitPass == null)
                    {
                        Create();
                    }

                    blitPass.Setup(src, dest);

                    renderer.EnqueuePass(blitPass);
                }
            }
        }
Ejemplo n.º 3
0
        public override void AddRenderPasses(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, ref UnityEngine.Rendering.Universal.RenderingData renderingData)
        {
            if (EnviroSkyMgr.instance != null && EnviroSky.instance != null && EnviroSkyMgr.instance.useVolumeClouds && EnviroSky.instance.PlayerCamera != null)
            {
                if (renderingData.cameraData.camera.cameraType == CameraType.Preview)
                {
                    return;
                }

                myCam = renderingData.cameraData.camera;

                var src  = renderer.cameraColorTarget;
                var dest = UnityEngine.Rendering.Universal.RenderTargetHandle.CameraTarget;

                if (currentReprojectionPixelSize != EnviroSky.instance.cloudsSettings.cloudsQualitySettings.reprojectionPixelSize)
                {
                    currentReprojectionPixelSize = EnviroSky.instance.cloudsSettings.cloudsQualitySettings.reprojectionPixelSize;
                    SetReprojectionPixelSize(EnviroSky.instance.cloudsSettings.cloudsQualitySettings.reprojectionPixelSize);
                }

                if (renderingData.cameraData.isSceneViewCamera && !EnviroSky.instance.showVolumeCloudsInEditor)
                {
                    return;
                }

                RenderVolumeClouds(renderingData.cameraData.cameraTargetDescriptor);

                if (blitPass == null)
                {
                    Create();
                }

                blitPass.Setup(src, dest);

                renderer.EnqueuePass(blitPass);
            }
        }
Ejemplo n.º 4
0
        void RenderLightShaft(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, RenderTexture source, RenderTargetIdentifier src, UnityEngine.Rendering.Universal.RenderTargetHandle destination, Material mat, Material clearMat, Transform lightSource, Color treshold, Color clr)
        {
            int divider = 4;

            if (EnviroSkyMgr.instance.LightShaftsSettings.resolution == EnviroPostProcessing.SunShaftsResolution.Normal)
            {
                divider = 2;
            }
            else if (EnviroSkyMgr.instance.LightShaftsSettings.resolution == EnviroPostProcessing.SunShaftsResolution.High)
            {
                divider = 1;
            }

            Vector3 v = Vector3.one * 0.5f;

            if (lightSource)
            {
                v = myCam.WorldToViewportPoint(lightSource.position);
            }
            else
            {
                v = new Vector3(0.5f, 0.5f, 0.0f);
            }

            int rtW = source.width / divider;
            int rtH = source.height / divider;

            RenderTextureDescriptor textureDescriptor = source.descriptor;

            textureDescriptor.width  = rtW;
            textureDescriptor.height = rtH;

            RenderTexture lrColorB;
            RenderTexture lrDepthBuffer;

            // VR Usage
            lrDepthBuffer = RenderTexture.GetTemporary(textureDescriptor);

            // mask out everything except the skybox
            // we have 2 methods, one of which requires depth buffer support, the other one is just comparing images

            mat.SetVector("_BlurRadius4", new Vector4(1.0f, 1.0f, 0.0f, 0.0f) * EnviroSkyMgr.instance.LightShaftsSettings.blurRadius);
            mat.SetVector("_SunPosition", new Vector4(v.x, v.y, v.z, EnviroSkyMgr.instance.LightShaftsSettings.maxRadius));
            mat.SetVector("_SunThreshold", treshold);

            Graphics.Blit(source, lrDepthBuffer, mat, 2);

            // paint a small black small border to get rid of clamping problems
            if (myCam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Mono)
            {
                DrawBorder(lrDepthBuffer, clearMat);
            }

            // radial blur:

            radialBlurIterations = Mathf.Clamp(radialBlurIterations, 1, 4);

            float ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (1.0f / 768.0f);

            mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f));
            mat.SetVector("_SunPosition", new Vector4(v.x, v.y, v.z, EnviroSkyMgr.instance.LightShaftsSettings.maxRadius));

            for (int it2 = 0; it2 < radialBlurIterations; it2++)
            {
                // each iteration takes 2 * 6 samples
                // we update _BlurRadius each time to cheaply get a very smooth look

                // VR USAGE
                lrColorB = RenderTexture.GetTemporary(textureDescriptor);


                Graphics.Blit(lrDepthBuffer, lrColorB, mat, 1);
                RenderTexture.ReleaseTemporary(lrDepthBuffer);
                ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (((it2 * 2.0f + 1.0f) * 6.0f)) / 768.0f;
                mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f));
                // VR USAGE
                lrDepthBuffer = RenderTexture.GetTemporary(textureDescriptor);


                Graphics.Blit(lrColorB, lrDepthBuffer, mat, 1);
                RenderTexture.ReleaseTemporary(lrColorB);
                ofs = EnviroSkyMgr.instance.LightShaftsSettings.blurRadius * (((it2 * 2.0f + 2.0f) * 6.0f)) / 768.0f;
                mat.SetVector("_BlurRadius4", new Vector4(ofs, ofs, 0.0f, 0.0f));
            }

            // put together:

            if (v.z >= 0.0f)
            {
                mat.SetVector("_SunColor", new Vector4(clr.r, clr.g, clr.b, clr.a) * EnviroSkyMgr.instance.LightShaftsSettings.intensity);
            }
            else
            {
                mat.SetVector("_SunColor", Vector4.zero); // no backprojection !
            }
            mat.SetTexture("_ColorBuffer", lrDepthBuffer);

            //FINAL
            // Graphics.Blit(source, destination, mat, (EnviroSkyMgr.instance.LightShaftsSettings.screenBlendMode == EnviroPostProcessing.ShaftsScreenBlendMode.Screen) ? 0 : 4);

            blitPassFinal.Setup(src, destination);
            renderer.EnqueuePass(blitPassFinal);

            RenderTexture.ReleaseTemporary(lrDepthBuffer);
        }