コード例 #1
0
        protected override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            foreach (Camera camera in cameras)
            {
                //场景中绘制
                PrepareForSceneWindow(camera);
                //剔除
                if (!camera.TryGetCullingParameters(out var cullingParameters))
                {
                    continue;
                }
                cullingParameters.shadowDistance = Mathf.Min(renderSetting.shadowSetting.maxDistance, camera.farClipPlane);
                CullingResults cullResults = context.Cull(ref cullingParameters);

                //光照以及阴影设置
                HandleLights(cullResults);
                lighting.Render(context, camera, renderSetting, cullResults);
                shadow.Render(context, camera, renderSetting, cullResults);
                //设置当前相机为渲染目标(必须在光照设置之后?), 然后绘制场景物体

                context.SetupCameraProperties(camera);
                CameraClearFlags flags = camera.clearFlags;
                buffer.ClearRenderTarget(
                    flags <= CameraClearFlags.Depth,
                    flags == CameraClearFlags.Color,
                    flags == CameraClearFlags.Color ?
                    camera.backgroundColor.linear : Color.clear
                    );
                context.ExecuteCommandBuffer(buffer);
                buffer.Clear();

                context.SetupCameraProperties(camera);
                DrawVisibleGeometry(context, camera, cullResults);
                DrawUnsupportedShaders();
                //绘制Gizmos
                DrawGizmos(context, camera);

                context.ExecuteCommandBuffer(buffer);
                buffer.Clear();
                //提交
                context.Submit();
            }
        }
コード例 #2
0
    private void Setup()
    {
        context.SetupCameraProperties(camera);
        CameraClearFlags flags = camera.clearFlags;

        buffer.ClearRenderTarget(flags <= CameraClearFlags.Depth, flags == CameraClearFlags.Color,
                                 flags == CameraClearFlags.Color ? camera.backgroundColor.linear : Color.clear);
        buffer.BeginSample(SampleName);
        ExecuteBuffer();
    }
コード例 #3
0
    private void RenderMainCamera(ScriptableRenderContext renderContext, Camera camera)
    {
        renderContext.SetupCameraProperties(camera);
        _CB.ClearRenderTarget(true, true, Color.blue);
        _CB.DrawMesh(_fullscreen_plane.GetPlane(), Matrix4x4.identity, _fullscreen_material.GetMaterial());
        renderContext.ExecuteCommandBuffer(_CB);
        _CB.Clear();

        renderContext.Submit();
    }
コード例 #4
0
 public void Render(ScriptableRenderContext renderContext, Camera[] cameras)
 {
     foreach (var c in cameras)
     {
         renderContext.SetupCameraProperties(c);
         BufferCommand(renderContext, c);
         CullingAndDraw(renderContext, c);
         renderContext.Submit();
     }
 }
コード例 #5
0
    void Setup()
    {
        context.SetupCameraProperties(camera);

        buffer.ClearRenderTarget(true, true, Color.clear);

        buffer.BeginSample(bufferName);

        ExecuteBuffer();
    }
コード例 #6
0
        private void Setup(ShadowSettings shadowSettings)
        {
            renderContext.SetupCameraProperties(camera); // ?? this method must be called before excute commandbuffer, or clear command will call GL.Draw to clear
            CameraClearFlags cameraClearFlags = camera.clearFlags;

            commandBuffer.ClearRenderTarget(cameraClearFlags <= CameraClearFlags.Depth, cameraClearFlags == CameraClearFlags.Color, cameraClearFlags == CameraClearFlags.Color ?
                                            camera.backgroundColor.linear : Color.clear); // ?? tbdr resolve
            commandBuffer.BeginSample(commandBufferName);
            ExecuteCommandBuffer();
        }
コード例 #7
0
ファイル: SRP1003.cs プロジェクト: zhangximing/CustomSRP
    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        BeginFrameRendering(context,cameras);

        foreach (Camera camera in cameras)
        {
            BeginCameraRendering(context,camera);

            //Culling
            ScriptableCullingParameters cullingParams;
            if (!camera.TryGetCullingParameters(out cullingParams))
                continue;
            CullingResults cull = context.Cull(ref cullingParams);

            //Camera setup some builtin variables e.g. camera projection matrices etc
            context.SetupCameraProperties(camera);

            //Get the setting from camera component
            bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false;
            bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true;
            bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false;

            //Camera clear flag
            CommandBuffer cmd = new CommandBuffer();
            cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor);
            context.ExecuteCommandBuffer(cmd);
            cmd.Release();

            //Setup DrawSettings and FilterSettings
            var sortingSettings = new SortingSettings(camera);
            DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings);
            FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all);

            //Skybox
            if(drawSkyBox)  {  context.DrawSkybox(camera);  }

            //Opaque objects
            sortingSettings.criteria = SortingCriteria.CommonOpaque;
            drawSettings.sortingSettings = sortingSettings;
            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cull, ref drawSettings, ref filterSettings);

            //Transparent objects
            sortingSettings.criteria = SortingCriteria.CommonTransparent;
            drawSettings.sortingSettings = sortingSettings;
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            context.DrawRenderers(cull, ref drawSettings, ref filterSettings);

            context.Submit();

            EndCameraRendering(context,camera);
        }

        EndFrameRendering(context,cameras);
    }
コード例 #8
0
    void Render(ScriptableRenderContext renderContext, Camera camera)
    {
        //填充当前相机信息
        renderContext.SetupCameraProperties(camera);

        //设置渲染指令
        CameraClearFlags clearFlag = camera.clearFlags;

        clearBuffer.ClearRenderTarget(
            (clearFlag & CameraClearFlags.Depth) != 0,
            (clearFlag & CameraClearFlags.Color) != 0,
            camera.backgroundColor);

        renderContext.ExecuteCommandBuffer(clearBuffer);
        clearBuffer.Clear();

        //剔除
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))
        {
            return;
        }
#if UNITY_EDITOR
        if (camera.cameraType == CameraType.SceneView)
        {
            ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); //保证UI在SceneView显示
        }
#endif

        CullResults.Cull(ref cullingParameters, renderContext, ref cull);

        //绘制不透明物体
        DrawRendererSettings drawSetting = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));
        drawSetting.sorting.flags = SortFlags.CommonOpaque; //告诉渲染器从前向后渲染(减少overdraw)
        drawSetting.flags         = drawRendererFlags;      //开启动态合批
        FilterRenderersSettings filterSetting = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque //过滤出不透明shape
        };
        renderContext.DrawRenderers(cull.visibleRenderers, ref drawSetting, filterSetting);

        //绘制天空盒
        renderContext.DrawSkybox(camera);

        //绘制透明物体
        drawSetting.sorting.flags      = SortFlags.CommonTransparent;  //告诉渲染器从后向前渲染(做颜色叠加)
        filterSetting.renderQueueRange = RenderQueueRange.transparent; //过滤出透明shape
        renderContext.DrawRenderers(cull.visibleRenderers, ref drawSetting, filterSetting);

        DrawDefaultPipline(renderContext, camera);

        //执行缓冲区里面的命令
        renderContext.Submit();
    }
コード例 #9
0
    private void Render(ScriptableRenderContext context, Camera camera)
    {
        context.SetupCameraProperties(camera);



        var buffer = new CommandBuffer
        {
            name = camera.name
        };
        CameraClearFlags clearFlags = camera.clearFlags;

        buffer.BeginSample("Render Camera");

        //
        buffer.ClearRenderTarget(
            (clearFlags & CameraClearFlags.Depth) != 0,
            (clearFlags & CameraClearFlags.Color) != 0,
            camera.backgroundColor);
        //uffer.ClearRenderTarget(true,true,Color.clear);



        if (!camera.TryGetCullingParameters(out var cullingParameters))
        {
            return;
        }

        buffer.BeginSample("RenderLoop.Draw");
        var cullingResults = context.Cull(ref cullingParameters);

        lighting.Setup(context, cullingResults); //设置光源数据

        var drawingSettings = new DrawingSettings(_unlitShaderTagId, new SortingSettings(camera));

        drawingSettings.SetShaderPassName(1, _litShaderTagId);

        var filteringSettings = new FilteringSettings(RenderQueueRange.opaque);

        context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
        buffer.EndSample("RenderLoop.Draw");

        context.DrawSkybox(camera);

        buffer.BeginSample("RenderLoop.Draw");
        filteringSettings = new FilteringSettings(RenderQueueRange.transparent);
        context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
        buffer.EndSample("RenderLoop.Draw");

        buffer.EndSample("Render Camera");
        context.ExecuteCommandBuffer(buffer);
        buffer.Release();

        context.Submit();
    }
コード例 #10
0
        private void Render(PipelineCamera pipelineCam, RenderTargetIdentifier dest, ref ScriptableRenderContext context, Camera cam, bool *pipelineChecked)
        {
            PipelineResources.CameraRenderingPath path = pipelineCam.renderingPath;
            pipelineCam.cam = cam;
            pipelineCam.EnableThis();
            if (!CullResults.GetCullingParameters(cam, out data.cullParams))
            {
                return;
            }
            context.SetupCameraProperties(cam);
            //Set Global Data
            data.context     = context;
            data.cullResults = CullResults.Cull(ref data.cullParams, context);
            data.resources   = resources;
            PipelineFunctions.GetViewProjectMatrix(cam, out data.vp, out data.inverseVP);
            for (int i = 0; i < data.frustumPlanes.Length; ++i)
            {
                Plane p = data.cullParams.GetCullingPlane(i);
                //GPU Driven RP's frustum plane is inverse from SRP's frustum plane
                data.frustumPlanes[i] = new Vector4(-p.normal.x, -p.normal.y, -p.normal.z, -p.distance);
            }
            var allEvents = resources.renderingPaths;
            var collect   = allEvents[pipelineCam.renderingPath];

#if UNITY_EDITOR
            //Need only check for Unity Editor's bug!
            if (!pipelineChecked[(int)pipelineCam.renderingPath])
            {
                pipelineChecked[(int)pipelineCam.renderingPath] = true;
                foreach (var e in collect)
                {
                    if (!e.CheckProperty())
                    {
                        e.InitEvent(resources);
                    }
                }
            }
#endif
            foreach (var e in collect)
            {
                if (e.Enabled)
                {
                    e.PreRenderFrame(pipelineCam, ref data);
                }
            }
            JobHandle.ScheduleBatchedJobs();
            foreach (var e in collect)
            {
                if (e.Enabled)
                {
                    e.FrameUpdate(pipelineCam, ref data);
                }
            }
        }
コード例 #11
0
        private void Setup(ScriptableRenderContext context, Camera camera)
        {
            // 设置渲染相关的相机参数,包含相机的各个矩阵和剪裁平面等。
            context.SetupCameraProperties(camera);
            CameraClearFlags flags = camera.clearFlags;

            cameraBuffer.ClearRenderTarget(flags <= CameraClearFlags.Depth, flags == CameraClearFlags.Color, flags == CameraClearFlags.Color ? camera.backgroundColor.linear : Color.clear);
            cameraBuffer.BeginSample(SampleName);
            CoreUtils.SetKeyword(cameraBuffer, SRPBatchingKeyword, GraphicsSettings.useScriptableRenderPipelineBatching);
            ExecuteBuffer(context, camera);
        }
コード例 #12
0
    void Render(ScriptableRenderContext context, Camera camera)
    {
        ScriptableCullingParameters scriptableCullingParameters;

        if (!camera.TryGetCullingParameters(out scriptableCullingParameters))
        {
            return;
        }

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

        BeginCameraRendering(context, camera);
        _cullingResults = context.Cull(ref scriptableCullingParameters);

        context.SetupCameraProperties(camera);

        CameraClearFlags clearFlags = camera.clearFlags;
        cameraBuffer.ClearRenderTarget((clearFlags & CameraClearFlags.Depth) != 0,
                                       (clearFlags & CameraClearFlags.Color) != 0, camera.backgroundColor);

        cameraBuffer.BeginSample("Render Camera");
        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear();

        SortingSettings sortingSettings = new SortingSettings();
        sortingSettings.criteria = SortingCriteria.CommonOpaque;
        DrawingSettings drawingSettings = new DrawingSettings(new ShaderTagId("SRPDefaultUnlit"), sortingSettings);
        drawingSettings.enableInstancing      = _instancing;
        drawingSettings.enableDynamicBatching = _dynamicBatching;

        FilteringSettings filteringSettings = FilteringSettings.defaultValue;
        filteringSettings.renderQueueRange = RenderQueueRange.opaque;

        context.DrawRenderers(_cullingResults, ref drawingSettings, ref filteringSettings);

        context.DrawSkybox(camera);

        sortingSettings.criteria           = SortingCriteria.CommonTransparent;
        filteringSettings.renderQueueRange = RenderQueueRange.transparent;
        context.DrawRenderers(_cullingResults, ref drawingSettings, ref filteringSettings);

        DrawDefaultPipeline(context, camera);

        cameraBuffer.EndSample("Render Camera");
        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear();

        EndCameraRendering(context, camera);
    }
コード例 #13
0
    private void Render(ScriptableRenderContext context, Camera camera)
    {
        context.SetupCameraProperties(camera);

        var filteringSettings = new FilteringSettings()
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        Clear(context, camera);
    }
コード例 #14
0
 protected override void Render(ScriptableRenderContext context, Camera[] cameras)
 {
     foreach (var camera in cameras)
     {
         context.SetupCameraProperties(camera);
         _cb.ClearRenderTarget(true, true, Color.blue);
         context.ExecuteCommandBuffer(_cb);
         _cb.Clear();
         context.Submit();
     }
 }
コード例 #15
0
        void Setup()
        {
            _context.SetupCameraProperties(_camera);
            var flags = _camera.clearFlags;

            _buffer.ClearRenderTarget(clearDepth: flags <= CameraClearFlags.Depth,
                                      clearColor: flags == CameraClearFlags.Color,
                                      backgroundColor: flags == CameraClearFlags.Color ? _camera.backgroundColor.linear : Color.clear);
            _buffer.BeginSample(_sampleName);
            ExecuteBuffer();
        }
コード例 #16
0
    private void RenderPerCamera(ScriptableRenderContext context, Camera camera)
    {
        context.SetupCameraProperties(camera);

        camera.TryGetCullingParameters(out var cullingParams);
        var cullingResults = context.Cull(ref cullingParams);

        //context.DrawSkybox(camera);
        this.OnPostCameraCulling(context, camera, ref cullingResults);

        //context.DrawSkybox(camera);
    }
コード例 #17
0
    public override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        base.Render(context, cameras);
        BeginFrameRendering(cameras);

        foreach (var camera in cameras)
        {
            context.SetupCameraProperties(camera);
            BeginCameraRendering(camera);

            // Cull
            if (!CullResults.GetCullingParameters(camera, out var cullingParameters))
            {
                return;
            }
            CullResults.Cull(ref cullingParameters, context, ref cull);

            // Clear

            var clearFlags = camera.clearFlags;
            cb.ClearRenderTarget(clearFlags.HasFlag(CameraClearFlags.Depth), clearFlags.HasFlag(CameraClearFlags.Color), camera.backgroundColor);

            cb.BeginSample("Render Camera");
            context.ExecuteCommandBuffer(cb);
            cb.Clear();

            // Draw

            var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));

            var filterSettings = new FilterRenderersSettings(true);

            // opaque pass
            drawSettings.sorting.flags      = SortFlags.CommonOpaque; // sort by distance to avoid overdraw
            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

            context.DrawSkybox(camera);

            // post-skybox pass for transparent renderers

            drawSettings.sorting.flags      = SortFlags.CommonTransparent;
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

            DrawDefaultPipeline(context, camera);

            cb.EndSample("Render Camera");
            context.ExecuteCommandBuffer(cb);
            cb.Clear();
            context.Submit();
        }
    }
コード例 #18
0
 public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
 {
     // SetupCameraProperties does the following:
     // Setup Camera RenderTarget and Viewport
     // VR Camera Setup and SINGLE_PASS_STEREO props
     // Setup camera view, proj and their inv matrices.
     // Setup properties: _WorldSpaceCameraPos, _ProjectionParams, _ScreenParams, _ZBufferParams, unity_OrthoParams
     // Setup camera world clip planes props
     // setup HDR keyword
     // Setup global time properties (_Time, _SinTime, _CosTime)
     context.SetupCameraProperties(renderingData.cameraData.camera, renderingData.cameraData.isStereoEnabled);
 }
コード例 #19
0
        private void Setup()
        {
            _context.SetupCameraProperties(_camera);
            CameraClearFlags flags      = _camera.clearFlags;
            bool             clearDepth = flags <= CameraClearFlags.Depth;
            bool             clearColor = flags == CameraClearFlags.Color;
            Color            backColor  = flags == CameraClearFlags.Color ? _camera.backgroundColor.linear : Color.clear;

            _commandBuffer.ClearRenderTarget(clearDepth, clearColor, backColor);
            _commandBuffer.BeginSample(SampleName);
            ExecuteCommandBuffer();
        }
コード例 #20
0
    public void SRPE01Rendering(ScriptableRenderContext context, IEnumerable <Camera> cameras)
    {
        foreach (Camera camera in cameras)
        {
            // Culling
            ScriptableCullingParameters cullingParams;

            if (!CullResults.GetCullingParameters(camera, out cullingParams))
            {
                continue;
            }
            CullResults cull = CullResults.Cull(ref cullingParams, context);

            // Setup camera for rendering (sets render target, view/projection matrices and other
            // per-camera built-in shader variables).
            context.SetupCameraProperties(camera);

            // Setup DrawSettings and FilterSettings
            //FilterRenderersSettings filterSettings = new FilterRenderersSettings(true);
            //filterSettings.renderQueueRange = RenderQueueRange.opaque;

            using (RenderPass rp = new RenderPass(context, camera.pixelWidth, camera.pixelHeight, 1, new[] { m_Albedo, m_Emission, m_Output }, m_Depth))
            {
                using (new RenderPass.SubPass(rp, new[] { m_Albedo, m_Emission }, null))
                {
                    var settings = new DrawRendererSettings(camera, new ShaderPassName("BasicPass"))
                    {
                        sorting = { flags = SortFlags.CommonOpaque }
                    };

                    // DrawRendererSettings drawSettings = new DrawRendererSettings(camera, new ShaderPassName("BasicPass"));
                    var fs = new FilterRenderersSettings(true);
                    fs.renderQueueRange = RenderQueueRange.opaque;
                    context.DrawRenderers(cull.visibleRenderers, ref settings, fs);
                }

                using (new RenderPass.SubPass(rp, new[] { m_Output }, new[] { m_Albedo, m_Emission }, false))
                {
                    context.DrawSkybox(camera);
                    var settings = new DrawRendererSettings(camera, new ShaderPassName("AddPass"))
                    {
                        sorting = { flags = SortFlags.CommonOpaque }
                    };
                    //DrawRendererSettings drawSettings = new DrawRendererSettings(camera, new ShaderPassName("AddPass"));
                    var fs = new FilterRenderersSettings(true);
                    fs.renderQueueRange = RenderQueueRange.opaque;
                    context.DrawRenderers(cull.visibleRenderers, ref settings, fs);
                }
            }

            context.Submit();
        }
    }
コード例 #21
0
        public override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            base.Render(context, cameras);

            if (LightsComposite == null)
            {
                Debug.LogError("cant render , becouse composite material is null");
                return;
            }

            Shader.globalRenderPipeline = "FlatLightRenderPipeline";

            // no sorting , no stereo
            foreach (Camera camera in cameras)
            {
                bool sceneViewCamera = camera.cameraType == CameraType.SceneView;
                m_CurrCamera = camera;

                ScriptableCullingParameters cullingParameters;
                if (!CullResults.GetCullingParameters(m_CurrCamera, false, out cullingParameters))
                {
                    continue;
                }

#if UNITY_EDITOR
                // Emit scene view UI
                if (sceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif

                CullResults.Cull(ref cullingParameters, context, ref m_CullResults);
                // skip light and skip shadow
                // skip intermediate resouces

                // SetupCameraProperties does the following:
                // Setup Camera RenderTarget and Viewport
                // VR Camera Setup and SINGLE_PASS_STEREO props
                // Setup camera view, proj and their inv matrices.
                // Setup properties: _WorldSpaceCameraPos, _ProjectionParams, _ScreenParams, _ZBufferParams, unity_OrthoParams
                // Setup camera world clip planes props
                // setup HDR keyword
                // Setup global time properties (_Time, _SinTime, _CosTime)
                context.SetupCameraProperties(m_CurrCamera, false);

                InternalRender(ref context);

                // no depth pass
                // present
                context.Submit();
            }
        }
コード例 #22
0
    private void Render(ScriptableRenderContext context, Camera camera)
    {
        ScriptableCullingParameters cullingParameters;

        if (!camera.TryGetCullingParameters(out cullingParameters))
        {
            return;
        }

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

        _cull = context.Cull(ref cullingParameters);

        context.SetupCameraProperties(camera);

        CameraClearFlags clearFlags = camera.clearFlags;
        _commandBuffer.ClearRenderTarget(
            clearFlags == CameraClearFlags.Depth || clearFlags == CameraClearFlags.Skybox,
            clearFlags == CameraClearFlags.Color || clearFlags == CameraClearFlags.Skybox,
            camera.backgroundColor);
        _commandBuffer.BeginSample("Render Camera");
        context.ExecuteCommandBuffer(_commandBuffer);
        _commandBuffer.Clear();

        var sortingSettings = new SortingSettings(camera)
        {
            criteria = SortingCriteria.CommonOpaque
        };

        var drawSettings = new DrawingSettings(new ShaderTagId("SRPDefaultUnlit"), sortingSettings);

        var filterSettings = new FilteringSettings(RenderQueueRange.opaque);
        context.DrawRenderers(_cull, ref drawSettings, ref filterSettings);
        context.DrawSkybox(camera);

        sortingSettings.criteria        = SortingCriteria.CommonTransparent;
        drawSettings.sortingSettings    = sortingSettings;
        filterSettings.renderQueueRange = RenderQueueRange.transparent;
        context.DrawRenderers(_cull, ref drawSettings, ref filterSettings);

        DrawDefaultPipeline(context, camera);

        _commandBuffer.EndSample("Render Camera");
        context.ExecuteCommandBuffer(_commandBuffer);
        _commandBuffer.Clear();

        context.Submit();
    }
コード例 #23
0
    void Setup()
    {
        //settng up camera before clearRT will give us more efficient process
        context.SetupCameraProperties(camera);
        //Get the clear flags from camera
        CameraClearFlags flags = camera.clearFlags;

        //make sure we have a Intermediate Buffer texture
        //Some effect depend on it
        useIntermediateBuffer = useScaledRendering || useDepthTexture || 
            postFXStack.IsActive || useColorTexture;

        //setup camera frame buffer for post FX
        //Without this, the content is directly draw to camera target
        if (useIntermediateBuffer)
        {
            if (flags > CameraClearFlags.Color)
            { flags = CameraClearFlags.Color; }

            //Separate the color and depth for the camera buffer
            buffer.GetTemporaryRT(colorAttachmentId, bufferSize.x,
                bufferSize.y, 0, FilterMode.Bilinear, 
                useHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default);
            buffer.GetTemporaryRT(depthAttachmentId, bufferSize.x,
                bufferSize.y, 32, FilterMode.Point,
                RenderTextureFormat.Depth);
            buffer.SetRenderTarget(colorAttachmentId, 
                RenderBufferLoadAction.DontCare,RenderBufferStoreAction.Store,
                depthAttachmentId,
                RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
        }

        //clearRT not need to be in profiling, it is self sampled using the buffer name
        buffer.ClearRenderTarget(
            flags <= CameraClearFlags.Depth,
            flags == CameraClearFlags.Color,
            flags == CameraClearFlags.Color ? camera.backgroundColor.linear : Color.clear
            );//clear the RT based on the clear flags
        //Profile injection, so we can use profiler to monitor what happens in between(B   eing&End)
        buffer.BeginSample(SampleName);

        //Set the depthtexture to missing, anything rendered after and before CopyAttachments()
        //will have invalid depth texture(ALL opaque objects and skybox)
        buffer.SetGlobalTexture(depthTextureId, missingTexture);
        buffer.SetGlobalTexture(colorTextureId, missingTexture);

        //Excute the Profile injection
        ExecuteBuffer();
        //buffer.Clear();

        
    }
コード例 #24
0
        private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor)
        {
            hd.SetupGlobalParams(cmd, 0);
            context.SetupCameraProperties(hd.camera);

            var transform = hd.camera.transform;
            var r         = transform.rotation;

            var originalProj = hd.camera.projectionMatrix;

            hd.camera.projectionMatrix = CubeProj;

            for (var i = 0; i < 6; ++i)
            {
                if ((target.CubeFaceMask & (1 << i)) == 0)
                {
                    continue;
                }

                transform.localRotation = Quaternion.LookRotation(CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
                var view = hd.camera.worldToCameraMatrix;
                SetupGlobalParamsForCubemap(cmd, view);

                CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)i);
                cmd.ClearRenderTarget(true, true, clearColor);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                if (hd.camera.TryGetCullingParameters(out var culling))
                {
                    var cull = context.Cull(ref culling);

                    var sorting = new SortingSettings(hd.camera);
                    var drawing = new DrawingSettings(pass, sorting);
                    var filter  = new FilteringSettings(RenderQueueRange.all);
                    // NOTE: This should flip culling, not hard-set it to front. SRP API does not provide this option
                    //       currently. Expected issues with front-culled geometry.
                    var stateBlock = new RenderStateBlock(RenderStateMask.Raster)
                    {
                        rasterState = new RasterState
                        {
                            cullingMode = CullMode.Front
                        }
                    };
                    context.DrawRenderers(cull, ref drawing, ref filter, ref stateBlock);
                }
            }

            transform.rotation         = r;
            hd.camera.projectionMatrix = originalProj;
        }
コード例 #25
0
        protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
        {
            BeginFrameRendering(renderContext, cameras);

            SortCameras(cameras);

            for (int index = 0; index < cameras.Length; ++index)
            {
                var camera = cameras[index];
                BeginCameraRendering(renderContext, camera);

                // clear target
                var cmd = CommandBufferPool.Get();
                cmd.ClearRenderTarget(true, false, Color.black);
                renderContext.ExecuteCommandBuffer(cmd);
                CommandBufferPool.Release(cmd);

                // Setup Camera
                renderContext.SetupCameraProperties(camera);

                // Culling
                ScriptableCullingParameters cullParams;
                if (!camera.TryGetCullingParameters(out cullParams))
                {
                    continue;
                }

                var cullingResults = renderContext.Cull(ref cullParams);

                SetupMainLightConstants(renderContext, ref cullingResults);

                // render
                for (int passIndex = 0; passIndex < renderPasses.Count; ++passIndex)
                {
                    var renderPass = renderPasses[passIndex];
                    renderPass.Render(renderContext, camera, ref cullingResults);
                }

                //draw gizmos

                /*#if UNITY_EDITOR
                 *          if (UnityEditor.Handles.ShouldRenderGizmos())
                 *              renderContext.DrawGizmos(camera, GizmoSubset.PostImageEffects);
                 #endif*/

                renderContext.Submit();

                EndCameraRendering(renderContext, camera);
            }

            EndFrameRendering(renderContext, cameras);
        }
コード例 #26
0
    private void Setup()
    {
        context.SetupCameraProperties(camera);
        var flags = camera.clearFlags;

        buffer.ClearRenderTarget(
            flags <= CameraClearFlags.Depth,
            flags == CameraClearFlags.Color,
            flags == CameraClearFlags.Color ? camera.backgroundColor.linear : Color.clear);
        buffer.BeginSample(SampleName);
        //Debug.Log($"BeginSample SampleName {SampleName} bufferName {bufferName} buffer.name {buffer.name} camera.name {camera.name} ");
        ExecuteBuffer();
    }
コード例 #27
0
    public void SetupGlobals()
    {
        context.SetupCameraProperties(CURRENT_CAMERA);
        CommandBuffer cmd = CommandBufferPool.Get("SetupGlobals");

        clusteredLightning.SetupClusteredLightning(ref cmd, m_CullResults, CURRENT_CAMERA, asset.NearCluster);

        cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
        cmd.ClearRenderTarget(true, true, Color.clear);

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
コード例 #28
0
ファイル: BasicPipeline02.cs プロジェクト: jcyongqin/SRP-Demo
        //这个函数在需要绘制管线的时候调用。
        public override void Render(ScriptableRenderContext context, Camera[] cameras)
        {
            base.Render(context, cameras);

            if (_cb == null)
            {
                _cb = new CommandBuffer();             // new CommandBuffer
            }
            //对于每一个相机执行操作。
            foreach (var camera in cameras)
            {
                //将上下文设置为当前相机的上下文。
                context.SetupCameraProperties(camera);
                _cb.name = "Setup";
                //显式将当前渲染目标设置为相机Backbuffer。
                _cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
                //设置渲染目标的颜色为相机背景色。
                _cb.ClearRenderTarget(true, true, camera.backgroundColor);
                context.ExecuteCommandBuffer(_cb);
                _cb.Clear();

                //绘制天空盒子,注意需要在ClearRenderTarget之后进行,不然颜色会被覆盖。
                context.DrawSkybox(camera);

                // 裁剪(Culling)
                var param = new ScriptableCullingParameters();
                CullResults.GetCullingParameters(camera, out param);    // 取出相机的裁剪信息
                param.isOrthographic = false;
                var culled = CullResults.Cull(ref param, context);

                // 过滤(Filtering)
                var fs = new FilterRenderersSettings(true);
                //设置只绘制不透明物体。
                fs.renderQueueRange = RenderQueueRange.opaque;
                //设置绘制所有层
                fs.layerMask = ~0;

                // 绘制设置(Renderer Settings)
                //注意在构造的时候就需要传入Lightmode参数
                var rs = new DrawRendererSettings(camera, new ShaderPassName("Unlit"));
                //由于绘制不透明物体可以借助Z-Buffer,因此不需要额外的排序。
                rs.sorting.flags = SortFlags.None;

                context.DrawRenderers(culled.visibleRenderers, ref rs, fs);

                context.Submit();                    // submit

                //开始执行管线
                context.Submit();
            }
        }
コード例 #29
0
    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        BeginFrameRendering(context, cameras);
        ScriptableCullingParameters cullParams;
        var clearColor = new Color(0, 0, 0.1f);

        foreach (var camera in cameras)
        {
            if (!camera.TryGetCullingParameters(out cullParams))
            {
                continue;
            }
            // notify engine and plugins that this camera is starting to render.
            BeginCameraRendering(context, camera);
            // configure view matrix, clipping, etc.
            context.SetupCameraProperties(camera);
            {
                var buffer = new CommandBuffer();
                buffer.ClearRenderTarget(true, true, clearColor);
                context.ExecuteCommandBuffer(buffer);
                buffer.Release();
            }
            // cull for this camera
            var cullResults = context.Cull(ref cullParams);

            // Draw opaque objects
            var drawSettings   = new DrawingSettings(new ShaderTagId("SRPDefaultUnlit"), new SortingSettings(camera));
            var filterSettings = FilteringSettings.defaultValue;
            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cullResults, ref drawSettings, ref filterSettings);
            // Draw skybox
            context.DrawSkybox(camera);
            // Draw transparent objects
            drawSettings.sortingSettings = new SortingSettings(camera)
            {
                criteria = SortingCriteria.CommonTransparent
            };
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            context.DrawRenderers(cullResults, ref drawSettings, ref filterSettings);

            /*
             * draw anything with incompatible materials with an error shader.
             */
            DrawWithDefaultPipeline(context, camera, cullResults);
            // Notify engine, plugins, etc. that this camera is finished rendering.
            EndCameraRendering(context, camera);
        }
        context.Submit();
        EndFrameRendering(context, cameras);
    }
コード例 #30
0
    void Setup()
    {
        context.SetupCameraProperties(camera);        //设置矩阵和一些属性
        CameraClearFlags flags = camera.clearFlags;   //CameraClearFlags是个枚举类型,分别是skybox,Color,Depth,Nothing

        buffer.ClearRenderTarget(
            flags <= CameraClearFlags.Depth,
            flags == CameraClearFlags.Color,
            flags == CameraClearFlags.Color ?
            camera.backgroundColor.linear : Color.clear
            );    //清除深度,颜色,以及用于清除的颜色
        buffer.BeginSample(SampleName);
        ExecuteBuffer();
    }