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


C# CommandBuffer.DrawProcedural方法代码示例

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


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

示例1: ResetGPUData

    public void ResetGPUData()
    {
        ReleaseGPUData();

        m_instance_data.Resize(m_max_instances);
        if (m_instance_buffer != null)
        {
            m_instance_buffer.Allocate(m_max_instances);
        }
        BatchRendererUtil.CreateVertexBuffer(m_mesh, ref m_vertex_buffer, ref m_vertex_count);

        {
            Material m = m_material;
            if (m_enable_rotation)
            {
                m.EnableKeyword("ENABLE_INSTANCE_ROTATION");
            }
            if (m_enable_scale)
            {
                m.EnableKeyword("ENABLE_INSTANCE_SCALE");
            }
            if (m_enable_emission)
            {
                m.EnableKeyword("ENABLE_INSTANCE_EMISSION");
            }
            if (m_enable_color)
            {
                m.EnableKeyword("ENABLE_INSTANCE_COLOR");
            }
            if (m_enable_uv_offset)
            {
                m.EnableKeyword("ENABLE_INSTANCE_UVOFFSET");
            }

            if (m_instance_buffer != null)
            {
                m.SetBuffer("g_vertices", m_vertex_buffer);
                m.SetBuffer("g_instance_buffer_t", m_instance_buffer.translation);
                m.SetBuffer("g_instance_buffer_r", m_instance_buffer.rotation);
                m.SetBuffer("g_instance_buffer_s", m_instance_buffer.scale);
                m.SetBuffer("g_instance_buffer_color", m_instance_buffer.color);
                m.SetBuffer("g_instance_buffer_emission", m_instance_buffer.emission);
                m.SetBuffer("g_instance_buffer_uv", m_instance_buffer.uv_offset);
            }
        }
        {
            m_cb = new CommandBuffer();
            m_cb.name = "ProceduralGBuffer";
            m_cb.DrawProcedural(Matrix4x4.identity, m_material, 0, MeshTopology.Triangles, m_vertex_count, m_max_instances);
            m_camera.AddCommandBuffer(CameraEvent.AfterGBuffer, m_cb);
        }

        // set default values
        UpdateGPUResources();
    }
开发者ID:nicegary,项目名称:Unity5Effects,代码行数:55,代码来源:ProceduralGBuffer.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: ResetGPUData

    public void ResetGPUData()
    {
        ReleaseGPUData();

        m_instance_data.Resize(m_max_instances);
        if (m_instance_buffer != null)
        {
            m_instance_buffer.Allocate(m_max_instances);
        }
        BatchRendererUtil.CreateVertexBuffer(m_mesh, ref m_vertex_buffer, ref m_vertex_count);

        {
            Material m = m_material;
            m.SetInt("g_flag_rotation", m_enable_rotation ? 1 : 0);
            m.SetInt("g_flag_scale", m_enable_scale ? 1 : 0);
            m.SetInt("g_flag_color", m_enable_color ? 1 : 0);
            m.SetInt("g_flag_emission", m_enable_emission ? 1 : 0);
            m.SetInt("g_flag_uvoffset", m_enable_uv_offset ? 1 : 0);
            if (m_instance_buffer != null)
            {
                m.SetBuffer("g_vertices", m_vertex_buffer);
                m.SetBuffer("g_instance_buffer_t", m_instance_buffer.translation);
                m.SetBuffer("g_instance_buffer_r", m_instance_buffer.rotation);
                m.SetBuffer("g_instance_buffer_s", m_instance_buffer.scale);
                m.SetBuffer("g_instance_buffer_color", m_instance_buffer.color);
                m.SetBuffer("g_instance_buffer_emission", m_instance_buffer.emission);
                m.SetBuffer("g_instance_buffer_uv", m_instance_buffer.uv_offset);
            }
        }
        {
            m_cb = new CommandBuffer();
            m_cb.name = "ProceduralGBuffer";
            m_cb.DrawProcedural(Matrix4x4.identity, m_material, 0, MeshTopology.Triangles, m_vertex_count, m_max_instances);
            m_camera.AddCommandBuffer(CameraEvent.AfterGBuffer, m_cb);
        }

        // set default values
        UpdateGPUResources();
    }
开发者ID:neight0903,项目名称:Unity5Effects,代码行数:39,代码来源:ProceduralGBuffer.cs

示例4: RenderSelfShadows

        /// <summary>
        /// Renders the selfshadow map for this light and the specified renderer.
        /// </summary>
        public void RenderSelfShadows(TressFXOITRenderer renderer)
        {
            if (this.shadowMappingCamera == null)
            {
                Debug.LogError("Shadow mapping camera is null but shadow map rendering was requested!");
                return;
            }

            // Prepare material
            Material mat = depthPassMaterial;
            renderer.SetShaderParams(mat);

            // Create command buffer for self shadows
            CommandBuffer selfShadowCommandBuffer = new CommandBuffer();
            selfShadowCommandBuffer.name = "TressFX SelfShadows";
            selfShadowCommandBuffer.SetRenderTarget(new RenderTargetIdentifier(this.selfShadowMap));

            if (this.selfShadowMode == SelfShadowMode.Lines)
                selfShadowCommandBuffer.DrawProcedural(Matrix4x4.identity, depthPassMaterial, 0, MeshTopology.Lines, renderer.g_LineIndicesBuffer.count);
            else if (this.selfShadowMode == SelfShadowMode.Triangles)
                selfShadowCommandBuffer.DrawProcedural(Matrix4x4.identity, depthPassMaterial, 1, MeshTopology.Lines, renderer.master.hairData.m_TriangleIndices.Length);

            // Prepare cam & render
            var shadowDistance = QualitySettings.shadowDistance;
            QualitySettings.shadowDistance = 0f;

            this.shadowMappingCamera.AddCommandBuffer(CameraEvent.AfterEverything, selfShadowCommandBuffer);
            this.shadowMappingCamera.targetTexture = this.selfShadowMap;
            this.shadowMappingCamera.cullingMask = 0;

            // Render shadows
            this.shadowMappingCamera.Render();
            this.shadowMappingCamera.RemoveAllCommandBuffers();

            QualitySettings.shadowDistance = shadowDistance;
        }
开发者ID:kennux,项目名称:TressFXUnity,代码行数:39,代码来源:TressFXOITLight.cs


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