示例#1
0
        protected virtual void RenderCamera(ScriptableRenderContext context, Camera camera)
        {
            var p = Matrix4x4.Perspective(30, 16.0f / 9, .3f, 1000);
            var v = new Vector4(.5f, .5f, 10, 1);

            camera.TryGetCullingParameters(out var cullingParameters);

            var cmd = CommandBufferPool.Get(camera.name);

            cmd.Clear();

            if (camera.cameraType == CameraType.SceneView)
            {
                ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
            }

            var cullResults = context.Cull(ref cullingParameters);

            var projectionMat         = camera.projectionMatrix;
            var jitteredProjectionMat = projectionMat;

            jitteredProjectionMat.m02 += (projectionJitter.Current.x * 2 - 1) / camera.pixelWidth;
            jitteredProjectionMat.m12 += (projectionJitter.Current.x * 2 - 1) / camera.pixelHeight;

            var renderingData = new RenderingData()
            {
                camera                   = camera,
                cullResults              = cullResults,
                ColorTarget              = BuiltinRenderTextureType.CameraTarget,
                DepthTarget              = BuiltinRenderTextureType.CameraTarget,
                ColorBufferFormat        = RenderTextureFormat.Default,
                shadowMapData            = new Dictionary <Light, ShadowMapData>(),
                FrameID                  = frameID,
                DiscardFrameBuffer       = true,
                ViewMatrix               = camera.worldToCameraMatrix,
                ProjectionMatrix         = projectionMat,
                JitteredProjectionMatrix = jitteredProjectionMat,
                ProjectionJitter         = new Vector2(.5f, .5f),
                NextProjectionJitter     = new Vector2(.5f, .5f),
            };

            this.Setup(context, ref renderingData);
            context.SetupCameraProperties(camera, false);

            InitRenderQueue(camera);
            SetupLight(ref renderingData);

            /*RenderTargetBinding binding = new RenderTargetBinding();
             * binding.colorRenderTargets = new RenderTargetIdentifier[] { ColorTarget };
             * binding.colorLoadActions = new RenderBufferLoadAction[] { RenderBufferLoadAction.Clear };
             * binding.depthRenderTarget = DepthTarget;
             * binding.depthLoadAction = RenderBufferLoadAction.Clear;
             * binding.colorStoreActions = new RenderBufferStoreAction[] { RenderBufferStoreAction.Store };
             * binding.depthStoreAction = RenderBufferStoreAction.Store;*/
            cmd.SetRenderTarget(ColorTarget, DepthTarget);
            cmd.ClearRenderTarget(true, true, Color.black, 1);
            cmd.SetRenderTarget(DepthTarget, DepthTarget);
            cmd.ClearRenderTarget(true, true, Color.black, 1);
            cmd.SetRenderTarget(ColorTarget, DepthTarget);
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            context.DrawSkybox(camera);

            foreach (var pass in RenderPassQueue)
            {
                pass.Setup(context, ref renderingData);
                pass.Render(context, ref renderingData);
            }

            // Draw global user passes
            foreach (var pass in globalUserPasses)
            {
                pass.Setup(context, ref renderingData);
                pass.Render(context, ref renderingData);
            }

            // Draw user passes
            var userPasses = camera.GetComponents <UserPass>();

            foreach (var pass in userPasses)
            {
                if (pass.Global)
                {
                    continue;
                }
                pass.Setup(context, ref renderingData);
                pass.Render(context, ref renderingData);
            }

            cmd.Blit(renderingData.ColorTarget, BuiltinRenderTextureType.CameraTarget);
            //cmd.CopyTexture(renderingData.DepthTarget, BuiltinRenderTextureType.CameraTarget);
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();

            if (camera.cameraType == CameraType.SceneView)
            {
                context.DrawGizmos(camera, GizmoSubset.PreImageEffects);
                context.DrawGizmos(camera, GizmoSubset.PostImageEffects);
            }

            foreach (var pass in RenderPassQueue)
            {
                pass.Cleanup(context, ref renderingData);
            }
            foreach (var pass in globalUserPasses)
            {
                pass.Cleanup(context, ref renderingData);
            }
            foreach (var pass in userPasses)
            {
                pass.Cleanup(context, ref renderingData);
            }


            this.Cleanup(context, ref renderingData);

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();

            projectionJitter.Next = renderingData.NextProjectionJitter;
        }
示例#2
0
 void SetupLight(ref RenderingData renderingData)
 {
     renderingData.lights = renderingData.cullResults.visibleLights;
 }