当前位置: 首页>>代码示例>>C#>>正文


C# CommandBuffer.ClearRenderTarget方法代码示例

本文整理汇总了C#中UnityEngine.Rendering.CommandBuffer.ClearRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C# CommandBuffer.ClearRenderTarget方法的具体用法?C# CommandBuffer.ClearRenderTarget怎么用?C# CommandBuffer.ClearRenderTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rendering.CommandBuffer的用法示例。


在下文中一共展示了CommandBuffer.ClearRenderTarget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPreRender

    public void OnPreRender()
    {
        var act = gameObject.activeInHierarchy && enabled;
        if (!act)
        {
            Cleanup();
            return;
        }

        var cam = Camera.current;
        if (!cam)
            return;

        CommandBuffer buf = null;
        // Did we already add the command buffer on this camera? Nothing to do then.
        if (m_Cameras.ContainsKey(cam))
            return;

        if (!DepthMaterial)
        {
            DepthMaterial = new Material(DepthShader);
            DepthMaterial.hideFlags = HideFlags.HideAndDontSave;
        }

        buf = new CommandBuffer();
        buf.name = "Render Grass Depth Reference";
        m_Cameras[cam] = buf;

        int referenceDepthID = Shader.PropertyToID("_rdepth");
        buf.GetTemporaryRT(referenceDepthID, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth);
        buf.SetRenderTarget(new RenderTargetIdentifier(referenceDepthID));
        buf.ClearRenderTarget(true, false, Color.white, 1);

        foreach (MeshRenderer r in GrassMeshes)
            buf.DrawRenderer(r, DepthMaterial);

        buf.SetRenderTarget(new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget));

        buf.SetGlobalTexture("_ReferenceDepth", referenceDepthID);

        cam.AddCommandBuffer(CameraEvent.BeforeImageEffects, buf);
        Debug.Log("Add Command Buffer");
    }
开发者ID:Flafla2,项目名称:Screen-Space-Grass,代码行数:43,代码来源:GrassManager.cs

示例2: OnWillRenderObject

    // Whenever any camera will render us, add a command buffer to do the work on it
    public void OnWillRenderObject() {   // REQUIRES THIS OBJ TO HAVE MESHRENDERER COMPONENT!!!!
        var act = gameObject.activeInHierarchy && enabled;
        if (!act) {
            Cleanup();
            return;
        }

        var cam = Camera.current;
        if (!cam)
            return;

        CommandBuffer buf = null;  // clear CommandBuffer... why does this have to be done every frame?
                                   // Did we already add the command buffer on this camera? Nothing to do then.
        if (m_Cameras.ContainsKey(cam))
            return;

        //if (!m_Material) {
        //    m_Material = new Material(m_BlurShader);
        //    m_Material.hideFlags = HideFlags.HideAndDontSave;  // not sure what this does -- prevents garbage collection??
        //}

        buf = new CommandBuffer();
        buf.name = "TestDrawProcedural";
        m_Cameras[cam] = buf;  // fill in dictionary entry for this Camera

        // START!!!
        // Canvas First:
        canvasMaterial.SetColor("_Color", Color.gray);  // initialize canvas        
        canvasMaterial.SetTexture("_DepthTex", canvasDepthTex);
        canvasMaterial.SetFloat("_MaxDepth", 1.0f);

        // Create RenderTargets:
        int colorReadID = Shader.PropertyToID("_ColorTextureRead");
        int colorWriteID = Shader.PropertyToID("_ColorTextureWrite");
        int depthReadID = Shader.PropertyToID("_DepthTextureRead");
        int depthWriteID = Shader.PropertyToID("_DepthTextureWrite");
        buf.GetTemporaryRT(colorReadID, -1, -1, 0, FilterMode.Bilinear);
        buf.GetTemporaryRT(colorWriteID, -1, -1, 0, FilterMode.Bilinear);
        buf.GetTemporaryRT(depthReadID, -1, -1, 0, FilterMode.Bilinear);
        buf.GetTemporaryRT(depthWriteID, -1, -1, 0, FilterMode.Bilinear);

        RenderTargetIdentifier[] mrt = { colorWriteID, depthWriteID };  // Define multipleRenderTarget so I can render to color AND depth
        buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget);  // Set render Targets
        buf.ClearRenderTarget(true, true, Color.white, 1.0f);  // clear -- needed???
        buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, canvasMaterial);   // Write into canvas Color & Depth buffers
        
        // Copy results into Read buffers for next pass:
        buf.Blit(colorWriteID, colorReadID);
        buf.Blit(depthWriteID, depthReadID);

        // Gesso/Primer Pass:
        gessoMaterial.SetPass(0);
        gessoMaterial.SetColor("_Color", new Color(0.19f, 0.192f, 0.194f, 1.0f));
        buf.SetGlobalTexture("_ColorReadTex", colorReadID);
        buf.SetGlobalTexture("_DepthReadTex", depthReadID);
        buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget);  // Set render Targets
        buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, gessoMaterial);
        // Copy results into Read buffers for next pass:
        buf.Blit(colorWriteID, colorReadID);
        buf.Blit(depthWriteID, depthReadID);

        // MAIN BRUSHSTROKE CONTENTS PASS!!!:
        strokeMaterial.SetPass(0);
        strokeMaterial.SetColor("_Color", brushStrokeColor);
        strokeMaterial.SetVector("_Size", size);
        strokeMaterial.SetBuffer("strokeDataBuffer", strokeBuffer);
        strokeMaterial.SetBuffer("quadPointsBuffer", quadPointsBuffer);
        buf.SetGlobalTexture("_ColorReadTex", colorReadID);
        buf.SetGlobalTexture("_DepthReadTex", depthReadID);
        buf.SetRenderTarget(colorWriteID);
        buf.SetGlobalTexture("_FrameBufferTexture", BuiltinRenderTextureType.CameraTarget); // Copy the Contents of FrameBuffer into brushstroke material so it knows what color it should be
        buf.DrawProcedural(Matrix4x4.identity, strokeMaterial, 0, MeshTopology.Triangles, 6, strokeBuffer.count);   // Apply brushstrokes

        // DISPLAY TO SCREEN:
        buf.Blit(colorWriteID, BuiltinRenderTextureType.CameraTarget);   // copy canvas target into main displayTarget so it is what the player sees

        // apply the commandBuffer
        cam.AddCommandBuffer(CameraEvent.AfterFinalPass, buf);  
        

        
        //buf.SetRenderTarget(canvasRT);
        //buf.ClearRenderTarget(true, true, Color.black, 1.0f);
        //int canvasID = Shader.PropertyToID("_CanvasTexture");
        //int tempID = Shader.PropertyToID("_TempTexture");
        //buf.GetTemporaryRT(canvasID, -1, -1, 0, FilterMode.Bilinear);  // Create a Temporary RenderTarget for the "canvas"
        //buf.GetTemporaryRT(tempID, -1, -1, 0, FilterMode.Bilinear);  // Create a Temporary RenderTarget for the "canvas"
        //buf.SetRenderTarget(canvasID);  // Set commandBuffer target to this "canvas" so the DrawProcedural will apply to this
        //buf.ClearRenderTarget(true, true, Color.white, 1.0f);  // Clear the target each frame and rebuild
        //buf.Blit(canvasID, tempID);  // copy into temporary buffer
        //buf.Blit(tempID, canvasID, gessoBlitMaterial);  // copy back into renderTarget, apply Gesso Primer
        //buf.SetGlobalTexture("_FrameBufferTexture", BuiltinRenderTextureType.CameraTarget);  // Copy the Contents of FrameBuffer into brushstroke material so it knows what color it should be
        //buf.DrawProcedural(Matrix4x4.identity, strokeMaterial, 0, MeshTopology.Triangles, 6, strokeBuffer.count);   // Apply brushstrokes

        // MRT example:
        //RenderTargetIdentifier[] mrt = { BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer2 };
        //buf.SetRenderTarget(mrt, BuiltinRenderTextureType.CameraTarget);

        //buf.Blit(canvasID, BuiltinRenderTextureType.CameraTarget);   // copy canvas target into main displayTarget so it is what the player sees
//.........这里部分代码省略.........
开发者ID:eaclou,项目名称:Master_CreatureTrainer01,代码行数:101,代码来源:PaintRenderMain01.cs

示例3: CreateCommandBuffers

    private void CreateCommandBuffers()
    {
        m_renderCmdBuffer = new CommandBuffer();
        m_renderCmdBuffer.name = "Highlights: Drawing Objects";

        // Drawing objects to the buffer
        m_renderCmdBuffer.SetRenderTarget(m_colorRT, BuiltinRenderTextureType.CameraTarget);
        m_renderCmdBuffer.ClearRenderTarget(false, true, Color.clear);

        var pass = m_selectionType == HighlightType.Glow ? HighlightPass.MarkStencilArea : HighlightPass.DrawSolid;
        foreach(var hObject in m_renderers)
        {
            m_renderCmdBuffer.SetGlobalColor("_Color", hObject.Value);
            m_renderCmdBuffer.SetGlobalFloat("_Cutoff",  m_cutoffValue * 0.5f);
            m_renderCmdBuffer.DrawRenderer(hObject.Key, m_highlightMaterial, 0, (int) pass);
        }
            
        foreach(var hObject in m_renderers)
        {
            m_renderCmdBuffer.SetGlobalColor("_Color", hObject.Value);
            m_renderCmdBuffer.DrawRenderer(hObject.Key, m_highlightMaterial, 0, (int) HighlightPass.ExtrudeOutline);
        }

        var drawEvent = GetCameraDrawEvent();
        m_camera.AddCommandBuffer(drawEvent, m_renderCmdBuffer);
    }
开发者ID:BubbleRap,项目名称:ExploreTheDarkness,代码行数:26,代码来源:HighlightsImageEffect.cs


注:本文中的UnityEngine.Rendering.CommandBuffer.ClearRenderTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。