Here are the examples of the csharp api UnityEngine.Rendering.CommandBuffer.DrawMesh(UnityEngine.Mesh, UnityEngine.Matrix4x4, UnityEngine.Material) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
12 Examples
19
View Source File : OutlineRenderer.cs
License : MIT License
Project Creator : Arvtesh
License : MIT License
Project Creator : Arvtesh
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Blit(RenderTargetIdentifier src, int shaderPreplaced, Material mat, MaterialPropertyBlock props)
{
// Set source texture as _MainTex to match Blit behavior.
_commandBuffer.SetGlobalTexture(_resources.MainTexId, src);
// NOTE: SystemInfo.graphicsShaderLevel check is not enough sometimes (esp. on mobiles), so there is SystemInfo.supportsInstancing
// check and a flag for forcing DrawMesh.
if (SystemInfo.graphicsShaderLevel >= 35 && SystemInfo.supportsInstancing && !_resources.UseFullscreenTriangleMesh)
{
_commandBuffer.DrawProcedural(Matrix4x4.idenreplacedy, mat, shaderPreplaced, MeshTopology.Triangles, 3, 1, props);
}
else
{
_commandBuffer.DrawMesh(_resources.FullscreenTriangleMesh, Matrix4x4.idenreplacedy, mat, 0, shaderPreplaced, props);
}
}
19
View Source File : WaveformWindow.cs
License : MIT License
Project Creator : BattleDawnNZ
License : MIT License
Project Creator : BattleDawnNZ
public void RenderWaveform(Texture2D source)
{
if (mWaveformMaterial == null)
return;
int width = source.width;
int height = source.height;
int histogramResolution = 256;
mThreadGroupSize = 256;
mThreadGroupSizeX = 16;
mThreadGroupSizeY = 16;
CreateBuffers(width, histogramResolution);
mCmd.Clear();
mCmd.BeginSample("CMWaveform");
var parameters = new Vector4(
width, height,
QualitySettings.activeColorSpace == ColorSpace.Linear ? 1 : 0,
histogramResolution);
// Clear the buffer on every frame
int kernel = mWaveformCompute.FindKernel("KCMWaveformClear");
mCmd.SetComputeBufferParam(mWaveformCompute, kernel, "_WaveformBuffer", mData);
mCmd.SetComputeVectorParam(mWaveformCompute, "_Params", parameters);
mCmd.DispatchCompute(mWaveformCompute, kernel,
Mathf.CeilToInt(width / (float)mThreadGroupSizeX),
Mathf.CeilToInt(histogramResolution / (float)mThreadGroupSizeY), 1);
// Gather all pixels and fill in our waveform
kernel = mWaveformCompute.FindKernel("KCMWaveformGather");
mCmd.SetComputeBufferParam(mWaveformCompute, kernel, "_WaveformBuffer", mData);
mCmd.SetComputeTextureParam(mWaveformCompute, kernel, "_Source", source);
mCmd.SetComputeVectorParam(mWaveformCompute, "_Params", parameters);
mCmd.DispatchCompute(mWaveformCompute, kernel, width,
Mathf.CeilToInt(height / (float)mThreadGroupSize), 1);
// Generate the waveform texture
float exposure = Mathf.Max(0f, m_Exposure);
exposure *= (float)histogramResolution / height;
mWaveformProperties.SetVector(Shader.PropertyToID("_Params"),
new Vector4(width, histogramResolution, exposure, 0f));
mWaveformProperties.SetBuffer(Shader.PropertyToID("_WaveformBuffer"), mData);
mCmd.SetRenderTarget(mOutput);
mCmd.DrawMesh(
FullscreenTriangle, Matrix4x4.idenreplacedy,
mWaveformMaterial, 0, 0, mWaveformProperties);
mCmd.EndSample("CMWaveform");
Graphics.ExecuteCommandBuffer(mCmd);
}
19
View Source File : AmplifyOcclusionEffect.cs
License : GNU General Public License v3.0
Project Creator : brandonmousseau
License : GNU General Public License v3.0
Project Creator : brandonmousseau
void PerformBlit( CommandBuffer cb, Material mat, int preplaced )
{
cb.DrawMesh( m_quadMesh, Matrix4x4.idenreplacedy, mat, 0, preplaced );
}
19
View Source File : SoftMask.cs
License : GNU General Public License v3.0
Project Creator : FluffyFishGames
License : GNU General Public License v3.0
Project Creator : FluffyFishGames
void UpdateMaskTexture()
{
if (!graphic || !graphic.canvas)
{
return;
}
_stencilDepth = MaskUtilities.GetStencilDepth(transform, MaskUtilities.FindRootSortOverrideCanvas(transform));
// Collect children soft masks.
int depth = 0;
s_TmpSoftMasks[0].Add(this);
while (_stencilDepth + depth < 3)
{
int count = s_TmpSoftMasks[depth].Count;
for (int i = 0; i < count; i++)
{
List<SoftMask> children = s_TmpSoftMasks[depth][i]._children;
int childCount = children.Count;
for (int j = 0; j < childCount; j++)
{
var child = children[j];
var childDepth = child.m_PartOfParent ? depth : depth + 1;
s_TmpSoftMasks[childDepth].Add(child);
}
}
depth++;
}
// Clear.
_cb.Clear();
_cb.SetRenderTarget(softMaskBuffer);
_cb.ClearRenderTarget(false, true, s_ClearColors[_stencilDepth]);
// Set view and projection matrices.
var c = graphic.canvas.rootCanvas;
var cam = c.worldCamera ?? Camera.main;
if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam)
{
_cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, GL.GetGPUProjectionMatrix(cam.projectionMatrix, false));
}
else
{
var pos = c.transform.position;
var vm = Matrix4x4.TRS(new Vector3(-pos.x, -pos.y, -1000), Quaternion.idenreplacedy, new Vector3(1, 1, -1f));
var pm = Matrix4x4.TRS(new Vector3(0, 0, -1), Quaternion.idenreplacedy, new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f));
_cb.SetViewProjectionMatrices(vm, pm);
}
// Draw soft masks.
for (int i = 0; i < s_TmpSoftMasks.Length; i++)
{
int count = s_TmpSoftMasks[i].Count;
for (int j = 0; j < count; j++)
{
var sm = s_TmpSoftMasks[i][j];
if (i != 0)
{
sm._stencilDepth = MaskUtilities.GetStencilDepth(sm.transform, MaskUtilities.FindRootSortOverrideCanvas(sm.transform));
}
// Set material property.
sm.material.SetInt(s_ColorMaskId, (int)1 << (3 - _stencilDepth - i));
sm._mpb.SetTexture(s_MainTexId, sm.graphic.mainTexture);
sm._mpb.SetFloat(s_SoftnessId, sm.m_Softness);
sm._mpb.SetFloat(s_Alpha, sm.m_Alpha);
// Draw mesh.
_cb.DrawMesh(sm.mesh, sm.transform.localToWorldMatrix, sm.material, 0, 0, sm._mpb);
}
s_TmpSoftMasks[i].Clear();
}
Graphics.ExecuteCommandBuffer(_cb);
}
19
View Source File : TerrainPatches.cs
License : MIT License
Project Creator : ontrigger
License : MIT License
Project Creator : ontrigger
private void UpdateCommandBuffer()
{
if (shadowCasterPreplaced == -1)
{
shadowCasterPreplaced = heightmap.m_materialInstance.FindPreplaced("ShadowCaster");
}
terrainTransform.SetTRS(heightmap.transform.position, Quaternion.idenreplacedy, Vector3.one);
shadowPreplacedCommandBuffer.Clear();
//shadowPreplacedCommandBuffer.SetRenderTarget(BuiltinRenderTextureType.CurrentActive);
shadowPreplacedCommandBuffer.DrawMesh(
heightmap.m_renderMesh, terrainTransform,
heightmap.m_materialInstance, 0, shadowCasterPreplaced);
}
19
View Source File : BuiltinDebugViewsComponent.cs
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
void MotionVectorsPreplaced(CommandBuffer cb)
{
#if UNITY_EDITOR
// Don't render motion vectors preview when the editor is not playing as it can in some
// cases results in ugly artifacts (i.e. when resizing the game view).
if (!Application.isPlaying)
return;
#endif
var material = context.materialFactory.Get(k_ShaderString);
var settings = model.settings.motionVectors;
// Blit the original source image
int tempRT = Uniforms._TempRT;
cb.GetTemporaryRT(tempRT, context.width, context.height, 0, FilterMode.Bilinear);
cb.SetGlobalFloat(Uniforms._Opacity, settings.sourceOpacity);
cb.SetGlobalTexture(Uniforms._MainTex, BuiltinRenderTextureType.CameraTarget);
cb.Blit(BuiltinRenderTextureType.CameraTarget, tempRT, material, (int)Preplaced.MovecOpacity);
// Motion vectors (imaging)
if (settings.motionImageOpacity > 0f && settings.motionImageAmplitude > 0f)
{
int tempRT2 = Uniforms._TempRT2;
cb.GetTemporaryRT(tempRT2, context.width, context.height, 0, FilterMode.Bilinear);
cb.SetGlobalFloat(Uniforms._Opacity, settings.motionImageOpacity);
cb.SetGlobalFloat(Uniforms._Amplitude, settings.motionImageAmplitude);
cb.SetGlobalTexture(Uniforms._MainTex, tempRT);
cb.Blit(tempRT, tempRT2, material, (int)Preplaced.MovecImaging);
cb.ReleaseTemporaryRT(tempRT);
tempRT = tempRT2;
}
// Motion vectors (arrows)
if (settings.motionVectorsOpacity > 0f && settings.motionVectorsAmplitude > 0f)
{
PrepareArrows();
float sy = 1f / settings.motionVectorsResolution;
float sx = sy * context.height / context.width;
cb.SetGlobalVector(Uniforms._Scale, new Vector2(sx, sy));
cb.SetGlobalFloat(Uniforms._Opacity, settings.motionVectorsOpacity);
cb.SetGlobalFloat(Uniforms._Amplitude, settings.motionVectorsAmplitude);
cb.DrawMesh(m_Arrows.mesh, Matrix4x4.idenreplacedy, material, 0, (int)Preplaced.MovecArrows);
}
cb.SetGlobalTexture(Uniforms._MainTex, tempRT);
cb.Blit(tempRT, BuiltinRenderTextureType.CameraTarget);
cb.ReleaseTemporaryRT(tempRT);
}
19
View Source File : AmbientOcclusionComponent.cs
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
public override void PopulateCommandBuffer(CommandBuffer cb)
{
var settings = model.settings;
// Material setup
var blitMaterial = context.materialFactory.Get(k_BlitShaderString);
var material = context.materialFactory.Get(k_ShaderString);
material.shaderKeywords = null;
material.SetFloat(Uniforms._Intensity, settings.intensity);
material.SetFloat(Uniforms._Radius, settings.radius);
material.SetFloat(Uniforms._Downsample, settings.downsampling ? 0.5f : 1f);
material.SetInt(Uniforms._SampleCount, (int)settings.sampleCount);
if (!context.isGBufferAvailable && RenderSettings.fog)
{
material.SetVector(Uniforms._FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
switch (RenderSettings.fogMode)
{
case FogMode.Linear:
material.EnableKeyword("FOG_LINEAR");
break;
case FogMode.Exponential:
material.EnableKeyword("FOG_EXP");
break;
case FogMode.ExponentialSquared:
material.EnableKeyword("FOG_EXP2");
break;
}
}
else
{
material.EnableKeyword("FOG_OFF");
}
int tw = context.width;
int th = context.height;
int ts = settings.downsampling ? 2 : 1;
const RenderTextureFormat kFormat = RenderTextureFormat.ARGB32;
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite.Linear;
const FilterMode kFilter = FilterMode.Bilinear;
// AO buffer
var rtMask = Uniforms._OcclusionTexture1;
cb.GetTemporaryRT(rtMask, tw / ts, th / ts, 0, kFilter, kFormat, kRWMode);
// AO estimation
cb.Blit((Texture)null, rtMask, material, (int)occlusionSource);
// Blur buffer
var rtBlur = Uniforms._OcclusionTexture2;
// Separable blur (horizontal preplaced)
cb.GetTemporaryRT(rtBlur, tw, th, 0, kFilter, kFormat, kRWMode);
cb.SetGlobalTexture(Uniforms._MainTex, rtMask);
cb.Blit(rtMask, rtBlur, material, occlusionSource == OcclusionSource.GBuffer ? 4 : 3);
cb.ReleaseTemporaryRT(rtMask);
// Separable blur (vertical preplaced)
rtMask = Uniforms._OcclusionTexture;
cb.GetTemporaryRT(rtMask, tw, th, 0, kFilter, kFormat, kRWMode);
cb.SetGlobalTexture(Uniforms._MainTex, rtBlur);
cb.Blit(rtBlur, rtMask, material, 5);
cb.ReleaseTemporaryRT(rtBlur);
if (context.profile.debugViews.IsModeActive(DebugMode.AmbientOcclusion))
{
cb.SetGlobalTexture(Uniforms._MainTex, rtMask);
cb.Blit(rtMask, BuiltinRenderTextureType.CameraTarget, material, 8);
context.Interrupt();
}
else if (ambientOnlySupported)
{
cb.SetRenderTarget(m_MRT, BuiltinRenderTextureType.CameraTarget);
cb.DrawMesh(GraphicsUtils.quad, Matrix4x4.idenreplacedy, material, 0, 7);
}
else
{
var fbFormat = context.isHdr ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
int tempRT = Uniforms._TempRT;
cb.GetTemporaryRT(tempRT, context.width, context.height, 0, FilterMode.Bilinear, fbFormat);
cb.Blit(BuiltinRenderTextureType.CameraTarget, tempRT, blitMaterial, 0);
cb.SetGlobalTexture(Uniforms._MainTex, tempRT);
cb.Blit(tempRT, BuiltinRenderTextureType.CameraTarget, material, 6);
cb.ReleaseTemporaryRT(tempRT);
}
cb.ReleaseTemporaryRT(rtMask);
}
19
View Source File : MotionBlurComponent.cs
License : MIT License
Project Creator : PacktPublishing
License : MIT License
Project Creator : PacktPublishing
public void MakeRecord(CommandBuffer cb, RenderTargetIdentifier source, int width, int height, Material material)
{
Release();
lumaTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear);
chromaTexture = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear);
lumaTexture.filterMode = FilterMode.Point;
chromaTexture.filterMode = FilterMode.Point;
if (m_MRT == null)
m_MRT = new RenderTargetIdentifier[2];
m_MRT[0] = lumaTexture;
m_MRT[1] = chromaTexture;
cb.SetGlobalTexture(Uniforms._MainTex, source);
cb.SetRenderTarget(m_MRT, lumaTexture);
cb.DrawMesh(GraphicsUtils.quad, Matrix4x4.idenreplacedy, material, 0, (int)Preplaced.FrameCompression);
m_Time = Time.time;
}
19
View Source File : MultiPassCamera.cs
License : Apache License 2.0
Project Creator : sintefneodroid
License : Apache License 2.0
Project Creator : sintefneodroid
void Setup() {
if (!this.gui_style) {
this.gui_style = Resources.FindObjectsOfTypeAll<GUISkin>().First(a => a.name == "BoundingBox");
}
this._all_renders = FindObjectsOfType<Renderer>();
if (this._capture_preplacedes == null || this._capture_preplacedes.Length == 0 || this.always_re) {
this._capture_preplacedes = new[] {
new CapturePreplacedMaterial(CameraEvent.AfterDepthTexture,
BuiltinRenderTextureType.Depth) {
_SupportsAntialiasing
= false,
_RenderTexture
= this
.depthRenderTexture
},
new CapturePreplacedMaterial(CameraEvent.AfterForwardAlpha,
BuiltinRenderTextureType.MotionVectors) {
_SupportsAntialiasing
= false,
_RenderTexture
= this
.flowRenderTexture
},
new CapturePreplacedMaterial(CameraEvent.AfterForwardAlpha,
BuiltinRenderTextureType.None) {
_SupportsAntialiasing
= false,
_RenderTexture
= this
.objectIdRenderTexture,
_TextureId
= Shader
.PropertyToID("_TmpFrameBuffer")
},
new CapturePreplacedMaterial(CameraEvent.AfterDepthTexture,
BuiltinRenderTextureType.None) {
_SupportsAntialiasing
= false,
_RenderTexture
= this
.tagIdRenderTexture,
_TextureId
= Shader
.PropertyToID("_CameraDepthTexture")
}
};
}
if (this.m_quad == null) {
this.m_quad = CreateFullscreenQuad();
}
this._camera = this.GetComponent<Camera>();
//this._camera.SetReplacementShader(this.uberMaterial.shader,"");
this._camera.RemoveAllCommandBuffers(); // cleanup capturing camera
this._camera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
foreach (var capture_preplaced in this._capture_preplacedes) {
var cb = new CommandBuffer {name = capture_preplaced.Source.ToString()};
cb.Clear();
if (capture_preplaced._Material) {
cb.GetTemporaryRT(capture_preplaced._TextureId,
-1,
-1,
0,
FilterMode.Point);
//cb.Blit(capture_preplaced.Source, capture_preplaced._RenderTexture, capture_preplaced._Material);
cb.Blit(capture_preplaced.Source, capture_preplaced._TextureId);
cb.SetRenderTarget(new RenderTargetIdentifier[] {capture_preplaced._RenderTexture},
capture_preplaced._RenderTexture);
cb.DrawMesh(this.m_quad,
Matrix4x4.idenreplacedy,
capture_preplaced._Material,
0,
0);
cb.ReleaseTemporaryRT(capture_preplaced._TextureId);
} else {
cb.Blit(capture_preplaced.Source, capture_preplaced._RenderTexture);
}
this._camera.AddCommandBuffer(capture_preplaced.When, cb);
}
this.CheckBlock();
foreach (var r in this._all_renders) {
r.GetPropertyBlock(this._block);
var sm = r.sharedMaterial;
if (sm) {
var id = sm.GetInstanceID();
var color = ColorEncoding.EncodeIdAsColor(id);
this._block.SetColor(SynthesisUtilities._Shader_MaterialId_Color_Name, color);
r.SetPropertyBlock(this._block);
}
}
}
19
View Source File : UberCamera.cs
License : Apache License 2.0
Project Creator : sintefneodroid
License : Apache License 2.0
Project Creator : sintefneodroid
void Setup() {
if (this.copy_shader == null) {
Debug.LogError("Copy shader is missing!");
return;
}
if (this._off_screen_mat != null) {
if (this._camera.targetTexture != null) {
this._off_screen_mat.EnableKeyword("OFFSCREEN");
} else {
this._off_screen_mat.DisableKeyword("OFFSCREEN");
}
}
this._copy_fb_cb = new CommandBuffer {name = "Copy FrameBuffer"};
this._copy_fb_cb.GetTemporaryRT(this._tmp_texture_id,
-1,
-1,
0,
FilterMode.Point);
this._copy_fb_cb.Blit(BuiltinRenderTextureType.CurrentActive, this._tmp_texture_id);
this._copy_fb_cb.SetRenderTarget(this._m_rt_gb_ids, this._fb_rts[0]);
this._copy_fb_cb.DrawMesh(this._quad_mesh,
Matrix4x4.idenreplacedy,
this._copy_material,
0,
0);
this._copy_fb_cb.ReleaseTemporaryRT(this._tmp_texture_id);
this._camera.AddCommandBuffer(CameraEvent.AfterEverything, this._copy_fb_cb);
this._clear_gb_cb = new CommandBuffer {
name = "Cleanup GBuffer"
}; // clear gbuffer (Unity doesn't clear emission buffer - it is not needed usually)
if (this._camera.allowHDR) {
this._clear_gb_cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
} else {
this._clear_gb_cb.SetRenderTarget(BuiltinRenderTextureType.GBuffer3);
}
this._clear_gb_cb.DrawMesh(this._quad_mesh,
Matrix4x4.idenreplacedy,
this._copy_material,
0,
3);
this._copy_material.SetColor(_clear_color, this._camera.backgroundColor);
this._copy_gb_cb = new CommandBuffer {name = "Copy GBuffer"}; // copy gbuffer
this._copy_gb_cb.SetRenderTarget(this._m_rt_fb_ids, this._gb_rts[0]);
this._copy_gb_cb.DrawMesh(this._quad_mesh,
Matrix4x4.idenreplacedy,
this._copy_material,
0,
2);
this._camera.AddCommandBuffer(CameraEvent.BeforeGBuffer, this._clear_gb_cb);
this._camera.AddCommandBuffer(CameraEvent.BeforeLighting, this._copy_gb_cb);
this._copy_velocity_cb = new CommandBuffer {name = "Copy Velocity"};
this._copy_velocity_cb.SetRenderTarget(this._gb_rts[7]);
this._copy_velocity_cb.DrawMesh(this._quad_mesh,
Matrix4x4.idenreplacedy,
this._copy_material,
0,
4);
this._camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, this._copy_velocity_cb);
this._camera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
this._copy_cbs = new[] {
this._copy_fb_cb,
this._clear_gb_cb,
this._copy_gb_cb,
this._copy_velocity_cb
};
}
19
View Source File : ScriptableRenderer.cs
License : MIT License
Project Creator : TheSlippyPenguin
License : MIT License
Project Creator : TheSlippyPenguin
public static void RenderFullscreenQuad(CommandBuffer cmd, Material material, MaterialPropertyBlock properties = null, int shaderPreplacedId = 0)
{
if (cmd == null)
throw new ArgumentNullException("cmd");
cmd.DrawMesh(fullscreenMesh, Matrix4x4.idenreplacedy, material, 0, shaderPreplacedId, properties);
}
19
View Source File : MovieRecorder.cs
License : Apache License 2.0
Project Creator : Unity-Technologies
License : Apache License 2.0
Project Creator : Unity-Technologies
public bool BeginRecording(string videoName)
{
if (m_recording) { return false; }
if (m_shCopy == null)
{
Debug.LogError("MovieRecorder: copy shader is missing!");
return false;
}
if (m_captureTarget == CaptureTarget.RenderTexture && m_targetRT == null)
{
Debug.LogError("MovieRecorder: target RenderTexture is null!");
return false;
}
m_outputDir.CreateDirectory();
if (m_quad == null) m_quad = fcAPI.CreateFullscreenQuad();
if (m_matCopy == null) m_matCopy = new Material(m_shCopy);
var cam = GetComponent<Camera>();
if (cam.targetTexture != null)
{
m_matCopy.EnableKeyword("OFFSCREEN");
}
else
{
m_matCopy.DisableKeyword("OFFSCREEN");
}
// create scratch buffer
{
int captureWidth = cam.pixelWidth;
int captureHeight = cam.pixelHeight;
GetCaptureResolution(ref captureWidth, ref captureHeight);
if (m_encoderConfigs.format == MovieEncoder.Type.MP4 ||
m_encoderConfigs.format == MovieEncoder.Type.WebM)
{
captureWidth = (captureWidth + 1) & ~1;
captureHeight = (captureHeight + 1) & ~1;
}
m_scratchBuffer = new RenderTexture(captureWidth, captureHeight, 0, RenderTextureFormat.ARGB32);
m_scratchBuffer.wrapMode = TextureWrapMode.Repeat;
m_scratchBuffer.Create();
}
// initialize encoder
{
int targetFramerate = 60;
if(m_framerateMode == FrameRateMode.Constant)
{
targetFramerate = m_targetFramerate;
}
string outPath = m_outputDir.GetFullPath() + "/" + videoName;
m_encoderConfigs.captureVideo = m_captureVideo;
m_encoderConfigs.captureAudio = m_captureAudio;
m_encoderConfigs.Setup(m_scratchBuffer.width, m_scratchBuffer.height, 3, targetFramerate);
m_encoder = MovieEncoder.Create(m_encoderConfigs, outPath);
if (m_encoder == null || !m_encoder.IsValid())
{
EndRecording();
return false;
}
}
// create command buffer
{
int tid = Shader.PropertyToID("_TmpFrameBuffer");
m_cb = new CommandBuffer();
m_cb.name = "MovieRecorder: copy frame buffer";
if(m_captureTarget == CaptureTarget.FrameBuffer)
{
m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear);
m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid);
m_cb.SetRenderTarget(m_scratchBuffer);
m_cb.DrawMesh(m_quad, Matrix4x4.idenreplacedy, m_matCopy, 0, 0);
m_cb.ReleaseTemporaryRT(tid);
}
else if(m_captureTarget == CaptureTarget.RenderTexture)
{
m_cb.SetRenderTarget(m_scratchBuffer);
m_cb.SetGlobalTexture("_TmpRenderTarget", m_targetRT);
m_cb.DrawMesh(m_quad, Matrix4x4.idenreplacedy, m_matCopy, 0, 1);
}
cam.AddCommandBuffer(CameraEvent.AfterEverything, m_cb);
}
base.BeginRecording();
return true;
}