private DrawProcedural ( Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount ) : void | ||
matrix | Matrix4x4 | |
material | Material | |
shaderPass | int | |
topology | MeshTopology | |
vertexCount | int | |
Résultat | void |
// Draws a full screen triangle as a faster alternative to drawing a full screen quad. public static void DrawFullScreen(CommandBuffer commandBuffer, Material material, MaterialPropertyBlock properties = null, int shaderPassId = 0) { commandBuffer.DrawProcedural(Matrix4x4.identity, material, shaderPassId, MeshTopology.Triangles, 3, 1, properties); }
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(); }
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(); }
static public int DrawProcedural(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 6) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Matrix4x4 a1; checkValueType(l, 2, out a1); UnityEngine.Material a2; checkType(l, 3, out a2); System.Int32 a3; checkType(l, 4, out a3); UnityEngine.MeshTopology a4; checkEnum(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); self.DrawProcedural(a1, a2, a3, a4, a5); pushValue(l, true); return(1); } else if (argc == 7) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Matrix4x4 a1; checkValueType(l, 2, out a1); UnityEngine.Material a2; checkType(l, 3, out a2); System.Int32 a3; checkType(l, 4, out a3); UnityEngine.MeshTopology a4; checkEnum(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); System.Int32 a6; checkType(l, 7, out a6); self.DrawProcedural(a1, a2, a3, a4, a5, a6); pushValue(l, true); return(1); } else if (argc == 8) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Matrix4x4 a1; checkValueType(l, 2, out a1); UnityEngine.Material a2; checkType(l, 3, out a2); System.Int32 a3; checkType(l, 4, out a3); UnityEngine.MeshTopology a4; checkEnum(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); System.Int32 a6; checkType(l, 7, out a6); UnityEngine.MaterialPropertyBlock a7; checkType(l, 8, out a7); self.DrawProcedural(a1, a2, a3, a4, a5, a6, a7); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
// 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 //Material testMat = new Material(Shader.Find("Unlit/Color")); //testMat.color = Color.yellow; //buf.DrawMesh(CreateFullscreenQuad(mainCam), Matrix4x4.identity, testMat); //buf.ReleaseTemporaryRT(colorReadID); //buf.ReleaseTemporaryRT(colorWriteID); //buf.ReleaseTemporaryRT(depthReadID); //buf.ReleaseTemporaryRT(depthWriteID); }
public void HDDraw(UnityEngine.Rendering.CommandBuffer cmd) { cmd.DrawProcedural(Matrix4x4.identity, m_Line3DMaterial, 0, MeshTopology.Triangles, m_NumLine3DsToDraw * 6, 1); }
/// <summary> /// Blit a RTHandle texture /// </summary> /// <param name="cmd">Command Buffer used for rendering.</param> /// <param name="source">Source RTHandle.</param> /// <param name="scaleBias">Scale and bias for sampling the input texture.</param> /// <param name="material">Material to invoke when blitting.</param> /// <param name="pass">Pass idx within the material to invoke.</param> public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass) { s_PropertyBlock.SetVector(BlitShaderIDs._BlitScaleBias, scaleBias); s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source); cmd.DrawProcedural(Matrix4x4.identity, material, pass, MeshTopology.Triangles, 3, 1, s_PropertyBlock); }
/// <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; }