/// <summary> /// Execute the DrawRenderers with parameters setup from the editor /// </summary> /// <param name="renderContext"></param> /// <param name="cmd"></param> /// <param name="camera"></param> /// <param name="cullingResult"></param> protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult) { ShaderTagId[] shaderPasses = new ShaderTagId[hdrpShaderTags.Count + ((overrideMaterial != null) ? 1 : 0)]; System.Array.Copy(hdrpShaderTags.ToArray(), shaderPasses, hdrpShaderTags.Count); if (overrideMaterial != null) { shaderPasses[hdrpShaderTags.Count] = new ShaderTagId(overrideMaterial.GetPassName(overrideMaterialPassIndex)); overrideMaterial.SetFloat(fadeValueId, fadeValue); } if (shaderPasses.Length == 0) { Debug.LogWarning("Attempt to call DrawRenderers with an empty shader passes. Skipping the call to avoid errors"); return; } var stateBlock = new RenderStateBlock(overrideDepthState ? RenderStateMask.Depth : 0) { depthState = new DepthState(depthWrite, depthCompareFunction), }; var result = new RendererListDesc(shaderPasses, cullingResult, hdCamera.camera) { rendererConfiguration = PerObjectData.None, renderQueueRange = GetRenderQueueRange(renderQueueType), sortingCriteria = sortingCriteria, excludeObjectMotionVectors = false, overrideMaterial = (overrideMaterial != null) ? overrideMaterial : defaultOverrideMaterial, overrideMaterialPassIndex = (overrideMaterial != null) ? overrideMaterialPassIndex : 0, stateBlock = stateBlock, layerMask = layerMask, }; HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(result)); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerTag); var shaderTag = new ShaderTagId("DepthOnly"); var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(shaderTag, ref renderingData, sortFlags); drawSettings.perObjectData = PerObjectData.None; if (renderingData.cameraData.isStereoEnabled) { context.StartMultiEye(renderingData.cameraData.camera); } drawSettings.overrideMaterial = material; context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings); cmd.SetGlobalTexture("_CameraDepthNormalsTexture", depthNormalsHandle.id); context.ExecuteCommandBuffer(cmd); cmd.Clear(); CommandBufferPool.Release(cmd); }
public override void Start() { base.Start(); // SegmentationCameraSensor always use JpegQuality = 100 JpegQuality = 100; SensorCamera.GetComponent <HDAdditionalCameraData>().customRender += CustomRender; passId = new ShaderTagId("SimulatorSegmentationPass"); // passId = new ShaderTagId("GBuffer"); if (InstanceSegmentationTags.Count > 0) { // Check if instance segmentation has been set (either by Editor or by another SegmentationCamera). if (SimulatorManager.Instance.CheckInstanceSegmentationSetting()) { // TODO: Change both semantic segmentation and instance segmentation from global to per camera. // so that this error can be removed. Debug.LogError("Instance segmentation has been set for some tags. Please only load SegmentationCamera once!"); } foreach (InstanceCandidateTags tag in InstanceSegmentationTags) { SimulatorManager.Instance.SetInstanceColor(tag.ToString()); } SimulatorManager.Instance.ResetSegmentationColors(); } }
protected override void Execute(CustomPassContext ctx) { if (!ctx.hdCamera.frameSettings.IsEnabled(FrameSettingsField.ObjectMotionVectors) || !ctx.hdCamera.frameSettings.IsEnabled(FrameSettingsField.OpaqueObjects)) { Debug.Log("Motion Vectors are disabled on the camera!"); return; } SyncRenderTextureAspect(motionVectorTexture, ctx.hdCamera.camera); var tags = new ShaderTagId("MotionVectors"); var motionVectorRendererListDesc = new RendererListDesc(tags, ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = PerObjectData.MotionVectors, renderQueueRange = RenderQueueRange.all, sortingCriteria = SortingCriteria.BackToFront, excludeObjectMotionVectors = false, layerMask = renderingMask }; if (ctx.hdCamera.msaaSamples != MSAASamples.None) { CoreUtils.SetRenderTarget(ctx.cmd, new RenderTargetIdentifier[] { dummy.colorBuffer, motionVectorTexture }, dummy.depthBuffer, ClearFlag.All); } else { CoreUtils.SetRenderTarget(ctx.cmd, new RenderTargetIdentifier[] { motionVectorTexture }, motionVectorTexture.depthBuffer, ClearFlag.All); } RendererList motionVectorsRendererList = RendererList.Create(motionVectorRendererListDesc); CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, motionVectorsRendererList); }
// This function is called from the custom post process at the before post process injection point, just after TAA public void RenderVideoObjects(CommandBuffer cmd) { // Fix depth buffer jittering if (fixDepthBufferJittering) { using (new ProfilingScope(cmd, new ProfilingSampler("Render Depth Buffer without jittering"))) { // We need to re-render everything to get the non-jittered depth buffer :/ CoreUtils.SetRenderTarget(cmd, videoDepthBuffer); CoreUtils.ClearRenderTarget(cmd, ClearFlag.Depth, Color.black); var tags = new ShaderTagId[] { new ShaderTagId("DepthForwardOnly"), new ShaderTagId("DepthOnly") }; var result = new RendererListDesc(tags, context.cullingResults, context.hdCamera.camera) { rendererConfiguration = PerObjectData.None, renderQueueRange = RenderQueueRange.all, sortingCriteria = SortingCriteria.CommonOpaque, excludeObjectMotionVectors = false, layerMask = fixDepthBufferJitteringMask, // stateBlock = overrideRenderState, }; CoreUtils.DrawRendererList(context.renderContext, context.cmd, RendererList.Create(result)); } } // TODO: add an option to render the "frame" objects in the unjittered depth-buffer to avoid flickering CoreUtils.SetRenderTarget(cmd, videoColorBuffer, fixDepthBufferJittering ? videoDepthBuffer : context.cameraDepthBuffer, ClearFlag.Color); var renderState = new RenderStateBlock(RenderStateMask.Depth) { depthState = new DepthState(false, CompareFunction.LessEqual) }; CustomPassUtils.DrawRenderers(context, videoObjectMask, overrideRenderState: renderState); }
/// <summary> /// Execute the DrawRenderers with parameters setup from the editor /// </summary> /// <param name="renderContext"></param> /// <param name="cmd"></param> /// <param name="camera"></param> /// <param name="cullingResult"></param> protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult) { ShaderTagId[] shaderPasses = new ShaderTagId[hdrpShaderTags.Count + ((overrideMaterial != null) ? 1 : 0)]; System.Array.Copy(hdrpShaderTags.ToArray(), shaderPasses, hdrpShaderTags.Count); if (overrideMaterial != null) { shaderPasses[hdrpShaderTags.Count] = new ShaderTagId(overrideMaterial.GetPassName(overrideMaterialPassIndex)); } if (shaderPasses.Length == 0) { Debug.LogWarning("Attempt to call DrawRenderers with an empty shader passes. Skipping the call to avoid errors"); return; } var result = new RendererListDesc(shaderPasses, cullingResult, hdCamera.camera) { rendererConfiguration = PerObjectData.None, renderQueueRange = GetRenderQueueRange(renderQueueType), sortingCriteria = sortingCriteria, excludeObjectMotionVectors = true, overrideMaterial = overrideMaterial, overrideMaterialPassIndex = overrideMaterialPassIndex, layerMask = layerMask, }; HDUtils.DrawRendererList(renderContext, cmd, RendererList.Create(result)); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer gbufferCommands = CommandBufferPool.Get(); using (new ProfilingScope(gbufferCommands, m_ProfilingSampler)) { // User can stack several scriptable renderers during rendering but deferred renderer should only lit pixels added by this gbuffer pass. // If we detect we are in such case (camera isin overlay mode), we clear the highest bits of stencil we have control of and use them to // mark what pixel to shade during deferred pass. Gbuffer will always mark pixels using their material types. if (m_DeferredLights.IsOverlay) { m_DeferredLights.ClearStencilPartial(gbufferCommands); } context.ExecuteCommandBuffer(gbufferCommands); gbufferCommands.Clear(); ref CameraData cameraData = ref renderingData.cameraData; Camera camera = cameraData.camera; ShaderTagId lightModeTag = s_ShaderTagUniversalGBuffer; DrawingSettings drawingSettings = CreateDrawingSettings(lightModeTag, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags); ShaderTagId universalMaterialTypeTag = s_ShaderTagUniversalMaterialType; NativeArray <ShaderTagId> tagValues = new NativeArray <ShaderTagId>(m_ShaderTagValues, Allocator.Temp); NativeArray <RenderStateBlock> stateBlocks = new NativeArray <RenderStateBlock>(m_RenderStateBlocks, Allocator.Temp); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings, universalMaterialTypeTag, false, tagValues, stateBlocks); tagValues.Dispose(); stateBlocks.Dispose(); // Render objects that did not match any shader pass with error shader RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None); }
protected override void Initialize() { base.Initialize(); passId = new ShaderTagId("SimulatorDepthPass"); CameraTargetTextureReadWriteType = RenderTextureReadWrite.Linear; SensorCamera.GetComponent <HDAdditionalCameraData>().customRender += CustomRender; }
public GBufferPass(RenderPassEvent evt, RenderQueueRange renderQueueRange, LayerMask layerMask, StencilState stencilState, int stencilReference, DeferredLights deferredLights) { base.profilingSampler = new ProfilingSampler(nameof(GBufferPass)); base.renderPassEvent = evt; m_DeferredLights = deferredLights; m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask); m_RenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing); m_RenderStateBlock.stencilState = stencilState; m_RenderStateBlock.stencilReference = stencilReference; m_RenderStateBlock.mask = RenderStateMask.Stencil; m_ShaderTagValues = new ShaderTagId[4]; m_ShaderTagValues[0] = s_ShaderTagLit; m_ShaderTagValues[1] = s_ShaderTagSimpleLit; m_ShaderTagValues[2] = s_ShaderTagUnlit; m_ShaderTagValues[3] = new ShaderTagId(); // Special catch all case for materials where UniversalMaterialType is not defined or the tag value doesn't match anything we know. m_RenderStateBlocks = new RenderStateBlock[4]; m_RenderStateBlocks[0] = DeferredLights.OverwriteStencil(m_RenderStateBlock, (int)StencilUsage.MaterialMask, (int)StencilUsage.MaterialLit); m_RenderStateBlocks[1] = DeferredLights.OverwriteStencil(m_RenderStateBlock, (int)StencilUsage.MaterialMask, (int)StencilUsage.MaterialSimpleLit); m_RenderStateBlocks[2] = DeferredLights.OverwriteStencil(m_RenderStateBlock, (int)StencilUsage.MaterialMask, (int)StencilUsage.MaterialUnlit); m_RenderStateBlocks[3] = m_RenderStateBlocks[0]; }
public Render2DObjectPass(Renderer2DData rendererData, RenderPassEvent renderPassEvent, string[] lightModeTags, RenderQueueType renderQueueType, int layerMask, RenderObjects.CustomCameraSettings cameraSettings) { renderFeaturePassTag = "RenderFeature " + lightModeTags[0]; //Draw setting 相关流程 this.renderPassEvent = renderPassEvent; this.renderQueueType = renderQueueType; RenderQueueRange renderQueueRange = (renderQueueType == RenderQueueType.Transparent) ? RenderQueueRange.transparent : RenderQueueRange.opaque; m_FilteringSettings = new FilteringSettings(renderQueueRange, layerMask); if (s_SortingLayers == null) { s_SortingLayers = SortingLayer.layers; } this.m_CameraSettings = cameraSettings; //Tag for (int i = 0; i < lightModeTags.Length; i++) { var tag = lightModeTags[i]; ShaderTagId sid = new ShaderTagId(tag); k_ShaderTags.Add(sid); } // m_Renderer2DData = rendererData; }
public DistortionRenderPass(DistortionSettings settings) { renderPassEvent = settings.renderPassEvent; targetTextureID = Shader.PropertyToID(settings.textureID); tempRTID = Shader.PropertyToID("_TempRT"); isRenderingObject = settings.isRenderingObject; shaderTagID = new ShaderTagId(settings.shaderTagID); }
public RendererListDesc(ShaderTagId passName, CullingResults cullingResult, Camera camera) : this() { this.passName = passName; this.passNames = null; this.cullingResult = cullingResult; this.camera = camera; }
/// <summary> /// Configures the pass. /// </summary> /// <param name="baseDescriptor">The <c>RenderTextureDescriptor</c> used for the depthStencilFormat.</param> /// <param name="depthAttachmentHandle">The <c>RTHandle</c> used to render to.</param> /// <seealso cref="RenderTextureDescriptor"/> /// <seealso cref="RTHandle"/> /// <seealso cref="GraphicsFormat"/> public void Setup( RenderTextureDescriptor baseDescriptor, RTHandle depthAttachmentHandle) { this.destination = depthAttachmentHandle; this.depthStencilFormat = baseDescriptor.depthStencilFormat; this.shaderTagId = k_ShaderTagId; }
public DrawObjectsRenderPass(RenderPassEvent passEvent, bool opaque, RenderQueueRange range, SortingCriteria criteria) { renderPassEvent = passEvent; isOpaque = opaque; sortingCriteria = criteria; filteringSettings = new FilteringSettings(range); shaderTagId = ShaderTags.ForwardBase; }
public RenderToTexturePass(RenderToTexture.Settings param) { this.filteringSettings = new FilteringSettings(RenderQueueRange.all, param.layerMask); this.material = param.material; this.shaderTagId = new ShaderTagId(param.passName); this.cmdName = param.cmdName; this.textureName = param.textureName; this.clearColor = param.clearColor; }
public RenderShadowTexturePass(DynamicShadowProjectorRendererData data) { renderPassEvent = RenderPassEvent.AfterRenderingTransparents; m_shaderTagIds = new ShaderTagId[data.m_sceneObjectShaderTagList.Length]; for (int i = 0; i < data.m_sceneObjectShaderTagList.Length; ++i) { m_shaderTagIds[i] = new ShaderTagId(data.m_sceneObjectShaderTagList[i]); } }
void RenderOpaque(ScriptableRenderContext context, ShaderTagId shaderTagId, SortingSettings sortingSettings) { LogTrace("RenderOpaque..."); DrawingSettings drawSettings = new DrawingSettings(shaderTagId, sortingSettings); FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.opaque); drawSettings.perObjectData = rendererConfiguration_shading; context.DrawRenderers(m_CullResults, ref drawSettings, ref filteringSettings); }
/// <summary> /// RendererListDesc constructor /// </summary> /// <param name="passName">Pass name used for this renderer list.</param> /// <param name="cullingResult">Culling result used to create the renderer list.</param> /// <param name="camera">Camera used to determine sorting parameters.</param> public RendererListDesc(ShaderTagId passName, CullingResults cullingResult, Camera camera) : this() { this.passName = passName; this.passNames = null; this.cullingResult = cullingResult; this.camera = camera; this.layerMask = -1; this.overrideMaterialPassIndex = 0; }
private void DrawCharacter(ScriptableRenderContext context, Camera camera, ShaderTagId pass, SortingSettings sortFlags) { var settings = new DrawingSettings(pass, sortFlags); settings.enableInstancing = true; settings.enableDynamicBatching = true; var filterSettings = new FilteringSettings(RenderQueueRange.transparent, 1 << LayerDefine.CHARA, 1 << LayerDefine.CHARA); context.DrawRenderers(cull, ref settings, ref filterSettings); }
public virtual void Init() { var hd = SensorCamera.GetComponent <HDAdditionalCameraData>(); hd.hasPersistentHistory = true; hd.customRender += CustomRender; PointCloudMaterial = new Material(RuntimeSettings.Instance.PointCloudShader); PointCloudLayer = LayerMask.NameToLayer("Sensor Effects"); passId = new ShaderTagId("SimulatorLidarPass"); Reset(); }
public OutlineRenderPass(Setting setting) { shaderTagId = new ShaderTagId("UniversalForward"); passSetting = setting; Shader shader = Shader.Find("MyUrp/UrpOutline"); if (shader) { outlineMaterial = new Material(shader); } }
protected override void Initialize() { SensorCamera.enabled = false; passId = new ShaderTagId("SimulatorLidarPass"); cs = Instantiate(computeShader); PointCloudMaterial = new Material(RuntimeSettings.Instance.PointCloudShader); HDAdditionalCameraData.hasPersistentHistory = true; HDAdditionalCameraData.customRender += CustomRender; ReadbackPool = new GpuReadbackPool <GpuReadbackData <Vector4>, Vector4>(); ReadbackPool.Initialize(GetTotalRayCount(), OnReadbackComplete); Reset(); }
public GodRayRenderPass(Setting setting) { occluderTexHandle.Init("_OccluderTexture"); shaderTagId = new ShaderTagId("UniversalForward"); passSetting = setting; Shader godRayShader = Shader.Find("Urp/UrpGodRayShader"); if (godRayShader) { godRayMaterial = new Material(godRayShader); } }
void Render( ScriptableRenderContext context, Camera camera) { ScriptableCullingParameters cullingParameters; if (!camera.TryGetCullingParameters(out cullingParameters)) { return; } #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { // ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif cullingResults = context.Cull(ref cullingParameters); context.SetupCameraProperties(camera, stereoSetup: false); FillCommandBuffer(camera); context.ExecuteCommandBuffer(commandBuffer); commandBuffer.Clear(); var tagId = new ShaderTagId("Main"); var drawingSettings = new DrawingSettings(tagId, new SortingSettings(camera)); drawingSettings.mainLightIndex = 0; var filteringSettings = new FilteringSettings(); // filteringSettings.excludeMotionVectorObjects = false; filteringSettings.layerMask = -1; filteringSettings.renderQueueRange = RenderQueueRange.opaque; filteringSettings.renderingLayerMask = 0xffffffff; // filteringSettings.sortingLayerRange = SortingLayerRange.all; context.DrawRenderers( cullingResults, ref drawingSettings, ref filteringSettings); // 空は不透明パスの最後 context.DrawSkybox(camera); // 透明パス filteringSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers( cullingResults, ref drawingSettings, ref filteringSettings); context.Submit(); }
/// <summary> /// Configure the pass /// </summary> public void Setup( RenderTextureDescriptor baseDescriptor, RenderTargetHandle depthAttachmentHandle) { this.depthAttachmentHandle = depthAttachmentHandle; baseDescriptor.colorFormat = RenderTextureFormat.Depth; baseDescriptor.depthBufferBits = k_DepthBufferBits; // Depth-Only pass don't use MSAA baseDescriptor.msaaSamples = 1; descriptor = baseDescriptor; this.allocateDepth = true; this.shaderTagId = k_ShaderTagId; }
public void Setup(Shader shader, ScriptableRenderer renderer, RenderPassEvent renderPassEvent) { if (material == null) { material = CoreUtils.CreateEngineMaterial(shader); } source = renderer.cameraColorTarget; // Configures where the render pass should be injected. this.renderPassEvent = renderPassEvent; m_ShaderTagId = new ShaderTagId("UniversalForward"); m_FilteringSettings = new FilteringSettings(RenderQueueRange.opaque, layerMask: -1); m_RenderStateBlock = new RenderStateBlock(RenderStateMask.Nothing); }
public ShaderTagId FindPassTagValue(int passIndex, ShaderTagId tagName) { bool flag = passIndex < 0 || passIndex >= this.passCount; if (flag) { throw new ArgumentOutOfRangeException("passIndex"); } int id = this.Internal_FindPassTagValue(passIndex, tagName.id); return(new ShaderTagId { id = id }); }
public VolumetricLightRenderPass(Setting setting) { volumetricHandle.Init("_Volumetric"); lowResDepthHandle.Init("_LowResDepth"); compositingHandle.Init("_Compositing"); shaderTagId = new ShaderTagId("UniversalForward"); dualKawaseIds = null; passSetting = setting; Shader volumetricLightShader = Shader.Find("Urp/UrpVolumetricLightShader"); if (volumetricLightShader) { volumetricLightMaterial = new Material(volumetricLightShader); } }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("RenderMask"); RenderQueueRange renderQueueRange = RenderQueueRange.all; FilteringSettings filters = new FilteringSettings(renderQueueRange); filters.layerMask = LayerMask.GetMask(new string[] { "ViewMasks" }); List <ShaderTagId> m_ShaderTagIdList = new List <ShaderTagId>(); m_ShaderTagIdList.Add(new ShaderTagId("LightweightForward")); m_ShaderTagIdList.Add(new ShaderTagId("SRPDefaultUnlit")); ShaderTagId id = new ShaderTagId("Opaque"); DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, SortingCriteria.CommonOpaque); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filters); }
protected override void Setup(ScriptableRenderContext ctx, CommandBuffer cmd) { _shaderTagId_JTRPMask = new ShaderTagId("JTRPMask"); _shaderTagId_JTRPFace = new ShaderTagId("JTRPFace"); _customBuffer = RTHandles.Alloc( scaleFactor: Vector2.one, colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R32_SFloat, name: "JTRP Mask Buffer", autoGenerateMips: false ); // if (ShaderConfig.s_CameraRelativeRendering != 0) // _ras.Build(Camera.current.transform.position); // else // _ras.Build(); }