コード例 #1
0
        private void RenderDefaultUnlit(ScriptableRenderContext context, Camera camera)
        {
            // Culling
            ScriptableCullingParameters cullingParams;

            if (!CullResults.GetCullingParameters(camera, out cullingParams))
            {
                return; // How can this happen, what does it mean?
            }
            cullingParams.cullingFlags = CullFlag.None;
            CullResults cullResults = new CullResults();

            CullResults.Cull(ref cullingParams, context, ref cullResults);

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

            // Drawing regular opaque
            drawSettings.sorting.flags      = SortFlags.CommonOpaque;
            filterSettings.renderQueueRange = RenderQueueRange.opaque;
            context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterSettings);

            // Drawing regular transparent
            drawSettings.sorting.flags      = SortFlags.CommonTransparent;
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterSettings);
        }
コード例 #2
0
        public override void Render(Camera[] cameras, RenderLoop renderLoop)
        {
            foreach (var camera in cameras)
            {
                CullResults       cullResults;
                CullingParameters cullingParams;
                if (!CullResults.GetCullingParameters(camera, out cullingParams))
                {
                    continue;
                }

                m_ShadowPass.UpdateCullingParameters(ref cullingParams);

                cullResults = CullResults.Cull(ref cullingParams, renderLoop);

                ShadowOutput shadows;
                m_ShadowPass.Render(renderLoop, cullResults, out shadows);

                renderLoop.SetupCameraProperties(camera);

                UpdateLightConstants(cullResults.visibleLights, ref shadows);

                var settings = new DrawRendererSettings(cullResults, camera, new ShaderPassName("ForwardBase"));
                settings.rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes;
                settings.sorting.sortOptions   = SortOptions.SortByMaterialThenMesh;

                renderLoop.DrawRenderers(ref settings);
                renderLoop.Submit();
            }

            // Post effects
        }
コード例 #3
0
    void RenderFallback(ScriptableRenderContext renderContext, Camera camera)
    {
        _command.ClearRenderTarget(true, true, Color.black);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        ScriptableCullingParameters cullingParams;

        if (!CullResults.GetCullingParameters(camera, out cullingParams))
        {
            return;
        }
        CullResults.Cull(ref cullingParams, renderContext, ref _cullResults);

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

        drawSettings.SetShaderPassName(1, new ShaderPassName("PrepassBase"));
        drawSettings.SetShaderPassName(2, new ShaderPassName("Always"));
        drawSettings.SetShaderPassName(3, new ShaderPassName("Vertex"));
        drawSettings.SetShaderPassName(4, new ShaderPassName("VertexLMRGBM"));
        drawSettings.SetShaderPassName(5, new ShaderPassName("VertexLM"));
        drawSettings.flags = _drawRendererFlags;

        renderContext.SetupCameraProperties(camera);
        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref drawSettings, _filterSettings);
        renderContext.DrawSkybox(camera);
    }
コード例 #4
0
    public void CullingAndDraw(ScriptableRenderContext context, Camera cam)
    {
        if (!CullResults.GetCullingParameters(cam, out cullingParameters))
        {
            return;
        }
#if UNITY_EDITOR
        if (cam.cameraType == CameraType.SceneView)
        {
            ScriptableRenderContext.EmitWorldGeometryForSceneView(cam);
        }
#endif
        UnityEngine.Profiling.Profiler.BeginSample("GCSource");
        CullResults.Cull(ref cullingParameters, context, ref cull);
        UnityEngine.Profiling.Profiler.EndSample();
        DrawRendererSettings drawSettings = new DrawRendererSettings(cam, new ShaderPassName("CstRP"));
        if (asset.enableDynamicBatching)
        {
            drawSettings.flags = DrawRendererFlags.EnableDynamicBatching;
        }
        if (asset.enableInstancing)
        {
            drawSettings.flags |= DrawRendererFlags.EnableInstancing;
        }
        drawSettings.sorting.flags = SortFlags.CommonOpaque;
        FilterRenderersSettings filterSettings = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque
        };
        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);
        context.DrawSkybox(cam);
        drawSettings.sorting.flags      = SortFlags.CommonTransparent;
        filterSettings.renderQueueRange = RenderQueueRange.transparent;
        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);
    }
コード例 #5
0
    void SteroidRenderCamera(ScriptableRenderContext context, Camera camera)
    {
        ScriptableCullingParameters scp;

        if (!CullResults.GetCullingParameters(camera, false, out scp))
        {
            return;
        }

        context.SetupCameraProperties(camera);

        var cullResults = CullResults.Cull(ref scp, context);

        cmd.ClearRenderTarget(false, true, camera.backgroundColor);
        context.ExecuteCommandBuffer(cmd);

        var sprites = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.transparent,
            layerMask        = asset.visibleLayers.value
        };

        var drs = new DrawRendererSettings(camera, new ShaderPassName("Steroid"))
        {
            flags = DrawRendererFlags.EnableDynamicBatching,
            rendererConfiguration = RendererConfiguration.None,
        };

        drs.sorting.flags = SortFlags.CommonTransparent;

        context.DrawRenderers(cullResults.visibleRenderers, ref drs, sprites);
    }
コード例 #6
0
    private void OpaqueRender(ScriptableRenderContext renderContext, Camera[] cameras, CommandBuffer cmd)
    {
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(cameras[0], out cullingParameters))
        {
            //If camera doesn't have culilng?
        }

        // Clear Depth
        CullResults cull = CullResults.Cull(ref cullingParameters, renderContext);

        renderContext.SetupCameraProperties(cameras[0]);
        cmd.ClearRenderTarget(true, false, cameras[0].backgroundColor);
        cmd.Release();

        // Draw object in the BasicPass shader pass
        DrawRendererSettings settings = new DrawRendererSettings(cameras[0], new ShaderPassName("BasicPass"));

        settings.sorting.flags = SortFlags.CommonOpaque;

        FilterRenderersSettings filterSettings = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        renderContext.DrawRenderers(cull.visibleRenderers, ref settings, filterSettings);

        renderContext.Submit();
    }
コード例 #7
0
    /// <summary>
    /// 実際の描画処理
    /// </summary>
    public override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        base.Render(context, cameras);
        if (cmd == null)
        {
            cmd = new CommandBuffer();
        }
        int idx = 0;

        foreach (var camera in cameras)
        {
            // Cullingします
            if (!CullResults.GetCullingParameters(camera, out cullingParams))
            {
                continue;
            }
            CullResults.Cull(ref cullingParams, context, ref cull);

            // カメラに関するShaderパラメーターをセットアップします
            context.SetupCameraProperties(camera);

            // 画面をクリアします
            cmd.Clear();
            cmd.ClearRenderTarget(true, true, Color.black, 1.0f);
            context.ExecuteCommandBuffer(cmd);

            // Directional Lightの値を設定します
            SetUpDirectionalLightParam(cull.visibleLights);

            // 何かCommandBufferに入っていれば…
            if (zPrepassCommandBuffers != null && idx == 0)
            {
                ExecuteCommandBufferList(context, zPrepassCommandBuffers);
            }
            // キャラクターを ZPrepassで描画します
            DrawCharacter(context, camera, zPrepass, SortFlags.CommonOpaque);
            // BGをBasicPassで描画します
            DrawBg(context, camera);

            // 何かCommandBufferに入っていれば…
            if (actualCommandBuffers != null && idx == 0)
            {
                ExecuteCommandBufferList(context, actualCommandBuffers);
            }
            // キャラクターをBasicPassで描画します
            DrawCharacter(context, camera, basicPass, SortFlags.OptimizeStateChanges);

            // 何か入っていれば...
            if (shadowCommandBuffers != null && idx == 0)
            {
                ExecuteCommandBufferList(context, shadowCommandBuffers);
            }
            // 最後に影を描画します
            DrawShadow(context, camera);

            // 描画内容をコミットします
            context.Submit();
            ++idx;
        }
    }
コード例 #8
0
    public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
    {
        base.Render(renderContext, cameras);

        foreach (var camera in cameras)
        {
            if (!camera.enabled)
            {
                continue;
            }

            CullingParameters cullingParams;
            bool gotCullingParams = CullResults.GetCullingParameters(camera, out cullingParams);
            Assert.IsTrue(gotCullingParams);

            CullResults cullResults = CullResults.Cull(ref cullingParams, renderContext);

            if (s_Callback != null)
            {
                s_Callback(camera, cullResults, renderContext);
            }
        }

        renderContext.Submit();
    }
コード例 #9
0
    private void RenderCamera(ScriptableRenderContext context, Camera camera)
    {
        //设置摄像机属性给上下文
        context.SetupCameraProperties(camera);
        //清除背景
        CameraClearFlags clearFlags = camera.clearFlags;

        cameraClearBuff.ClearRenderTarget(
            (clearFlags & CameraClearFlags.Depth) != 0,
            (clearFlags & CameraClearFlags.Color) != 0,
            camera.backgroundColor
            );
        context.ExecuteCommandBuffer(cameraClearBuff);
        cameraClearBuff.Clear();
        //剔除视图外的物体
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))
        {
            return;
        }
#if UNITY_EDITOR
        if (camera.cameraType == CameraType.SceneView)
        {
            ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
        }
#endif
        CullResults.Cull(ref cullingParameters, context, ref cull);
        //绘制物体
        DrawOpaqueRenders(context, camera, cull);
        DrawDefaultPipeline(context, camera);
        context.DrawSkybox(camera);
        DrawTransparentRenders(context, camera, cull);
        context.Submit();
    }
    private CullResults GetCullingResults(ref ScriptableRenderContext context, ref Camera camera)
    {
        CullResults results = new CullResults();

        CullResults.GetCullingParameters(camera, out ScriptableCullingParameters cullingParameters);
        CullResults.Cull(ref cullingParameters, context, ref results);
        return(results);
    }
コード例 #11
0
ファイル: DoomSRPPipeline.cs プロジェクト: ifeuille/DoomSRP
        public static void RenderSingleCamera(DoomSRPPipeline pipelineInstance, ScriptableRenderContext context, Camera camera, ref CullResults cullResults, IRendererSetup setup = null)
        {
            if (pipelineInstance == null)
            {
                Debug.LogError("Trying to render a camera with an invalid render pipeline instance.");
                return;
            }

            ScriptableCullingParameters cullingParameters;

            if (!CullResults.GetCullingParameters(camera, out cullingParameters))
            {
                return;
            }

            CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag);

            using (new ProfilingSample(cmd, k_RenderCameraTag))
            {
                CameraData         cameraData;
                PipelineSettings   settings  = pipelineInstance.settings;
                ScriptableRenderer renderer  = pipelineInstance.renderer;
                LightLoop          lightloop = pipelineInstance.GetLightLoop();
                InitializeCameraData(pipelineInstance.settings, camera, out cameraData);
                SetupPerCameraShaderConstants(cameraData);

                cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane);
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif
                CullResults.Cull(ref cullingParameters, context, ref cullResults);

                RenderingData renderingData;
                InitializeRenderingData(settings, ref cameraData, ref cullResults, ref lightloop, out renderingData);
                var setupToUse = setup;
                if (setupToUse == null)
                {
                    setupToUse = defaultRendererSetup;
                }

                renderer.Clear();
                setupToUse.Setup(renderer, ref renderingData);
                renderer.Execute(context, ref renderingData);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            context.Submit();
#if UNITY_EDITOR
            Handles.DrawGizmos(camera);
#endif
        }
コード例 #12
0
ファイル: MyPipeline.cs プロジェクト: jesenzhang/R-Evolution
    public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
    {
        base.Render(renderContext, cameras);

        foreach (var camera in cameras)
        {
            renderContext.SetupCameraProperties(camera);

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

            if (!CullResults.GetCullingParameters(camera, out ScriptableCullingParameters cullingParameters))
            {
                return;
            }

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

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

            var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));
            //先渲染不透明
            //This instructs Unity to sort the renderers by distance, from front to back, plus a few other criteria.
            drawSettings.sorting.flags = SortFlags.CommonOpaque;
            //筛选不透明物体
            var filterSettings = new FilterRenderersSettings(true)
            {
                renderQueueRange = RenderQueueRange.opaque
            };

            renderContext.DrawRenderers(
                cull.visibleRenderers, ref drawSettings, filterSettings
                );
            //渲染天空
            renderContext.DrawSkybox(camera);

            //筛选透明物体
            drawSettings.sorting.flags      = SortFlags.CommonTransparent;
            filterSettings.renderQueueRange = RenderQueueRange.transparent;
            //渲染透明
            renderContext.DrawRenderers(
                cull.visibleRenderers, ref drawSettings, filterSettings
                );

#if UNITY_EDITOR
            DrawDefaultPipeline(renderContext, camera);
#endif
        }
        renderContext.Submit();
    }
コード例 #13
0
ファイル: MyPipeline.cs プロジェクト: pawii/Unity-SRP
    private void Render(ScriptableRenderContext context, Camera camera)
    {
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))
        {
            return;
        }

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

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

        context.SetupCameraProperties(camera);

        CameraClearFlags clearFlags = camera.clearFlags;
        cameraBuffer.ClearRenderTarget(
            (clearFlags & CameraClearFlags.Depth) != 0,
            (clearFlags & CameraClearFlags.Color) != 0,
            camera.backgroundColor
            );
        //cameraBuffer.ClearRenderTarget(true, false, Color.clear);
        cameraBuffer.BeginSample("Render Camera");
        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear();

        var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));
        drawSettings.flags         = drawFlags;
        drawSettings.sorting.flags = SortFlags.CommonOpaque;

        var filterSettings = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

        context.DrawSkybox(camera);

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

        DrawDefaultPipeline(context, camera);

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

        context.Submit();
    }
コード例 #14
0
    void Render(ScriptableRenderContext context, Camera camera)
    {
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))  // check if culling parameters are valid else return
        {
            return;
        }

        //CullResults contains information about what is visible in the context
        CullResults.Cull(ref cullingParameters, context, ref cull);

        context.SetupCameraProperties(camera);


        CameraClearFlags clearFlags = camera.clearFlags;

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

        cameraBuffer.BeginSample("Render Camera sample"); // to improve readability of data shown by frame debugger

        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear(); // Clear resorces,data used by buffer to be used in next frame

        DrawRendererSettings drawSettings = new DrawRendererSettings(
            camera, new ShaderPassName("SRPDefaultUnlit")        // The camera is used to setup sorting and culling layers, while the pass controls which shader pass is used for rendering.
            );

        drawSettings.sorting.flags = SortFlags.CommonOpaque;    //This instructs Unity to sort the renderers by distance from front to back

        // delay drawing transparent renderers until after the skybox to avoid over draw of objects with skybox
        FilterRenderersSettings filterSettings = new FilterRenderersSettings(true)      // limit the draw before the skybox to only the opaque renderers.
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

        context.DrawSkybox(camera);

        // render transparent after skybox
        // Trnsparent combines the color of what's being drawn with what has been drawn before,
        drawSettings.sorting.flags      = SortFlags.CommonTransparent;
        filterSettings.renderQueueRange = RenderQueueRange.transparent;
        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

        DrawDefaultPipeline(context, camera); // to render objects that uses difrent shaders

        cameraBuffer.EndSample("Render Camera sample");
        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear(); // Clear resorces,data used by buffer to be used in next frame
        context.Submit();     // must call submit to make draw functions work
    }
コード例 #15
0
        public static void RenderSingleCamera(ScriptableRenderContext context, PipelineSettings settings, Camera camera, ref CullResults cullResults, IRendererSetup setup, ScriptableRenderer renderer)
        {
            string        renderCameraTag = camera.name;
            CommandBuffer cmd             = CommandBufferPool.Get(renderCameraTag);

            using (new ProfilingSample(cmd, renderCameraTag))
            {
                CameraData cameraData;
                InitializeCameraData(settings, camera, out cameraData);
                SetupPerCameraShaderConstants(cameraData);

                ScriptableCullingParameters cullingParameters;
                if (!CullResults.GetCullingParameters(camera, cameraData.isStereoEnabled, out cullingParameters))
                {
                    CommandBufferPool.Release(cmd);
                    return;
                }

                cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane);

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

#if UNITY_EDITOR
                // Emit scene view UI
                if (cameraData.isSceneViewCamera)
                {
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
                }
#endif
                CullResults.Cull(ref cullingParameters, context, ref cullResults);
                List <VisibleLight> visibleLights = cullResults.visibleLights;

                RenderingData renderingData;
                InitializeRenderingData(settings, ref cameraData, visibleLights,
                                        renderer.maxSupportedLocalLightsPerPass, renderer.maxSupportedVertexLights,
                                        out renderingData);

                var setupToUse = setup;
                if (setupToUse == null)
                {
                    setupToUse = defaultRendererSetup;
                }

                setupToUse.Setup(renderer, ref context, ref cullResults, ref renderingData);

                renderer.Execute(ref context, ref cullResults, ref renderingData);

                context.ExecuteCommandBuffer(cmd);
                CommandBufferPool.Release(cmd);
                context.Submit();
#if UNITY_EDITOR
                Handles.DrawGizmos(camera);
#endif
            }
        }
コード例 #16
0
ファイル: ZPipline.cs プロジェクト: billwillman/ZSrpPipline
    private void PrepareCulls(ScriptableRenderContext ctx, Camera cam)
    {
        ScriptableCullingParameters cullParams;

        // 从摄像机获得当前相机的建材参数
        if (CullResults.GetCullingParameters(cam, out cullParams))
        {
            CullResults.Cull(ref cullParams, ctx, ref m_CamCullResults);
        }
    }
コード例 #17
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();
    }
コード例 #18
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);
                }
            }
        }
コード例 #19
0
    //this methode renders the scene with the now shaded textures
    //it's called by the Render(...) every frame
    //Input:    renderContext:  ScriptableRenderContext
    //          camera:         Camera in scene
    void ReadBack(ScriptableRenderContext context, Camera camera)
    {
        //setup _____________________________________________________________________________________________________________________________________________
        //reset camera buffer
        cameraBuffer.Clear();

        //set object shader to read back
        foreach (ObjData obj in sceneObjects)
        {
            Material mat = obj.obj.GetComponent <Renderer>().material;
            mat.DisableKeyword("_FIRST_PASS");
            mat.EnableKeyword("_READ_BACK");
        }

        //set new render target
        Graphics.SetRenderTarget(finalImage);

        //culling ___________________________________________________________________________________________________________________________________________
        ScriptableCullingParameters cullingParameters;

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

        //clearing ___________________________________________________________________________________________________________________________________________
        cameraBuffer.ClearRenderTarget(true, true, camera.backgroundColor);
        context.ExecuteCommandBuffer(cameraBuffer);
        cameraBuffer.Clear();

        //drawing ____________________________________________________________________________________________________________________________________________
        //setup settings for rendering
        DrawRendererSettings drawSettings = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));

        drawSettings.sorting.flags = SortFlags.CommonOpaque;
        FilterRenderersSettings filterSettings = new FilterRenderersSettings(true);

        //draw
        context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);
        context.Submit();

        //finish _____________________________________________________________________________________________________________________________________________
        //set object shader back to firstpass
        foreach (ObjData obj in sceneObjects)
        {
            Material mat = obj.obj.GetComponent <Renderer>().material;
            mat.EnableKeyword("_FIRST_PASS");
            mat.DisableKeyword("_READ_BACK");
        }

        //display image on screen
        Graphics.Blit(finalImage, camera.activeTexture);
    }
コード例 #20
0
    public void Voxelize(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        ScriptableCullingParameters cullingParams;

        if (!CullResults.GetCullingParameters(_camera, out cullingParams))
        {
            return;
        }
        CullResults.Cull(ref cullingParams, renderContext, ref _cullResults);

        _lightColors.Clear();
        _lightPositions.Clear();

        foreach (var light in _cullResults.visibleLights)
        {
            if (light.lightType == LightType.Point)
            {
                _lightColors.Add(light.finalColor);
                _lightPositions.Add(light.light.transform.position);
            }
        }

        UpdateCamera();

        _camera.pixelRect = _rect;

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(_propDummyTarget, _cameraDescriptor);
        _command.SetRenderTarget(_propDummyTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

        _command.SetGlobalInt("Resolution", _resolution);
        _command.SetGlobalMatrix("WorldToVoxel", _vxgi.worldToVoxel);
        _command.SetGlobalMatrix("VoxelToProjection", GL.GetGPUProjectionMatrix(_camera.projectionMatrix, true) * _camera.worldToCameraMatrix * _vxgi.voxelToWorld);
        _command.SetRandomWriteTarget(1, _vxgi.voxelBuffer, false);

        _drawSettings.flags = renderer.drawRendererFlags;
        _drawSettings.rendererConfiguration = renderer.rendererConfiguration;

        renderContext.ExecuteCommandBuffer(_command);
        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref _drawSettings, _filterSettings);

        _command.Clear();

        _command.ClearRandomWriteTargets();
        _command.ReleaseTemporaryRT(_propDummyTarget);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
コード例 #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
    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();
        }
    }
コード例 #23
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();
        }
    }
コード例 #24
0
    public void Voxelize(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        ScriptableCullingParameters cullingParams;

        if (!CullResults.GetCullingParameters(_camera, out cullingParams))
        {
            return;
        }
        CullResults.Cull(ref cullingParams, renderContext, ref _cullResults);

        _vxgi.lights.Clear();

        foreach (var light in _cullResults.visibleLights)
        {
            if (VXGI.supportedLightTypes.Contains(light.lightType) && light.finalColor.maxColorComponent > 0f)
            {
                _vxgi.lights.Add(new LightSource(light, _vxgi.worldToVoxel));
            }
        }

        UpdateCamera();

        _camera.pixelRect = _rect;

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(ShaderIDs.Dummy, _cameraDescriptor);
        _command.SetRenderTarget(ShaderIDs.Dummy, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

        _command.SetGlobalInt(ShaderIDs.Resolution, _resolution);
        _command.SetGlobalMatrix(ShaderIDs.WorldToVoxel, _vxgi.worldToVoxel);
        _command.SetGlobalMatrix(ShaderIDs.VoxelToProjection, GL.GetGPUProjectionMatrix(_camera.projectionMatrix, true) * _camera.worldToCameraMatrix * _vxgi.voxelToWorld);
        _command.SetRandomWriteTarget(1, _vxgi.voxelBuffer, false);

        _drawSettings.flags = renderer.drawRendererFlags;
        _drawSettings.rendererConfiguration = renderer.rendererConfiguration;

        renderContext.ExecuteCommandBuffer(_command);
        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref _drawSettings, _filterSettings);

        _command.Clear();

        _command.ClearRandomWriteTargets();
        _command.ReleaseTemporaryRT(ShaderIDs.Dummy);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
コード例 #25
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();
            }
        }
コード例 #26
0
        private void Render(PipelineCamera pipelineCam, RenderTargetIdentifier dest, ref ScriptableRenderContext context, Camera cam)
        {
            CameraRenderingPath path = pipelineCam.renderingPath;

            pipelineCam.cam = cam;
            pipelineCam.EnableThis();
            if (!CullResults.GetCullingParameters(cam, out data.cullParams))
            {
                return;
            }
            context.SetupCameraProperties(cam);
            //Set Global Data
            data.defaultDrawSettings = new DrawRendererSettings(cam, new ShaderPassName(""));
            data.context             = context;
            data.cullResults         = CullResults.Cull(ref data.cullParams, context);

            PipelineFunctions.InitRenderTarget(ref pipelineCam.targets, cam, data.buffer);
            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);
            }
            PipelineEvent[] events = null;
            switch (pipelineCam.renderingPath)
            {
            case CameraRenderingPath.GPUDeferred:
                events = gpurpEvents;
                break;
            }
            currentRenderingPath = pipelineCam.renderingPath;
            foreach (var e in events)
            {
                if (e.enabled && e.preEnable)
                {
                    e.PreRenderFrame(pipelineCam, ref data);
                }
            }
            JobHandle.ScheduleBatchedJobs();
            foreach (var e in events)
            {
                if (e.enabled && e.postEnable)
                {
                    e.FrameUpdate(pipelineCam, ref data);
                }
            }
            data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, dest);
        }
コード例 #27
0
    public static void Render(RenderLoopWrapper wrapper, Camera[] cameras, RenderLoop renderLoop)
    {
        foreach (var camera in cameras)
        {
            CullingParameters cullingParams;
            bool gotCullingParams = CullResults.GetCullingParameters(camera, out cullingParams);
            Assert.IsTrue(gotCullingParams);

            CullResults cullResults = CullResults.Cull(ref cullingParams, renderLoop);

            s_Callback(camera, cullResults, renderLoop);
        }

        renderLoop.Submit();
    }
コード例 #28
0
    void Render(ScriptableRenderContext rc, Camera camera)
    {
        // Get camera culling parameters
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))
        {
            return;
        }

        // perform culling, CullResults stores information on what is visible
        CullResults.Cull(ref cullingParameters, rc, ref cull);

        // Setup camera properties
        rc.SetupCameraProperties(camera);

        CameraClearFlags clearFlags = camera.clearFlags;

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

        // Execute command buffer
        rc.ExecuteCommandBuffer(cameraBuffer);

        // release it!
        cameraBuffer.Clear();

        // DRAW!!!!
        var drawSettings   = new DrawRendererSettings(camera, new ShaderPassName("SRPDefaultUnlit"));
        var filterSettings = new FilterRenderersSettings(true);

        // First draw opaque objects
        drawSettings.sorting.flags      = SortFlags.CommonOpaque;
        filterSettings.renderQueueRange = RenderQueueRange.opaque;
        rc.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

        rc.DrawSkybox(camera);

        // draw transparent objects after skybox is drawn!
        drawSettings.sorting.flags      = SortFlags.CommonTransparent;
        filterSettings.renderQueueRange = RenderQueueRange.transparent;
        rc.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings);

        rc.Submit();
    }
コード例 #29
0
    //called once for every camera by methode above
    //this methode calls the all methodes mention in description in order
    //Input:    renderContext:  ScriptableRenderContext
    //          camera:         Camera in scene
    public void Render(ScriptableRenderContext context, Camera camera)
    {
        //statistics
        pixelCountStat = 0;
        tileCountStat  = 0;

        //setup rendercontext for camera
        context.SetupCameraProperties(camera);

        //culling ______________________________________________________________________________________________________
        ScriptableCullingParameters cullingParameters;

        if (!CullResults.GetCullingParameters(camera, out cullingParameters))
        {
            return;
        }

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


        //UV Renderer __________________________________________________________________________________________________
        //Renders vertexIds and baycentric coordinates in uv space for each object´if not already done
        if (sceneObjects == null)
        {
            sceneObjects = UVRenderer(context, camera);
        }

        //First pass ___________________________________________________________________________________________________
        //Renders uv coordinates, mip level and id for each visible part of each object
        FirstPass(context, camera);

        //Compute shader _______________________________________________________________________________________________
        foreach (ObjData obj in sceneObjects)
        {
            //calculate which part of each texture is visible on screen
            RunTileMaskShader(obj, firstPassTargets[0], firstPassTargets[1]);
            //shade visible textures in uv space
            RunObjectSpaceComputeShader(obj);
        }

        //Read-Back ____________________________________________________________________________________________________
        //Render objects with shaded textures
        ReadBack(context, camera);

        //reset render target
        Graphics.SetRenderTarget(null);
    }
        private void Render(PipelineCamera pipelineCam, RenderTargetIdentifier dest, ref ScriptableRenderContext context, Camera cam)
        {
            CameraRenderingPath path = pipelineCam.renderingPath;

            pipelineCam.cam = cam;
            pipelineCam.EnableThis();
            if (!CullResults.GetCullingParameters(cam, out data.cullParams))
            {
                return;
            }
            context.SetupCameraProperties(cam);
            //Set Global Data
            data.defaultDrawSettings = new DrawRendererSettings(cam, new ShaderPassName(""));
            data.context             = context;
            data.cullResults         = CullResults.Cull(ref data.cullParams, context);

            PipelineFunctions.InitRenderTarget(ref pipelineCam.targets, cam, data.buffer);
            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);
            }
            DrawEvent evt;

            if (allDrawEvents.TryGetValue(path, out evt))
            {
                //Pre Calculate Events
                foreach (var i in evt.preRenderEvents)
                {
                    i.PreRenderFrame(pipelineCam, ref data);
                }
                //Run job system together
                JobHandle.ScheduleBatchedJobs();
                //Start Prepare Render Targets
                //Frame Update Events
                foreach (var i in evt.drawEvents)
                {
                    i.FrameUpdate(pipelineCam, ref data);
                }
            }
            data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, dest);
            data.ExecuteCommandBuffer();
        }