// At the beginning of the renderpass, clear this attachment with the given clear color (or depth/stencil) public void ConfigureClear(Color clearColor, float clearDepth = 1.0f, uint clearStencil = 0) { m_ClearColor = clearColor; m_ClearDepth = clearDepth; m_ClearStencil = clearStencil; m_LoadAction = RenderBufferLoadAction.Clear; }
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depthBuffer, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction, ClearFlag clearFlag, Color clearColor) { cmd.SetRenderTarget(colorBuffer, colorLoadAction, colorStoreAction, depthBuffer, depthLoadAction, depthStoreAction); ClearRenderTarget(cmd, clearFlag, clearColor); }
internal static void Blit(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, Material material, int passIndex = 0, bool useDrawProcedural = false, RenderBufferLoadAction colorLoadAction = RenderBufferLoadAction.Load, RenderBufferStoreAction colorStoreAction = RenderBufferStoreAction.Store, RenderBufferLoadAction depthLoadAction = RenderBufferLoadAction.Load, RenderBufferStoreAction depthStoreAction = RenderBufferStoreAction.Store) { cmd.SetGlobalTexture(ShaderPropertyId.sourceTex, source); if (useDrawProcedural) { Vector4 scaleBias = new Vector4(1, 1, 0, 0); Vector4 scaleBiasRt = new Vector4(1, 1, 0, 0); cmd.SetGlobalVector(ShaderPropertyId.scaleBias, scaleBias); cmd.SetGlobalVector(ShaderPropertyId.scaleBiasRt, scaleBiasRt); cmd.SetRenderTarget(new RenderTargetIdentifier(destination, 0, CubemapFace.Unknown, -1), colorLoadAction, colorStoreAction, depthLoadAction, depthStoreAction); cmd.DrawProcedural(Matrix4x4.identity, material, passIndex, MeshTopology.Quads, 4, 1, null); } else { cmd.SetRenderTarget(destination, colorLoadAction, colorStoreAction, depthLoadAction, depthStoreAction); cmd.Blit(source, BuiltinRenderTextureType.CurrentActive, material, passIndex); } }
internal static void Blit(CommandBuffer cmd, RTHandle source, RTHandle destination, Material material, int passIndex = 0, bool useDrawProcedural = false, RenderBufferLoadAction colorLoadAction = RenderBufferLoadAction.Load, RenderBufferStoreAction colorStoreAction = RenderBufferStoreAction.Store, RenderBufferLoadAction depthLoadAction = RenderBufferLoadAction.Load, RenderBufferStoreAction depthStoreAction = RenderBufferStoreAction.Store) { cmd.SetGlobalTexture(ShaderPropertyId.sourceTex, source); if (useDrawProcedural) { Vector4 scaleBias = new Vector4(1, 1, 0, 0); Vector4 scaleBiasRt = new Vector4(1, 1, 0, 0); cmd.SetGlobalVector(ShaderPropertyId.scaleBias, scaleBias); cmd.SetGlobalVector(ShaderPropertyId.scaleBiasRt, scaleBiasRt); CoreUtils.SetRenderTarget(cmd, destination, colorLoadAction, colorStoreAction, ClearFlag.None, Color.clear); cmd.DrawProcedural(Matrix4x4.identity, material, passIndex, MeshTopology.Quads, 4, 1, null); } else { CoreUtils.SetRenderTarget(cmd, destination, colorLoadAction, colorStoreAction, ClearFlag.None, Color.clear); cmd.Blit(source.nameID, BuiltinRenderTextureType.CurrentActive, material, passIndex); } }
protected void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor) { if (colorAttachmentHandle != RenderTargetHandle.CameraTarget) { if (depthAttachmentHandle != RenderTargetHandle.CameraTarget) { SetRenderTarget( cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, depthAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); } else { SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); } } else { SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); } }
internal static void SetRenderTargetImpl(RenderTargetSetup setup) { if (setup.color.Length == 0) { throw new ArgumentException("Invalid color buffer count for SetRenderTarget"); } if (setup.color.Length != setup.colorLoad.Length) { throw new ArgumentException("Color LoadAction and Buffer arrays have different sizes"); } if (setup.color.Length != setup.colorStore.Length) { throw new ArgumentException("Color StoreAction and Buffer arrays have different sizes"); } RenderBufferLoadAction[] colorLoad = setup.colorLoad; for (int i = 0; i < colorLoad.Length; i++) { RenderBufferLoadAction load = colorLoad[i]; Graphics.CheckLoadActionValid(load, "Color"); } RenderBufferStoreAction[] colorStore = setup.colorStore; for (int j = 0; j < colorStore.Length; j++) { RenderBufferStoreAction store = colorStore[j]; Graphics.CheckStoreActionValid(store, "Color"); } Graphics.CheckLoadActionValid(setup.depthLoad, "Depth"); Graphics.CheckStoreActionValid(setup.depthStore, "Depth"); if (setup.cubemapFace < CubemapFace.Unknown || setup.cubemapFace > CubemapFace.NegativeZ) { throw new ArgumentException("Bad CubemapFace provided"); } Graphics.Internal_SetMRTFullSetup(setup.color, out setup.depth, setup.mipLevel, setup.cubemapFace, setup.colorLoad, setup.colorStore, setup.depthLoad, setup.depthStore); }
internal static void CheckLoadActionValid(RenderBufferLoadAction load, string bufferType) { if ((load != RenderBufferLoadAction.Load) && (load != RenderBufferLoadAction.DontCare)) { throw new ArgumentException("Bad " + bufferType + " LoadAction"); } }
public void ConfigureClear(Color clearColor, float clearDepth = 1f, uint clearStencil = 0u) { this.m_ClearColor = clearColor; this.m_ClearDepth = clearDepth; this.m_ClearStencil = clearStencil; this.m_LoadAction = RenderBufferLoadAction.Clear; }
internal static void CheckLoadActionValid(RenderBufferLoadAction load, string bufferType) { if (load != 0 && load != RenderBufferLoadAction.DontCare) { throw new ArgumentException(UnityString.Format("Bad {0} LoadAction provided.", bufferType)); } }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag); using (new ProfilingSample(cmd, k_RenderTransparentsTag)) { RenderBufferLoadAction loadOp = RenderBufferLoadAction.Load; RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store; SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, depthAttachmentHandle.Identifier(), loadOp, storeOp, ClearFlag.None, Color.black, descriptor.dimension); context.ExecuteCommandBuffer(cmd); cmd.Clear(); Camera camera = renderingData.cameraData.camera; var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, renderingData.supportsDynamicBatching); context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_TransparentFilterSettings); // Render objects that did not match any shader pass with error shader renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_TransparentFilterSettings, SortFlags.None); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
protected static void SetRenderTarget( CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depthAttachment, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction, ClearFlag clearFlags, Color clearColor, TextureDimension dimension) { if (depthAttachment == BuiltinRenderTextureType.CameraTarget) { SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, clearFlags, clearColor, dimension); } else { if (dimension == TextureDimension.Tex2DArray) { CoreUtils.SetRenderTarget(cmd, colorAttachment, depthAttachment, clearFlags, clearColor, 0, CubemapFace.Unknown, -1); } else { CoreUtils.SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, depthAttachment, depthLoadAction, depthStoreAction, clearFlags, clearColor); } } }
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag); using (new ProfilingSample(cmd, k_RenderOpaquesTag)) { RenderBufferLoadAction loadOp = RenderBufferLoadAction.DontCare; RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store; SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, depthAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); // TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT // (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color. // For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system //if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport) // cmd.SetViewport(camera.pixelRect); context.ExecuteCommandBuffer(cmd); cmd.Clear(); Camera camera = renderingData.cameraData.camera; var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawRendererSettings(camera, sortFlags, rendererConfiguration, renderingData.supportsDynamicBatching); context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_OpaqueFilterSettings); // Render objects that did not match any shader pass with error shader renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_OpaqueFilterSettings, SortFlags.None); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
internal static void CheckLoadActionValid(RenderBufferLoadAction load, string bufferType) { if ((load != RenderBufferLoadAction.Load) && (load != RenderBufferLoadAction.DontCare)) { object[] args = new object[] { bufferType }; throw new ArgumentException(UnityString.Format("Bad {0} LoadAction provided.", args)); } }
public void SetRenderTarget(RenderTargetIdentifier rt, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction) { if (loadAction == RenderBufferLoadAction.Clear) { throw new ArgumentException("RenderBufferLoadAction.Clear is not supported"); } SetRenderTargetSingle_Internal(rt, loadAction, storeAction, loadAction, storeAction); }
public void SetRenderTarget(RenderTargetIdentifier rt, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction) { ValidateAgainstExecutionFlags(CommandBufferExecutionFlags.None, CommandBufferExecutionFlags.AsyncCompute); if (loadAction == RenderBufferLoadAction.Clear) { throw new ArgumentException("RenderBufferLoadAction.Clear is not supported"); } SetRenderTargetSingle_Internal(rt, loadAction, storeAction, loadAction, storeAction); }
public void SetRenderTarget(RenderTargetIdentifier color, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depth, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { if (colorLoadAction == RenderBufferLoadAction.Clear || depthLoadAction == RenderBufferLoadAction.Clear) { throw new ArgumentException("RenderBufferLoadAction.Clear is not supported"); } SetRenderTargetColorDepth_Internal(color, depth, colorLoadAction, colorStoreAction, depthLoadAction, depthStoreAction); }
internal static RenderBufferLoadAction[] LoadActions(RenderBuffer[] buf) { RenderBufferLoadAction[] bufferLoadActionArray = new RenderBufferLoadAction[buf.Length]; for (int index = 0; index < buf.Length; ++index) { bufferLoadActionArray[index] = buf[index].loadAction; buf[index].loadAction = RenderBufferLoadAction.Load; } return(bufferLoadActionArray); }
public RenderTargetBinding(RenderTargetIdentifier[] colorRenderTargets, RenderBufferLoadAction[] colorLoadActions, RenderBufferStoreAction[] colorStoreActions, RenderTargetIdentifier depthRenderTarget, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { this.m_ColorRenderTargets = colorRenderTargets; this.m_DepthRenderTarget = depthRenderTarget; this.m_ColorLoadActions = colorLoadActions; this.m_ColorStoreActions = colorStoreActions; this.m_DepthLoadAction = depthLoadAction; this.m_DepthStoreAction = depthStoreAction; this.m_Flags = RenderTargetFlags.None; }
/// <summary> /// Sets the current render target using specified <see cref="RenderBufferLoadAction"/>. /// </summary> /// <param name="cmd">The command buffer to set the render target on</param> /// <param name="rt">The render target to set</param> /// <param name="loadAction">The load action</param> /// <param name="storeAction">The store action</param> /// <param name="depthLoadAction">The load action for the depth/stencil part of rt</param> /// <param name="depthStoreAction">The store action for the depth/stencil part of rt</param> /// <remarks> /// <see cref="RenderBufferLoadAction"/> are only used on Unity 2018.2 or newer. /// </remarks> public static void SetRenderTargetWithLoadStoreAction(CommandBuffer cmd, RenderTargetIdentifier rt, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { #if UNITY_2018_2_OR_NEWER cmd.SetRenderTarget(rt, loadAction, storeAction, depthLoadAction, depthStoreAction); #else cmd.SetRenderTarget(rt); #endif }
internal static RenderBufferLoadAction[] LoadActions(RenderBuffer[] buf) { RenderBufferLoadAction[] array = new RenderBufferLoadAction[buf.Length]; for (int i = 0; i < buf.Length; i++) { array[i] = buf[i].loadAction; buf[i].loadAction = RenderBufferLoadAction.Load; } return array; }
public void SetRenderTarget(RenderTargetIdentifier color, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depth, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { ValidateAgainstExecutionFlags(CommandBufferExecutionFlags.None, CommandBufferExecutionFlags.AsyncCompute); if (colorLoadAction == RenderBufferLoadAction.Clear || depthLoadAction == RenderBufferLoadAction.Clear) { throw new ArgumentException("RenderBufferLoadAction.Clear is not supported"); } SetRenderTargetColorDepth_Internal(color, depth, colorLoadAction, colorStoreAction, depthLoadAction, depthStoreAction); }
internal static RenderBufferLoadAction[] LoadActions(RenderBuffer[] buf) { RenderBufferLoadAction[] actionArray = new RenderBufferLoadAction[buf.Length]; for (int i = 0; i < buf.Length; i++) { actionArray[i] = buf[i].loadAction; buf[i].loadAction = RenderBufferLoadAction.Load; } return(actionArray); }
public AttachmentDescriptor(GraphicsFormat format) : this() { m_LoadAction = RenderBufferLoadAction.DontCare; m_StoreAction = RenderBufferStoreAction.DontCare; m_Format = format; m_LoadStoreTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.None); m_ResolveTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.None); m_ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f); m_ClearDepth = 1.0f; }
internal RenderTargetSetup(RenderBuffer[] color, RenderBuffer depth, int mip, int face, RenderBufferLoadAction[] colorLoad, RenderBufferStoreAction[] colorStore, RenderBufferLoadAction depthLoad, RenderBufferStoreAction depthStore) { this.color = color; this.depth = depth; this.mipLevel = mip; this.cubemapFace = face; this.colorLoad = colorLoad; this.colorStore = colorStore; this.depthLoad = depthLoad; this.depthStore = depthStore; }
public AttachmentDescriptor(GraphicsFormat format) { this = default(AttachmentDescriptor); this.m_LoadAction = RenderBufferLoadAction.DontCare; this.m_StoreAction = RenderBufferStoreAction.DontCare; this.m_Format = format; this.m_LoadStoreTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.None); this.m_ResolveTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.None); this.m_ClearColor = new Color(0f, 0f, 0f, 0f); this.m_ClearDepth = 1f; }
public RenderTargetBinding(RenderTargetIdentifier[] colorRenderTargets, RenderBufferLoadAction[] colorLoadActions, RenderBufferStoreAction[] colorStoreActions, RenderTargetIdentifier depthRenderTarget, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { m_ColorRenderTargets = colorRenderTargets; m_DepthRenderTarget = depthRenderTarget; m_ColorLoadActions = colorLoadActions; m_ColorStoreActions = colorStoreActions; m_DepthLoadAction = depthLoadAction; m_DepthStoreAction = depthStoreAction; }
public RenderTargetBinding(RenderTargetIdentifier colorRenderTarget, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depthRenderTarget, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction) { this = new RenderTargetBinding(new RenderTargetIdentifier[] { colorRenderTarget }, new RenderBufferLoadAction[] { colorLoadAction }, new RenderBufferStoreAction[] { colorStoreAction }, depthRenderTarget, depthLoadAction, depthStoreAction); }
private void BlitFullscreenTriangle(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, int pass /*, bool clear = false*/) { cmd.SetGlobalTexture(MAIN_TEX, source); //RenderBufferLoadAction loadAction = clear ? RenderBufferLoadAction.Clear : RenderBufferLoadAction.DontCare; RenderBufferLoadAction loadAction = RenderBufferLoadAction.DontCare; cmd.SetRenderTarget(destination, loadAction, RenderBufferStoreAction.Store); //if (clear) // cmd.ClearRenderTarget(true, true, Color.clear); cmd.DrawMesh(this.triangle, Matrix4x4.identity, this.blitMaterial, 0, pass); }
protected static void SetRenderTarget( CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, ClearFlag clearFlag, Color clearColor, TextureDimension dimension) { if (dimension == TextureDimension.Tex2DArray) CoreUtils.SetRenderTarget(cmd, colorAttachment, clearFlag, clearColor, 0, CubemapFace.Unknown, -1); else CoreUtils.SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, clearFlag, clearColor); }
public RenderTargetBinding(RenderTargetSetup setup) { this.m_ColorRenderTargets = new RenderTargetIdentifier[setup.color.Length]; for (int i = 0; i < this.m_ColorRenderTargets.Length; i++) { this.m_ColorRenderTargets[i] = new RenderTargetIdentifier(setup.color[i], setup.mipLevel, setup.cubemapFace, setup.depthSlice); } this.m_DepthRenderTarget = setup.depth; this.m_ColorLoadActions = (RenderBufferLoadAction[])setup.colorLoad.Clone(); this.m_ColorStoreActions = (RenderBufferStoreAction[])setup.colorStore.Clone(); this.m_DepthLoadAction = setup.depthLoad; this.m_DepthStoreAction = setup.depthStore; this.m_Flags = RenderTargetFlags.None; }
protected void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor) { SetRenderTarget( cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, depthAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension); }
internal static RenderBufferLoadAction[] LoadActions(RenderBuffer[] buf) { RenderBufferLoadAction[] bufferLoadActionArray = new RenderBufferLoadAction[buf.Length]; for (int index = 0; index < buf.Length; ++index) { bufferLoadActionArray[index] = buf[index].loadAction; buf[index].loadAction = RenderBufferLoadAction.Load; } return bufferLoadActionArray; }
internal static void CheckLoadActionValid(RenderBufferLoadAction load, string bufferType) { if (load != RenderBufferLoadAction.Load && load != RenderBufferLoadAction.DontCare) throw new ArgumentException(UnityString.Format("Bad {0} LoadAction provided.", (object) bufferType)); }
private static extern void Internal_SetMRTFullSetup(RenderBuffer[] colorSA, out RenderBuffer depth, int mip, CubemapFace face, RenderBufferLoadAction[] colorLoadSA, RenderBufferStoreAction[] colorStoreSA, RenderBufferLoadAction depthLoad, RenderBufferStoreAction depthStore);
private static extern void Internal_SetRTFullSetup(out RenderBuffer color, out RenderBuffer depth, int mip, int face, RenderBufferLoadAction colorLoad, RenderBufferStoreAction colorStore, RenderBufferLoadAction depthLoad, RenderBufferStoreAction depthStore);
internal void SetLoadAction(RenderBufferLoadAction action) { RenderBufferHelper.SetLoadAction(out this, (int) action); }