Ejemplo n.º 1
0
 public CustomRenderPipelineInstance(PostProcessingSettings postProcessingSettings)
 {
     this.postProcessingSettings = postProcessingSettings;
 }
Ejemplo n.º 2
0
        protected override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            HashSet <Camera> subCameras = new HashSet <Camera>();

            foreach (Camera camera in cameras)
            {
                CameraStack stack = camera.GetComponent <CameraStack>();
                if (stack != null)
                {
                    subCameras.Add(stack.SecondaryCamera);
                    subCameras.Add(stack.TertiaryCamera);
                }
            }

            foreach (Camera camera in cameras)
            {
                if (subCameras.Contains(camera))
                {
                    continue;
                }

                PostProcessingSettings postProcessingSettings = this.postProcessingSettings;
#if UNITY_EDITOR
                if (camera.cameraType > CameraType.SceneView)
                {
                    postProcessingSettings = null;
                }
                if (camera.cameraType == CameraType.SceneView && !SceneView.currentDrawingSceneView.sceneViewState.showImageEffects)
                {
                    postProcessingSettings = null;
                }
#endif
                if (camera.cameraType == CameraType.Game && Camera.main != camera)
                {
                    postProcessingSettings = null;
                }

                CommandBuffer buffer = new CommandBuffer()
                {
                    name = camera.name
                };

                // buffer.GetTemporaryRT(cameraColorTextureId, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.Default);
                buffer.GetTemporaryRT(cameraColorTexture1Id, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.Default);
                buffer.GetTemporaryRT(cameraColorTexture2Id, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.Default);
                buffer.GetTemporaryRT(cameraDepthTextureId, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
                buffer.GetTemporaryRT(cameraDepthTexture1Id, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
                buffer.GetTemporaryRT(cameraDepthTexture2Id, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
                buffer.GetTemporaryRT(cameraDepthTexture3Id, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
                context.ExecuteCommandBuffer(buffer);
                buffer.Clear();

                ClearFlag clearFlag = GetClearFlag(camera.clearFlags);
                if (clearFlag != ClearFlag.None)
                {
                    buffer.SetRenderTarget(
                        cameraColorTexture1Id, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
                        cameraDepthTextureId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store
                        );
                    buffer.ClearRenderTarget(
                        (clearFlag & ClearFlag.Depth) != 0,
                        (clearFlag & ClearFlag.Color) != 0,
                        (clearFlag & ClearFlag.Color) != 0 ? camera.backgroundColor : Color.clear,
                        1.0f
                        );
                }
                context.ExecuteCommandBuffer(buffer);
                buffer.Clear();

                CameraStack stack = camera.GetComponent <CameraStack>();
                if (stack != null)
                {
                    CameraRenderer.Render(context, stack.TertiaryCamera, ClearFlag.Depth, cameraColorTexture1Id, cameraDepthTexture3Id);
                    CameraRenderer.Render(context, stack.SecondaryCamera, ClearFlag.Depth, cameraColorTexture1Id, cameraDepthTexture2Id);
                }
                CameraRenderer.Render(context, camera, ClearFlag.Depth, cameraColorTexture1Id, stack != null ? cameraDepthTexture1Id : cameraDepthTextureId);

                context.SetupCameraProperties(camera);
                if (stack != null)
                {
                    PostProcessing.SetMultipleZBufferParams(buffer, camera, stack.SecondaryCamera, stack.TertiaryCamera);
                    buffer.EnableShaderKeyword(multipleDepthTexturesId);
                }
                else
                {
                    buffer.DisableShaderKeyword(multipleDepthTexturesId);
                }
                // PostProcessing.Render(buffer, cameraColorTextureId, cameraDepthTextureId, BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget, postProcessingSettings);
                PostProcessing.RenderOceanPass(buffer, cameraColorTexture1Id, cameraDepthTextureId, cameraColorTexture2Id, BuiltinRenderTextureType.CameraTarget, postProcessingSettings);
                PostProcessing.RenderAtmospherePass(buffer, cameraColorTexture2Id, cameraDepthTextureId, cameraColorTexture1Id, BuiltinRenderTextureType.CameraTarget, postProcessingSettings);
                PostProcessing.Blit(buffer, cameraColorTexture1Id, cameraDepthTextureId, BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget);
                context.ExecuteCommandBuffer(buffer);
                buffer.Clear();
                context.Submit();

                // buffer.ReleaseTemporaryRT(cameraColorTextureId);
                buffer.ReleaseTemporaryRT(cameraColorTexture1Id);
                buffer.ReleaseTemporaryRT(cameraColorTexture2Id);
                buffer.ReleaseTemporaryRT(cameraDepthTextureId);
                buffer.ReleaseTemporaryRT(cameraDepthTexture1Id);
                buffer.ReleaseTemporaryRT(cameraDepthTexture2Id);
                buffer.ReleaseTemporaryRT(cameraDepthTexture3Id);
                context.ExecuteCommandBuffer(buffer);
                buffer.Release();
            }
        }
Ejemplo n.º 3
0
        public static void RenderAtmospherePass(CommandBuffer buffer, RenderTargetIdentifier colorSource, RenderTargetIdentifier depthSource, RenderTargetIdentifier colorTarget, RenderTargetIdentifier depthTarget, PostProcessingSettings postProcessingSettings)
        {
            if (postProcessingSettings == null)
            {
                return;
            }

            // TODO: manage 1 or 3 depth textures.
            buffer.SetGlobalTexture(cameraColorTextureId, colorSource);
            buffer.SetGlobalTexture(cameraDepthTextureId, depthSource);
            buffer.SetRenderTarget(
                colorTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
                depthTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store
                );
            DoAtmospherePass(buffer, postProcessingSettings.AtmosphereSettings);
        }