private DrawMesh ( Mesh mesh, Matrix4x4 matrix, Material material ) : void | ||
mesh | Mesh | |
matrix | Matrix4x4 | |
material | Material | |
Résultat | void |
/// <summary> /// Sends render commands to native code /// </summary> public static void RenderOnscreen(Noesis.View view, bool flipY, UnityEngine.Rendering.CommandBuffer commands) { // This is a workaround for a bug in Unity. When rendering nothing Unity sends us an empty MTLRenderCommandEncoder if (UnityEngine.SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) { if (_dummyMesh == null) { _dummyMesh = new UnityEngine.Mesh(); _dummyMesh.vertices = new UnityEngine.Vector3[3]; _dummyMesh.vertices[0] = new UnityEngine.Vector3(0, 0, 0); _dummyMesh.vertices[1] = new UnityEngine.Vector3(0, 0, 0); _dummyMesh.vertices[2] = new UnityEngine.Vector3(0, 0, 0); _dummyMesh.triangles = new int[3] { 0, 2, 1 }; } if (_dummyMaterial == null) { _dummyMaterial = new UnityEngine.Material(UnityEngine.Shader.Find("UI/Default")); } commands.DrawMesh(_dummyMesh, new UnityEngine.Matrix4x4(), _dummyMaterial); } commands.IssuePluginEventAndData(_renderOnscreenCallback, flipY ? 1 : 0, view.CPtr.Handle); }
static public int DrawMesh(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 4) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.DrawMesh(a1, a2, a3); pushValue(l, true); return(1); } else if (argc == 5) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.DrawMesh(a1, a2, a3, a4); pushValue(l, true); return(1); } else if (argc == 6) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); self.DrawMesh(a1, a2, a3, a4, a5); 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 OnPreRender() { var cam = GetComponent<Camera>(); if (m_material == null) { m_material = new Material(m_shader); } if (m_commands == null) { m_commands = new CommandBuffer(); m_commands.name = "ClearForwardGBuffer"; m_commands.DrawMesh(m_quad, Matrix4x4.identity, m_material); cam.AddCommandBuffer(CameraEvent.AfterFinalPass, m_commands); } m_material.SetColor("_ClearColor", cam.backgroundColor); }
// Use this for initialization void Start() { rt = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGBFloat); Camera.main.targetTexture = rt; //Camera.main.hdr = true; mpb = new MaterialPropertyBlock(); mpb.SetTexture("_MainTex", testImg); //quadMeshMtl.SetTexture("_MainTex",testImg); GenerateQuadMesh(); UnityEngine.Rendering.CommandBuffer cbuffer; cbuffer = new UnityEngine.Rendering.CommandBuffer(); cbuffer.SetRenderTarget(rt); cbuffer.DrawMesh(quadMesh, Matrix4x4.identity, quadMeshMtl, 0, -1, mpb); Graphics.ExecuteCommandBuffer(cbuffer); //Graphics.DrawMesh(quadMesh,Matrix4x4.identity,quadMeshMtl,LayerMask.NameToLayer("Default"),Camera.main,0,mpb,false,false); }
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")); }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { m_mp4conf = fcAPI.fcMP4Config.default_value; m_mp4conf.video = m_captureVideo; m_mp4conf.audio = m_captureAudio; m_mp4conf.video_width = m_scratch_buffer.width; m_mp4conf.video_height = m_scratch_buffer.height; m_mp4conf.video_max_framerate = 60; m_mp4conf.video_bitrate = m_videoBitrate; m_mp4conf.audio_bitrate = m_audioBitrate; m_mp4conf.audio_sampling_rate = AudioSettings.outputSampleRate; m_mp4conf.audio_num_channels = fcAPI.fcGetNumAudioChannels(); m_ctx = fcAPI.fcMP4CreateContext(ref m_mp4conf); m_output_file = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4"; m_ostream = fcAPI.fcCreateFileStream(GetOutputPath()); fcAPI.fcMP4AddOutputStream(m_ctx, m_ostream); } // initialize command buffer { m_cb = new CommandBuffer(); m_cb.name = "MP4OffscreenRecorder: copy frame buffer"; m_cb.SetRenderTarget(m_scratch_buffer); m_cb.SetGlobalTexture("_TmpRenderTarget", m_target); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3); } }
internal override void RenderVectors(Camera camera, CommandBuffer renderCB, float scale, Quality quality) { if (this.m_initialized && !this.m_error && this.m_renderer.isVisible) { bool flag = (this.m_owner.Instance.CullingMask & 1 << this.m_obj.gameObject.layer) != 0; int num = (!flag) ? 255 : this.m_owner.Instance.GenerateObjectId(this.m_obj.gameObject); Vector3[] vertices = this.m_cloth.vertices; for (int i = 0; i < this.m_targetVertexCount; i++) { this.m_currVertices[i] = vertices[this.m_targetRemap[i]]; } if (this.m_starting || !this.m_wasVisible) { Array.Copy(this.m_currVertices, this.m_prevVertices, this.m_targetVertexCount); } this.m_clonedMesh.vertices = this.m_currVertices; this.m_clonedMesh.normals = this.m_prevVertices; Matrix4x4 value; if (this.m_obj.FixedStep) { value = this.m_owner.PrevViewProjMatrixRT * this.m_currLocalToWorld; } else { value = this.m_owner.PrevViewProjMatrixRT * this.m_prevLocalToWorld; } renderCB.SetGlobalMatrix("_AM_MATRIX_PREV_MVP", value); renderCB.SetGlobalFloat("_AM_OBJECT_ID", (float)num * 0.003921569f); renderCB.SetGlobalFloat("_AM_MOTION_SCALE", (!flag) ? 0f : scale); int num2 = (quality != Quality.Mobile) ? 2 : 0; for (int j = 0; j < this.m_sharedMaterials.Length; j++) { MotionState.MaterialDesc materialDesc = this.m_sharedMaterials[j]; int shaderPass = num2 + ((!materialDesc.coverage) ? 0 : 1); if (materialDesc.coverage) { Texture mainTexture = materialDesc.material.mainTexture; if (mainTexture != null) { materialDesc.propertyBlock.SetTexture("_MainTex", mainTexture); } if (materialDesc.cutoff) { materialDesc.propertyBlock.SetFloat("_Cutoff", materialDesc.material.GetFloat("_Cutoff")); } } renderCB.DrawMesh(this.m_clonedMesh, this.m_currLocalToWorld, this.m_owner.Instance.ClothVectorsMaterial, j, shaderPass, materialDesc.propertyBlock); } } }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { fcAPI.fcGifConfig conf; conf.width = m_scratch_buffer.width; conf.height = m_scratch_buffer.height; conf.num_colors = Mathf.Clamp(m_numColors, 1, 256); conf.max_active_tasks = 0; m_ctx = fcAPI.fcGifCreateContext(ref conf); } // initialize command buffer { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "GifRecorder: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb.SetRenderTarget(m_scratch_buffer); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb.ReleaseTemporaryRT(tid); } }
// 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); }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { fcAPI.fcGifConfig conf; conf.width = m_scratch_buffer.width; conf.height = m_scratch_buffer.height; conf.num_colors = Mathf.Clamp(m_numColors, 1, 256); conf.max_active_tasks = 0; m_ctx = fcAPI.fcGifCreateContext(ref conf); } // initialize command buffer { m_cb = new CommandBuffer(); m_cb.name = "GifOffscreenRecorder: copy frame buffer"; m_cb.SetRenderTarget(m_scratch_buffer); m_cb.SetGlobalTexture("_TmpRenderTarget", m_target); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3); } }
void OnPreRender() { m_material.SetInt("g_frame", Time.frameCount); m_material.SetInt("g_hdr", m_camera.hdr ? 1 : 0); m_material.SetInt("g_scene", m_scene); m_material.SetInt("g_enable_adaptive", m_enable_adaptive ? 1 : 0); m_material.SetInt("g_enable_temporal", m_enable_temporal ? 1 : 0); m_material.SetInt("g_enable_glowline", m_enable_glowline ? 1 : 0); RenderSettings.fogColor = m_fog_color; if (m_quad == null) { m_quad = RaymarcherUtils.GenerateQuad(); } if (m_detailed_quad == null) { m_detailed_quad = RaymarcherUtils.GenerateDetailedQuad(); } bool need_to_reflesh_command_buffer = false; Vector2 reso = new Vector2(m_camera.pixelWidth, m_camera.pixelHeight); if(m_resolution_prev!=reso) { m_resolution_prev = reso; need_to_reflesh_command_buffer = true; } if (m_enable_adaptive_prev != m_enable_adaptive) { m_enable_adaptive_prev = m_enable_adaptive; need_to_reflesh_command_buffer = true; } if (m_dbg_show_steps_prev != m_dbg_show_steps) { m_dbg_show_steps_prev = m_dbg_show_steps; need_to_reflesh_command_buffer = true; } if (need_to_reflesh_command_buffer) { need_to_reflesh_command_buffer = false; ClearCommandBuffer(); } if (m_cb_raymarch==null) { if (m_enable_adaptive) { RenderTargetIdentifier[] rt; m_cb_prepass = new CommandBuffer(); m_cb_prepass.name = "Raymarcher Adaptive PrePass"; int odepth = Shader.PropertyToID("ODepth"); int odepth_prev = Shader.PropertyToID("ODepthPrev"); int ovelocity = Shader.PropertyToID("OVelocity"); int qdepth = Shader.PropertyToID("QDepth"); int qdepth_prev = Shader.PropertyToID("QDepthPrev"); int hdepth = Shader.PropertyToID("HDepth"); int hdepth_prev = Shader.PropertyToID("HDepthPrev"); int adepth = Shader.PropertyToID("ADepth"); int adepth_prev = Shader.PropertyToID("ADepthPrev"); m_cb_prepass.GetTemporaryRT(odepth, m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(odepth_prev,m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(ovelocity, m_camera.pixelWidth / 8, m_camera.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RHalf); m_cb_prepass.GetTemporaryRT(qdepth, m_camera.pixelWidth / 4, m_camera.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(qdepth_prev,m_camera.pixelWidth / 4, m_camera.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth, m_camera.pixelWidth / 2, m_camera.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth_prev,m_camera.pixelWidth / 2, m_camera.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth, m_camera.pixelWidth / 1, m_camera.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth_prev,m_camera.pixelWidth / 1, m_camera.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); rt = new RenderTargetIdentifier[2] { odepth, ovelocity }; m_cb_prepass.SetGlobalTexture("g_depth_prev", odepth_prev); m_cb_prepass.SetRenderTarget(rt, odepth); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 1); m_cb_prepass.Blit(odepth, odepth_prev); m_cb_prepass.SetGlobalTexture("g_velocity", ovelocity); m_cb_prepass.SetRenderTarget(qdepth); m_cb_prepass.SetGlobalTexture("g_depth", odepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", qdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 2); m_cb_prepass.Blit(qdepth, qdepth_prev); m_cb_prepass.SetRenderTarget(hdepth); m_cb_prepass.SetGlobalTexture("g_depth", qdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", hdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 3); m_cb_prepass.Blit(hdepth, hdepth_prev); m_cb_prepass.SetRenderTarget(adepth); m_cb_prepass.SetGlobalTexture("g_depth", hdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", adepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 4); m_cb_prepass.Blit(adepth, adepth_prev); m_cb_prepass.SetGlobalTexture("g_depth", adepth); m_camera.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_prepass); } m_cb_raymarch = new CommandBuffer(); m_cb_raymarch.name = "Raymarcher"; m_cb_raymarch.DrawMesh(m_quad, Matrix4x4.identity, m_material, 0, 0); m_camera.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_raymarch); } }
void OnEnable() { m_outputDir.CreateDirectory(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_shCopy); // initialize exr context fcAPI.fcExrConfig conf = fcAPI.fcExrConfig.default_value; m_ctx = fcAPI.fcExrCreateContext(ref conf); // initialize render targets m_scratch_buffers = new RenderTexture[m_targets.Length]; for (int i = 0; i < m_scratch_buffers.Length; ++i) { var rt = m_targets[i]; m_scratch_buffers[i] = new RenderTexture(rt.width, rt.height, 0, rt.format); m_scratch_buffers[i].Create(); } // initialize command buffers { m_cb_copy = new CommandBuffer(); m_cb_copy.name = "PngOffscreenRecorder: Copy"; for (int i = 0; i < m_targets.Length; ++i) { m_cb_copy.SetRenderTarget(m_scratch_buffers[i]); m_cb_copy.SetGlobalTexture("_TmpRenderTarget", m_targets[i]); m_cb_copy.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3); } } }
void OnRenderImage(RenderTexture source, RenderTexture destination) { // intialize the post effect render camera effectCamera.CopyFrom(GetComponent <Camera>()); effectCamera.clearFlags = CameraClearFlags.Nothing; effectCamera.cullingMask = 0; effectCamera.enabled = false; // initialize or resize linked list head buffer if (_headerBuffer != null && _headerBuffer.count != headerLength) { _headerBuffer.Release(); _headerBuffer = null; } if (_headerBuffer == null) { _headerBuffer = new ComputeBuffer(headerLength, Marshal.SizeOf(typeof(int))); } // initialize or resize the fragment linked list / append buffer if (_linkedListBuffer != null && _linkedListBuffer.count != linkedListLength) { _linkedListBuffer.Release(); _linkedListBuffer = null; } if (_linkedListBuffer == null) { _linkedListBuffer = new ComputeBuffer(linkedListLength, Marshal.SizeOf(typeof(LinkedListNode)), ComputeBufferType.Counter); } Graphics.SetRandomWriteTarget(1, _headerBuffer); Graphics.SetRandomWriteTarget(2, _linkedListBuffer); clearUtilities.SetBuffer(CLEAR_HEADER_KERNEL, HEAD_BUFFER_NAME, _headerBuffer); clearUtilities.Dispatch(CLEAR_HEADER_KERNEL, _headerBuffer.count, 1, 1); clearUtilities.SetBuffer(CLEAR_LINKEDLIST_KERNEL, LINKEDLIST_BUFFER_NAME, _linkedListBuffer); clearUtilities.Dispatch(CLEAR_LINKEDLIST_KERNEL, _linkedListBuffer.count, 1, 1); // Draw the meshes Shader.SetGlobalBuffer(HEAD_BUFFER_NAME, _headerBuffer); Shader.SetGlobalBuffer(LINKEDLIST_BUFFER_NAME, _linkedListBuffer); Shader.SetGlobalInt(LINKEDLIST_END_NAME, _linkedListBuffer.count); UnityEngine.Rendering.CommandBuffer commandBuffer = new UnityEngine.Rendering.CommandBuffer(); for (int i = 0; i < _renderers.Count; i++) { FragmentSortedRenderer fsr = _renderers[i]; // TODO: Support multiple materials? MeshFilter mf = fsr.GetComponent <MeshFilter>(); if (fsr.material && mf) { commandBuffer.DrawMesh(mf.sharedMesh, fsr.transform.localToWorldMatrix, fsr.material); } } effectCamera.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterEverything, commandBuffer); effectCamera.Render(); effectCamera.RemoveAllCommandBuffers(); commandBuffer.Release(); // Sort the fragments clearUtilities.SetBuffer(SORT_LINKEDLIST_KERNEL, HEAD_BUFFER_NAME, _headerBuffer); clearUtilities.SetBuffer(SORT_LINKEDLIST_KERNEL, LINKEDLIST_BUFFER_NAME, _linkedListBuffer); clearUtilities.Dispatch(SORT_LINKEDLIST_KERNEL, _headerBuffer.count, 1, 1); Graphics.ClearRandomWriteTargets(); compositeMaterial.DisableKeyword("FRAGS_PER_PIXEL"); if (drawFragmentCount) { compositeMaterial.EnableKeyword("FRAGS_PER_PIXEL"); compositeMaterial.SetFloat("_FragmentCount", checkFragmentCount); } compositeMaterial.SetFloat("_DepthScale", effectCamera.farClipPlane - effectCamera.nearClipPlane); Graphics.Blit(source, destination, compositeMaterial); Shader.SetGlobalBuffer(HEAD_BUFFER_NAME, null); Shader.SetGlobalBuffer(LINKEDLIST_BUFFER_NAME, null); Shader.SetGlobalInt(LINKEDLIST_END_NAME, 0); }
void OnEnable() { m_outputDir.CreateDirectory(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_shCopy); var cam = GetComponent<Camera>(); if (cam.targetTexture != null) { m_mat_copy.EnableKeyword("OFFSCREEN"); } #if UNITY_EDITOR if (m_captureGBuffer && !FrameCapturerUtils.IsRenderingPathDeferred(cam)) { Debug.LogWarning("PngRecorder: Rendering Path must be deferred to use Capture GBuffer mode."); m_captureGBuffer = false; } #endif // UNITY_EDITOR // initialize png context fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value; m_ctx = fcAPI.fcPngCreateContext(ref conf); // initialize render targets { m_frame_buffer = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, RenderTextureFormat.ARGBHalf); m_frame_buffer.wrapMode = TextureWrapMode.Repeat; m_frame_buffer.Create(); var formats = new RenderTextureFormat[7] { RenderTextureFormat.ARGBHalf, // albedo (RGB) RenderTextureFormat.RHalf, // occlusion (R) RenderTextureFormat.ARGBHalf, // specular (RGB) RenderTextureFormat.RHalf, // smoothness (R) RenderTextureFormat.ARGBHalf, // normal (RGB) RenderTextureFormat.ARGBHalf, // emission (RGB) RenderTextureFormat.RHalf, // depth (R) }; m_gbuffer = new RenderTexture[7]; for (int i = 0; i < m_gbuffer.Length; ++i) { // last one is depth (1 channel) m_gbuffer[i] = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, formats[i]); m_gbuffer[i].filterMode = FilterMode.Point; m_gbuffer[i].Create(); } } // initialize command buffers { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb_copy_fb = new CommandBuffer(); m_cb_copy_fb.name = "PngRecorder: Copy FrameBuffer"; m_cb_copy_fb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Point); m_cb_copy_fb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb_copy_fb.SetRenderTarget(m_frame_buffer); m_cb_copy_fb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb_copy_fb.ReleaseTemporaryRT(tid); m_cb_copy_gb = new CommandBuffer(); m_cb_copy_gb.name = "PngRecorder: Copy G-Buffer"; m_cb_copy_gb.SetRenderTarget( new RenderTargetIdentifier[] { m_gbuffer[0], m_gbuffer[1], m_gbuffer[2], m_gbuffer[3] }, m_gbuffer[0]); m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 4); m_cb_copy_gb.SetRenderTarget( new RenderTargetIdentifier[] { m_gbuffer[4], m_gbuffer[5], m_gbuffer[6], m_gbuffer[3] }, m_gbuffer[0]); m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 5); } }
internal override void RenderVectors( Camera camera, CommandBuffer renderCB, float scale, AmplifyMotion.Quality quality ) { if ( m_initialized && !m_error && m_renderer.isVisible ) { Profiler.BeginSample( "Skinned.Update" ); if ( !m_useFallback ) { if ( !m_useGPU ) WaitForAsyncUpdate(); } Profiler.EndSample(); Profiler.BeginSample( "Skinned.Render" ); if ( !m_useGPU ) { if ( !m_useFallback ) m_clonedMesh.vertices = m_currVertices; m_clonedMesh.normals = m_prevVertices; } const float rcp255 = 1 / 255.0f; bool mask = ( m_owner.Instance.CullingMask & ( 1 << m_obj.gameObject.layer ) ) != 0; int objectId = mask ? m_owner.Instance.GenerateObjectId( m_obj.gameObject ) : 255; Matrix4x4 prevModelViewProj; if ( m_obj.FixedStep ) prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_currLocalToWorld; else prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_prevLocalToWorld; renderCB.SetGlobalMatrix( "_AM_MATRIX_PREV_MVP", prevModelViewProj ); renderCB.SetGlobalFloat( "_AM_OBJECT_ID", objectId * rcp255 ); renderCB.SetGlobalFloat( "_AM_MOTION_SCALE", mask ? scale : 0 ); if ( m_useGPU ) { #if !UNITY_4 Vector4 vertexTexelSize = new Vector4( 1.0f / m_gpuVertexTexWidth, 1.0f / m_gpuVertexTexHeight, m_gpuVertexTexWidth, m_gpuVertexTexHeight ); renderCB.SetGlobalVector( "_AM_VERTEX_TEXEL_SIZE", vertexTexelSize ); renderCB.SetGlobalVector( "_AM_VERTEX_TEXEL_HALFSIZE", vertexTexelSize * 0.5f ); renderCB.SetGlobalTexture( "_AM_PREV_VERTEX_TEX", m_gpuPrevVertices ); renderCB.SetGlobalTexture( "_AM_CURR_VERTEX_TEX", m_gpuCurrVertices ); #endif } int hardwarePass = m_useGPU ? 4 : 0; int qualityPass = ( quality == AmplifyMotion.Quality.Mobile ) ? 0 : 2; int basePass = hardwarePass + qualityPass; for ( int i = 0; i < m_sharedMaterials.Length; i++ ) { MaterialDesc matDesc = m_sharedMaterials[ i ]; int pass = basePass + ( matDesc.coverage ? 1 : 0 ); if ( matDesc.coverage ) { Texture mainTex = matDesc.material.mainTexture; if ( mainTex != null ) matDesc.propertyBlock.SetTexture( "_MainTex", mainTex ); if ( matDesc.cutoff ) matDesc.propertyBlock.SetFloat( "_Cutoff", matDesc.material.GetFloat( "_Cutoff" ) ); } renderCB.DrawMesh( m_clonedMesh, m_currLocalToWorld, m_owner.Instance.SkinnedVectorsMaterial, i, pass, matDesc.propertyBlock ); } Profiler.EndSample(); } }
private void drawOverrideEyeMat(CommandBuffer buf, OverrideEye eyeObj, int pass) { if(eyeObj.Mr != null) { MeshFilter _mf = eyeObj.GetComponent<MeshFilter>(); for(int _i = 0; _i < _mf.sharedMesh.subMeshCount; ++_i) { buf.DrawMesh(_mf.sharedMesh, eyeObj.gameObject.transform.localToWorldMatrix, this.m_overrideEyeMat, _i, pass); } } else if(eyeObj.SkinMr != null) { for(int _i = 0; _i < eyeObj.SkinMr.sharedMesh.subMeshCount; ++_i) { buf.DrawRenderer(eyeObj.SkinMr, this.m_overrideEyeMat, _i, pass); } } }
private void drawSlefMat(CommandBuffer buf, OverrideEye eyeObj, int pass) { if(eyeObj.Mr != null) { MeshFilter _mf = eyeObj.GetComponent<MeshFilter>(); for(int _i = 0; _i < _mf.sharedMesh.subMeshCount; ++_i) { buf.DrawMesh(_mf.sharedMesh, eyeObj.gameObject.transform.localToWorldMatrix, eyeObj.Materials[_i], _i, pass); } } else if(eyeObj.SkinMr != null) { for(int _i = 0; _i < eyeObj.SkinMr.sharedMesh.subMeshCount; ++_i) { eyeObj.Materials[_i].EnableKeyword("DIRLIGHTMAP_OFF"); eyeObj.Materials[_i].EnableKeyword("DYNAMICLIGHTMAP_OFF"); buf.DrawRenderer(eyeObj.SkinMr, eyeObj.Materials[_i], _i, pass); } } }
void OnEnable() { OnDisable(); var camera = GetComponent<Camera>(); commandBuffer = new CommandBuffer(); commandBuffer.name = "SkyMesh"; commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); var matrix = Matrix4x4.TRS(m_position, Quaternion.Euler(m_rotation), m_scale); commandBuffer.DrawMesh(m_mesh, matrix, m_material); camera.AddCommandBuffer(m_cameraEvent, commandBuffer); lastCameraEvent = m_cameraEvent; }
void OnRenderObject() { // We have to use command buffers instead of Graphics.DrawMesh because of strange depth issues that I am experiencing // with Graphics.Drawmesh (perhaps Graphics.DrawMesh is called before all opaque objects are rendered?) var act = gameObject.activeInHierarchy && enabled; if (!act) { Cleanup(); return; } // If _SelectableMesh == null there is a crash in Unity 5.4 beta (apparently you can't pass null to CommandBuffer::DrawMesh now). if (!_SelectableMesh || !GroundMaterial) return; var cam = Camera.current; if (!cam || cam.cameraType == CameraType.Preview || ((1 << gameObject.layer) & Camera.current.cullingMask) == 0) return; CommandBuffer buf = null; if (cameras.ContainsKey(cam)) return; buf = new CommandBuffer(); // Note: Mesh is drawn slightly pushed upwards to avoid z-fighting issues buf.DrawMesh(_SelectableMesh, Matrix4x4.TRS(Vector3.up * 0.005f, Quaternion.identity, Vector3.one), GroundMaterial, 0); cameras[cam] = buf; cam.AddCommandBuffer(CameraEvent.AfterForwardOpaque, buf); }
void UpdateCommandBuffer() { var cam = GetComponent<Camera>(); RenderSettings.fogColor = m_fog_color; if (m_quad == null) { m_quad = RaymarcherUtils.GenerateQuad(); } bool reflesh_command_buffer = false; Vector2 reso = new Vector2(cam.pixelWidth, cam.pixelHeight); if(m_resolution_prev!=reso) { m_resolution_prev = reso; reflesh_command_buffer = true; } if (m_enable_adaptive_prev != m_enable_adaptive) { m_enable_adaptive_prev = m_enable_adaptive; reflesh_command_buffer = true; } if (m_dbg_show_steps_prev != m_dbg_show_steps) { m_dbg_show_steps_prev = m_dbg_show_steps; reflesh_command_buffer = true; } if (reflesh_command_buffer) { reflesh_command_buffer = false; ClearCommandBuffer(); } if (m_cb_raymarch==null) { if (m_enable_adaptive) { RenderTargetIdentifier[] rt; m_cb_prepass = new CommandBuffer(); m_cb_prepass.name = "Raymarcher Adaptive PrePass"; int odepth = Shader.PropertyToID("ODepth"); int odepth_prev = Shader.PropertyToID("ODepthPrev"); int ovelocity = Shader.PropertyToID("OVelocity"); int qdepth = Shader.PropertyToID("QDepth"); int qdepth_prev = Shader.PropertyToID("QDepthPrev"); int hdepth = Shader.PropertyToID("HDepth"); int hdepth_prev = Shader.PropertyToID("HDepthPrev"); int adepth = Shader.PropertyToID("ADepth"); int adepth_prev = Shader.PropertyToID("ADepthPrev"); m_cb_prepass.GetTemporaryRT(odepth, cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(odepth_prev,cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(ovelocity, cam.pixelWidth / 8, cam.pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RHalf); m_cb_prepass.GetTemporaryRT(qdepth, cam.pixelWidth / 4, cam.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(qdepth_prev,cam.pixelWidth / 4, cam.pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth, cam.pixelWidth / 2, cam.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(hdepth_prev,cam.pixelWidth / 2, cam.pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth, cam.pixelWidth / 1, cam.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); m_cb_prepass.GetTemporaryRT(adepth_prev,cam.pixelWidth / 1, cam.pixelHeight / 1, 0, FilterMode.Point, RenderTextureFormat.RFloat); rt = new RenderTargetIdentifier[2] { odepth, ovelocity }; m_cb_prepass.SetGlobalTexture("g_depth_prev", odepth_prev); m_cb_prepass.SetRenderTarget(rt, odepth); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 1); m_cb_prepass.Blit(odepth, odepth_prev); m_cb_prepass.SetGlobalTexture("g_velocity", ovelocity); m_cb_prepass.SetRenderTarget(qdepth); m_cb_prepass.SetGlobalTexture("g_depth", odepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", qdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 2); m_cb_prepass.Blit(qdepth, qdepth_prev); m_cb_prepass.SetRenderTarget(hdepth); m_cb_prepass.SetGlobalTexture("g_depth", qdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", hdepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 3); m_cb_prepass.Blit(hdepth, hdepth_prev); m_cb_prepass.SetRenderTarget(adepth); m_cb_prepass.SetGlobalTexture("g_depth", hdepth); m_cb_prepass.SetGlobalTexture("g_depth_prev", adepth_prev); m_cb_prepass.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 4); m_cb_prepass.Blit(adepth, adepth_prev); m_cb_prepass.SetGlobalTexture("g_depth", adepth); cam.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_prepass); } m_cb_raymarch = new CommandBuffer(); m_cb_raymarch.name = "Raymarcher"; m_cb_raymarch.DrawMesh(m_quad, Matrix4x4.identity, m_internal_material, 0, 0); cam.AddCommandBuffer(CameraEvent.BeforeGBuffer, m_cb_raymarch); } }
internal override void RenderVectors( Camera camera, CommandBuffer renderCB, float scale, AmplifyMotion.Quality quality ) { if ( m_initialized && !m_error && m_meshRenderer.isVisible ) { Profiler.BeginSample( "Solid.Render" ); bool mask = ( m_owner.Instance.CullingMask & ( 1 << m_obj.gameObject.layer ) ) != 0; if ( !mask || ( mask && m_moved ) ) { const float rcp255 = 1 / 255.0f; int objectId = mask ? m_owner.Instance.GenerateObjectId( m_obj.gameObject ) : 255; Matrix4x4 prevModelViewProj; if ( m_obj.FixedStep ) prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_currLocalToWorld; else prevModelViewProj = m_owner.PrevViewProjMatrixRT * m_prevLocalToWorld; renderCB.SetGlobalMatrix( "_AM_MATRIX_PREV_MVP", prevModelViewProj ); renderCB.SetGlobalFloat( "_AM_OBJECT_ID", objectId * rcp255 ); renderCB.SetGlobalFloat( "_AM_MOTION_SCALE", mask ? scale : 0 ); // TODO: cache property blocks int qualityPass = ( quality == AmplifyMotion.Quality.Mobile ) ? 0 : 2; for ( int i = 0; i < m_sharedMaterials.Length; i++ ) { MaterialDesc matDesc = m_sharedMaterials[ i ]; int pass = qualityPass + ( matDesc.coverage ? 1 : 0 ); if ( matDesc.coverage ) { Texture mainTex = matDesc.material.mainTexture; if ( mainTex != null ) matDesc.propertyBlock.SetTexture( "_MainTex", mainTex ); if ( matDesc.cutoff ) matDesc.propertyBlock.SetFloat( "_Cutoff", matDesc.material.GetFloat( "_Cutoff" ) ); } renderCB.DrawMesh( m_mesh, m_transform.localToWorldMatrix, m_owner.Instance.SolidVectorsMaterial, i, pass, matDesc.propertyBlock ); } } Profiler.EndSample(); } }
static public int DrawMesh(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 4) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); self.DrawMesh(a1, a2, a3); return(0); } else if (argc == 5) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); self.DrawMesh(a1, a2, a3, a4); return(0); } else if (argc == 6) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); self.DrawMesh(a1, a2, a3, a4, a5); return(0); } else if (argc == 7) { UnityEngine.Rendering.CommandBuffer self = (UnityEngine.Rendering.CommandBuffer)checkSelf(l); UnityEngine.Mesh a1; checkType(l, 2, out a1); UnityEngine.Matrix4x4 a2; checkValueType(l, 3, out a2); UnityEngine.Material a3; checkType(l, 4, out a3); System.Int32 a4; checkType(l, 5, out a4); System.Int32 a5; checkType(l, 6, out a5); UnityEngine.MaterialPropertyBlock a6; checkType(l, 7, out a6); self.DrawMesh(a1, a2, a3, a4, a5, a6); return(0); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
internal override void RenderVectors(Camera camera, CommandBuffer renderCB, float scale, Quality quality) { if (this.m_initialized && !this.m_error && this.m_meshRenderer.isVisible) { bool flag = (this.m_owner.Instance.CullingMask & 1 << this.m_obj.gameObject.layer) != 0; if (!flag || (flag && this.m_moved)) { int num = (!flag) ? 255 : this.m_owner.Instance.GenerateObjectId(this.m_obj.gameObject); Matrix4x4 value; if (this.m_obj.FixedStep) { value = this.m_owner.PrevViewProjMatrixRT * this.m_currLocalToWorld; } else { value = this.m_owner.PrevViewProjMatrixRT * this.m_prevLocalToWorld; } renderCB.SetGlobalMatrix("_AM_MATRIX_PREV_MVP", value); renderCB.SetGlobalFloat("_AM_OBJECT_ID", (float)num * 0.003921569f); renderCB.SetGlobalFloat("_AM_MOTION_SCALE", (!flag) ? 0f : scale); int num2 = (quality != Quality.Mobile) ? 2 : 0; for (int i = 0; i < this.m_sharedMaterials.Length; i++) { MotionState.MaterialDesc materialDesc = this.m_sharedMaterials[i]; int shaderPass = num2 + ((!materialDesc.coverage) ? 0 : 1); if (materialDesc.coverage) { Texture mainTexture = materialDesc.material.mainTexture; if (mainTexture != null) { materialDesc.propertyBlock.SetTexture("_MainTex", mainTexture); } if (materialDesc.cutoff) { materialDesc.propertyBlock.SetFloat("_Cutoff", materialDesc.material.GetFloat("_Cutoff")); } } renderCB.DrawMesh(this.m_mesh, this.m_transform.localToWorldMatrix, this.m_owner.Instance.SolidVectorsMaterial, i, shaderPass, materialDesc.propertyBlock); } } } }
void InitializeContext() { m_num_video_frames = 0; // initialize scratch buffer UpdateScratchBuffer(); // initialize context and stream { m_mp4conf = fcAPI.fcMP4Config.default_value; m_mp4conf.video = m_captureVideo; m_mp4conf.audio = m_captureAudio; m_mp4conf.video_width = m_scratch_buffer.width; m_mp4conf.video_height = m_scratch_buffer.height; m_mp4conf.video_max_framerate = 60; m_mp4conf.video_bitrate = m_videoBitrate; m_mp4conf.audio_bitrate = m_audioBitrate; m_mp4conf.audio_sampling_rate = AudioSettings.outputSampleRate; m_mp4conf.audio_num_channels = fcAPI.fcGetNumAudioChannels(); m_ctx = fcAPI.fcMP4CreateContext(ref m_mp4conf); m_output_file = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4"; m_ostream = fcAPI.fcCreateFileStream(GetOutputPath()); fcAPI.fcMP4AddOutputStream(m_ctx, m_ostream); } // initialize command buffer { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "MP4Recorder: copy frame buffer"; m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb.SetRenderTarget(m_scratch_buffer); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb.ReleaseTemporaryRT(tid); } }
internal override void RenderVectors( Camera camera, CommandBuffer renderCB, float scale, AmplifyMotion.Quality quality ) { Profiler.BeginSample( "Particle.Render" ); // TODO: batch if ( m_initialized && !m_error && m_renderer.isVisible ) { bool mask = ( m_owner.Instance.CullingMask & ( 1 << m_obj.gameObject.layer ) ) != 0; if ( !mask || ( mask && m_moved ) ) { const float rcp255 = 1 / 255.0f; int objectId = mask ? m_owner.Instance.GenerateObjectId( m_obj.gameObject ) : 255; renderCB.SetGlobalFloat( "_AM_OBJECT_ID", objectId * rcp255 ); renderCB.SetGlobalFloat( "_AM_MOTION_SCALE", mask ? scale : 0 ); int qualityPass = ( quality == AmplifyMotion.Quality.Mobile ) ? 0 : 2; for ( int i = 0; i < m_sharedMaterials.Length; i++ ) { MaterialDesc matDesc = m_sharedMaterials[ i ]; int pass = qualityPass + ( matDesc.coverage ? 1 : 0 ); if ( matDesc.coverage ) { Texture mainTex = matDesc.material.mainTexture; if ( mainTex != null ) matDesc.propertyBlock.SetTexture( "_MainTex", mainTex ); if ( matDesc.cutoff ) matDesc.propertyBlock.SetFloat( "_Cutoff", matDesc.material.GetFloat( "_Cutoff" ) ); } var enumerator = m_particleDict.GetEnumerator(); while ( enumerator.MoveNext() ) { KeyValuePair<uint, Particle> pair = enumerator.Current; Matrix4x4 prevModelViewProj = m_owner.PrevViewProjMatrixRT * pair.Value.prevLocalToWorld; renderCB.SetGlobalMatrix( "_AM_MATRIX_PREV_MVP", prevModelViewProj ); renderCB.DrawMesh( m_mesh, pair.Value.currLocalToWorld, m_owner.Instance.SolidVectorsMaterial, i, pass, matDesc.propertyBlock ); } } } } Profiler.EndSample(); }