private ClearRenderTarget ( bool clearDepth, bool clearColor, System.Color backgroundColor ) : void | ||
clearDepth | bool | |
clearColor | bool | |
backgroundColor | System.Color | |
리턴 | void |
private RenderTexture RenderPreview(Noesis.View view, int width, int height) { try { if (CanRender() && view != null && view.Content != null) { NoesisRenderer.SetRenderSettings(); view.SetSize(width, height); view.Update(0.0f); FlushMetalEncoder(_commands); NoesisRenderer.RenderOffscreen(view, _commands); RenderTexture rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 8); _commands.SetRenderTarget(rt); _commands.ClearRenderTarget(true, true, UnityEngine.Color.clear, 0.0f); NoesisRenderer.RenderOnscreen(view, false, _commands); Graphics.ExecuteCommandBuffer(_commands); _commands.Clear(); GL.InvalidateState(); RenderTexture.ReleaseTemporary(rt); return(rt); } } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } return(null); }
static public int ClearRenderTarget(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 4) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); System.Boolean a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); UnityEngine.Color a3; checkType(l, 4, out a3); self.ClearRenderTarget(a1, a2, a3); pushValue(l, true); return(1); } else if (argc == 5) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); System.Boolean a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); UnityEngine.Color a3; checkType(l, 4, out a3); System.Single a4; checkType(l, 5, out a4); self.ClearRenderTarget(a1, a2, a3, a4); 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)); } }
void RenderRearParaboloid(Material _mat, Mesh _mesh) { Matrix4x4 view = Matrix4x4.Inverse(Matrix4x4.TRS( Vector3.zero, Quaternion.LookRotation(Vector3.back, Vector3.up), new Vector3(1, 1, -1) )); RenderTexture rt = new RenderTexture(mTexSize, mTexSize, 16); UnityEngine.Rendering.CommandBuffer cmd = new UnityEngine.Rendering.CommandBuffer(); cmd.name = "RenderFrontParaboloid"; cmd.SetViewProjectionMatrices(view, Matrix4x4.identity); cmd.SetRenderTarget(rt); cmd.ClearRenderTarget(true, true, Color.clear); cmd.DrawMesh(_mesh, Matrix4x4.identity, _mat); Graphics.ExecuteCommandBuffer(cmd); Texture2D tex = RenderTexture2Texture2D(rt); SaveTexture <Texture2D>(tex, GetPath("Rear")); }
// 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 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"); }
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); }