void OnEndFrameRendering(ScriptableRenderContext context, Camera[] cameras) { #if UNITY_EDITOR if (UnityEditor.EditorApplication.isPaused) { return; } #endif if (!cameras.Contains(m_CameraRenderingToSource)) { return; } if (m_NextFrameToCapture > Time.frameCount) { return; } m_NextFrameToCapture = Time.frameCount + 1; if (!GraphicsUtilities.SupportsAsyncReadback()) { RenderTexture.active = m_Source; m_CpuTexture.ReadPixels(new Rect( Vector2.zero, new Vector2(m_Source.width, m_Source.height)), 0, 0); RenderTexture.active = null; var data = m_CpuTexture.GetRawTextureData <T>(); m_ImageReadCallback(Time.frameCount, data, m_Source); return; } var commandBuffer = CommandBufferPool.Get("RenderTextureReader"); var frameCount = Time.frameCount; commandBuffer.RequestAsyncReadback(m_Source, r => OnGpuReadback(r, frameCount)); context.ExecuteCommandBuffer(commandBuffer); context.Submit(); CommandBufferPool.Release(commandBuffer); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (renderingData.lightData.mainLightIndex == -1) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_CollectShadowsTag); cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, FilterMode.Bilinear); // Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that // doesn't like null sources when trying to determine a stereo-ized blit. So for proper // stereo functionality, we use the screen-space shadow map as the source (until we have // a better solution). // An alternative would be DrawProcedural, but that would require further changes in the shader. RenderTargetIdentifier screenSpaceOcclusionTexture = colorAttachmentHandle.Identifier(); SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension); cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandle.ScreenSpaceShadow)); if (renderingData.cameraData.isStereoEnabled) { Camera camera = renderingData.cameraData.camera; context.StartMultiEye(camera); context.ExecuteCommandBuffer(cmd); context.StopMultiEye(camera); } else { context.ExecuteCommandBuffer(cmd); } CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } CommandBuffer cmd = CommandBufferPool.Get(k_CopyColorTag); Downsampling downsampling = renderingData.cameraData.opaqueTextureDownsampling; float opaqueScaler = m_OpaqueScalerValues[(int)downsampling]; RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData, opaqueScaler); RenderTargetIdentifier colorRT = source.Identifier(); RenderTargetIdentifier opaqueColorRT = destination.Identifier(); cmd.GetTemporaryRT(destination.id, opaqueDesc, renderingData.cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear); switch (downsampling) { case Downsampling.None: cmd.Blit(colorRT, opaqueColorRT); break; case Downsampling._2xBilinear: cmd.Blit(colorRT, opaqueColorRT); break; case Downsampling._4xBox: Material samplingMaterial = renderer.GetMaterial(MaterialHandle.Sampling); samplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2); cmd.Blit(colorRT, opaqueColorRT, samplingMaterial, 0); break; case Downsampling._4xBilinear: cmd.Blit(colorRT, opaqueColorRT); break; } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var material = GlitchMaterial; if (material == null) { return; } var cmd = CommandBufferPool.Get(FinalBlitPassTag); // Copy & Set MainTex. var camera = renderingData.cameraData.camera; var activeTexture = camera.activeTexture; cmd.Blit(activeTexture, _mainTexture); material.SetTexture(MainTexID, _mainTexture); // Calc Glitch. { _verticalJumpTime += Time.deltaTime * VerticalJump * 11.3f; var sl_thresh = Mathf.Clamp01(1.0f - ScanLineJitter * 1.2f); var sl_disp = 0.002f + Mathf.Pow(ScanLineJitter, 3) * 0.05f; material.SetVector(ScanLineJitterID, new Vector2(sl_disp, sl_thresh)); var vj = new Vector2(VerticalJump, _verticalJumpTime); material.SetVector(VerticalJumpID, vj); material.SetFloat(HorizontalShakeID, HorizontalShake * 0.2f); var cd = new Vector2(ColorDrift * 0.04f, Time.time * 606.11f); material.SetVector(ColorDriftID, cd); } cmd.Blit(_mainTexture, camera.activeTexture, material); // Execute CmdBuff. context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
// This is where the rendering happens. Notice that we are given a ScriptableRenderContext to perform rendering // with, as well as an array of cameras to render. Note that the ScriptableRenderContext works using a deferred // execution model, and rendering calls won't happen until we submit them. public override void Render(ScriptableRenderContext context, Camera[] cameras) { // The base class will do some checks for us, so remember to call into that one first. base.Render(context, cameras); // Loop over each camera to perform rendering for it. foreach (var camera in cameras) { // Perform culling using the current camera. The result of this is a handle to visible renderers (i.e. // Game Objects with a Renderer component), as well as lists of visible lights, reflection probes etc. if (!CullResults.Cull(camera, context, out m_CullResults)) { // If the culling fails, we ignore this camera and continue on to the next one. continue; } // This call makes the context extract various properties from the camera, and use it to set-up things // like render targets and shader variables. context.SetupCameraProperties(camera); { // A lot of things in SRP happens through CommandBuffers. Since they are classes we cannot create // new instances of them without allocating GC memory. To avoid that we can use the // CommandBufferPool to get an empty, existing CommandBuffer. We can tag each command buffer with a // name, which will show up both in the Frame Debugger, and RenderDoc. var cmd = CommandBufferPool.Get("Clear"); // Clear the current color buffer to black, as well as the current depth buffer. cmd.ClearRenderTarget(true, true, Color.black); // Execute the command buffer via the ScriptableRenderContext. context.ExecuteCommandBuffer(cmd); // While the execution doesn't happen immediately, the command buffer _is_ copied into internal // storage, and so we can safely release it back to the pool. CommandBufferPool.Release(cmd); } // Finally, we submit the calls we made for immediate execution. Note that you can do this any time you // want to. Typically it makes sense to do it per camera, but some times you might want to break it up. context.Submit(); } }
void RenderMainLightCascadeShadowmap(ref ScriptableRenderContext context, ref CullingResults cullResults, ref LightData lightData, ref ShadowData shadowData) { int shadowLightIndex = lightData.mainLightIndex; if (shadowLightIndex == -1) { return; } VisibleLight shadowLight = lightData.visibleLights[shadowLightIndex]; CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); cmd.SetGlobalDepthBias(shadowData.bias[shadowLightIndex].z, 0.0f);// shader do slope bias using (new ProfilingSample(cmd, m_ProfilerTag)) { var settings = new ShadowDrawingSettings(cullResults, shadowLightIndex); for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex) { var splitData = settings.splitData; splitData.cullingSphere = m_CascadeSplitDistances[cascadeIndex]; settings.splitData = splitData; Vector4 shadowBias = ShadowUtils.GetShadowBias(ref shadowLight, shadowLightIndex, ref shadowData, m_CascadeSlices[cascadeIndex].projectionMatrix, m_CascadeSlices[cascadeIndex].resolution); ShadowUtils.SetupShadowCasterConstantBuffer(cmd, ref shadowLight, shadowBias); ShadowUtils.RenderShadowSlice(cmd, ref context, ref m_CascadeSlices[cascadeIndex], ref settings, m_CascadeSlices[cascadeIndex].projectionMatrix, m_CascadeSlices[cascadeIndex].viewMatrix); } SetupMainLightShadowReceiverConstants(cmd, ref shadowData, shadowLight); } CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, true); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowCascades, shadowData.mainLightShadowCascadesCount > 1); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.SoftShadows, shadowLight.light.shadows == LightShadows.Soft && shadowData.supportsSoftShadows); cmd.SetGlobalDepthBias(0, 0); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(tag); cmd.Clear(); cmd.SetGlobalInt("_Width", downsampledCocTarget.width); cmd.SetGlobalInt("_Height", downsampledCocTarget.height); cmd.SetGlobalInt("_FullWidth", 4 * downsampledCocTarget.width); cmd.SetGlobalInt("_FullHeight", 4 * downsampledCocTarget.height); // Calculate CoC and downsample. cmd.Blit(cameraColorTarget, cameraTextureCopy); cmd.Blit(cameraTextureCopy, downsampledCocTarget, materialToBlit, 0); // Two-pass Gaussian blur (horizontal then vertical). cmd.Blit(downsampledCocTarget, tmpBlurTarget, materialToBlit, 1); cmd.Blit(tmpBlurTarget, blurredCocTarget, materialToBlit, 2); // Fix foreground silhouettes. // Note: |CommandBuffer.SetGlobalTexture| appears to not work when there are // *any* global properties exposed in the Properties block of the material shader. materialToBlit.SetTexture("_DownsampledCoc", downsampledCocTarget); materialToBlit.SetTexture("_BlurredCoc", blurredCocTarget); cmd.Blit(cameraTextureCopy, tmpBlurTarget, materialToBlit, 3); // Apply small blur to fix discontinuities. cmd.Blit(tmpBlurTarget, cocTarget, materialToBlit, 4); // Blit final composited image to camera texture. // Note: Sharp texture provided by |cameraColorTarget|. Small blur computed // in fragment shader. materialToBlit.SetTexture("_MediumBlur", cocTarget); materialToBlit.SetTexture("_LargeBlur", blurredCocTarget); cmd.Blit(cameraTextureCopy, cameraColorTarget, materialToBlit, 5); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(profilerTag); // TODO: Add a way to preview pulses without running the game // TODO: I doubt using a global variable is the best approach here, but I don't know how to // inject CommandBuffer from simulation code that can utilize the current game state. if (Main.pulses != null) { RenderTargetIdentifier src = source; RenderTargetIdentifier dst = temporaryRT; int pulseCount = Main.pulses.Count; for (int iPulse = 0; iPulse < pulseCount; iPulse++) { Pulse p = Main.pulses[iPulse]; // TODO: Is it possible to set material properties locally, rather then globally? float pulseDuration = Time.time - p.startTime; float distanceTravelled = pulseDuration * p.spec.travelSpeed; cmd.SetGlobalVector(pulsePositionId, p.startPosition); cmd.SetGlobalFloat(pulseDistanceId, distanceTravelled); Blit(cmd, src, dst, settings.blitMaterial); var temp = src; src = dst; dst = temp; } if (pulseCount % 2 == 1) { Blit(cmd, src, dst); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <summary> /// Custom rendering for clearing the background with the pass-thru video for AR happens here. We use the parameters passed in via setup /// to create command buffer that clears the render target and blits to it using the clear material. /// </summary> /// <param name="renderer"> The ScriptableRenderer that is being used. </param> /// <param name="context"> The ScriptableRenderContext used to execute the command buffer that we create. </param> /// <param name="renderingData"> RenderingData (unused here). </param> /// <exception cref="ArgumentNullException"> Throw this exception if the renderer is null. </exception> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } var cmd = CommandBufferPool.Get(k_ARBlitTag); RenderBufferLoadAction colorLoadOp = RenderBufferLoadAction.DontCare; RenderBufferStoreAction colorStoreOp = RenderBufferStoreAction.Store; RenderBufferLoadAction depthLoadOp = RenderBufferLoadAction.DontCare; RenderBufferStoreAction depthStoreOp = RenderBufferStoreAction.Store; SetRenderTarget(cmd, m_TargetIdentifier, colorLoadOp, colorStoreOp, m_DepthIdentifier, depthLoadOp, depthStoreOp, ClearFlag.All, Color.clear, m_Descriptor.dimension); cmd.Blit(null, m_TargetIdentifier, m_BlitMaterial); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag); using (new ProfilingSample(cmd, k_RenderOpaquesTag)) { // When ClearFlag.None that means this is not the first render pass to write to camera target. // In that case we set loadOp for both color and depth as RenderBufferLoadAction.Load RenderBufferLoadAction loadOp = clearFlag != ClearFlag.None ? RenderBufferLoadAction.DontCare : RenderBufferLoadAction.Load; 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; XRUtils.DrawOcclusionMesh(cmd, camera, renderingData.cameraData.isStereoEnabled); 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); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); bool isEnable = (m_interface != null) && m_interface.IsEnable(); Material skyBoxMaterial = RenderSettings.skybox; if (isEnable) { skyBoxMaterial.SetInt("_ZTest", 0); cmd.EnableShaderKeyword("_PROCESS_DISSOLVE"); var descriptor = renderingData.cameraData.cameraTargetDescriptor; descriptor.depthBufferBits = 0; //生成拷貝目前畫面的渲染貼圖 cmd.GetTemporaryRT(m_copyBackgroundRT.id, descriptor, FilterMode.Bilinear); //將目前的結果Blit到渲染貼圖 cmd.Blit(m_colorTargetIdentifier, m_copyBackgroundRT.Identifier()); //只指定ColorBuffer,不指定DepthBuffer,這樣就可以直接使用深度貼圖而不用cpoy(Input不可以等於Output) CoreUtils.SetRenderTarget(cmd, m_colorTargetIdentifier, ClearFlag.None, Color.clear, 0, CubemapFace.Unknown, -1); context.ExecuteCommandBuffer(cmd); cmd.Clear(); } else { skyBoxMaterial.SetInt("_ZTest", 4); } //渲染天空盒 context.DrawSkybox(renderingData.cameraData.camera); //指定原本的Color及Depth Buffer(還原預設指定的RenderTarget) if (isEnable) { CoreUtils.SetRenderTarget(cmd, m_colorTargetIdentifier, m_depthTargetIdentifier, ClearFlag.None, Color.clear, 0, CubemapFace.Unknown, -1); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
protected void RenderCamera() { var cmd = CommandBufferPool.Get(); var hd = HDCamera.GetOrCreate(SensorCamera); if (renderTarget.IsCube && !HDAdditionalCameraData.hasCustomRender) { // HDRP renders cubemap as multiple separate images, each with different exposure. // Locking exposure will force it to use the same value for all faces, removing inconsistencies. hd.LockExposure(); SensorCamera.stereoSeparation = 0f; SensorCamera.RenderToCubemap(renderTarget, faceMask, Camera.MonoOrStereoscopicEye.Left); hd.UnlockExposure(); } else { SensorCamera.Render(); } if (Distorted) { if (Fisheye) { LensDistortion.UnifiedProjectionDistort(cmd, renderTarget, DistortedHandle); } else { LensDistortion.PlumbBobDistort(cmd, renderTarget, DistortedHandle); } cmd.SetGlobalVector(ScreenSizeProperty, new Vector4(Width, Height, 1.0f / Width, 1.0f / Height)); var ctx = new PostProcessPassContext(cmd, hd, DistortedHandle); SimulatorManager.Instance.Sensors.PostProcessSystem.RenderLateForSensor(ctx, this); } FinalRenderTarget.BlitTo2D(cmd, hd); HDRPUtilities.ExecuteAndClearCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (m_WaterCausticMaterial == null) { Debug.LogErrorFormat("Missing caustic material}. {0} render pass will not execute. Check for missing reference in the renderer resources.", GetType().Name); return; } CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterCausticsTag); m_view = renderingData.cameraData.camera.worldToCameraMatrix; m_proj = renderingData.cameraData.camera.projectionMatrix; cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); ScriptableRenderer.RenderFullscreenQuad(cmd, m_WaterCausticMaterial); context.ExecuteCommandBuffer(cmd); cmd.Clear(); cmd.SetViewProjectionMatrices(m_view, m_proj); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
void RenderVolumeDepth(ScriptableRenderContext context, RenderingData renderingData) { var cmd = CommandBufferPool.Get("Light Volume Depth"); var debugRT = IdentifierPool.Get(); cmd.GetTemporaryRT(debugRT, renderingData.camera.pixelWidth, renderingData.camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat); cmd.SetRenderTarget(debugRT); cmd.SetGlobalTexture("_RWVolumeDepthTexture", VolumeDepthTex); foreach (var volumeData in visibleVolumes) { cmd.SetGlobalInt("_VolumeIndex", volumeData.VolumeIndex); cmd.DrawMesh(volumeData.Volume.VolumeMesh, volumeData.Volume.transform.localToWorldMatrix, volumeMat, 0, PassVolumeDepth); } cmd.ReleaseTemporaryRT(debugRT); IdentifierPool.Release(debugRT); context.ExecuteCommandBuffer(cmd); cmd.Clear(); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmdBuf = CommandBufferPool.Get(); if (m_CameraColorHandle == renderingData.cameraData.renderer.GetCameraColorFrontBuffer(cmdBuf)) { m_CameraColorHandle = renderingData.cameraData.renderer.cameraColorTargetHandle; } using (new ProfilingScope(cmdBuf, m_ProfilingSampler)) { var colorAttachmentIdentifier = m_CameraColorHandle.nameID; var captureActions = renderingData.cameraData.captureActions; for (captureActions.Reset(); captureActions.MoveNext();) { captureActions.Current(colorAttachmentIdentifier, cmdBuf); } } context.ExecuteCommandBuffer(cmdBuf); CommandBufferPool.Release(cmdBuf); }
public override void Render(ScriptableRenderContext context, ref RenderingData renderingData) { var cmd = CommandBufferPool.Get("RenderTransparent"); using (new ProfilingSample(cmd, "RenderTransparent")) { // Start profilling context.ExecuteCommandBuffer(cmd); cmd.Clear(); if (!asset.UseDepthPeeling) { RenderDefaultTransparent(context, ref renderingData); } else { RenderDepthPeeling(context, ref renderingData); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("FlatKit Outline Pass"); RenderTextureDescriptor opaqueDescriptor = renderingData.cameraData.cameraTargetDescriptor; opaqueDescriptor.depthBufferBits = 0; if (destination == RenderTargetHandle.CameraTarget) { cmd.GetTemporaryRT(temporaryColorTexture.id, opaqueDescriptor, FilterMode.Point); Blit(cmd, source, temporaryColorTexture.Identifier(), outlineMaterial, 0); Blit(cmd, temporaryColorTexture.Identifier(), source); } else { Blit(cmd, source, destination.Identifier(), outlineMaterial, 0); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ref ScriptableRenderContext renderContext, CullResults cullResults, Camera camera) { List <Light> lights = new List <Light>(); foreach (var light in cullResults.visibleLights) { lights.Add(light.light); } PrepareShadow(ref renderContext, lights, camera); PrepareLightBuffer(cullResults.visibleLights); renderContext.SetupCameraProperties(camera); CommandBuffer cb = CommandBufferPool.Get("CommonRenderer_setbuffer"); cb.ClearRenderTarget(true, true, Color.clear); renderContext.ExecuteCommandBuffer(cb); var filterSetting = new FilterRenderersSettings(true); filterSetting.renderQueueRange = RenderQueueRange.opaque; filterSetting.layerMask = camera.cullingMask; var renderSetting = new DrawRendererSettings(camera, new ShaderPassName("VRP_BAKE")); renderSetting.sorting.flags = SortFlags.None; { renderContext.ExecuteCommandBuffer(m_renderResources.setup_per_camera_properties); m_renderResources.setup_per_camera_properties.Clear(); renderContext.DrawRenderers(cullResults.visibleRenderers, ref renderSetting, filterSetting); } renderContext.DrawSkybox(camera); CommandBufferPool.Release(cb); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { ScriptableCullingParameters cullingParameters = new ScriptableCullingParameters(); renderingData.cameraData.camera.TryGetCullingParameters(out cullingParameters); var cullResults = context.Cull(ref cullingParameters); CommandBuffer cmd = CommandBufferPool.Get(Tag); using (new ProfilingSample(cmd, Tag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); var cam = renderingData.cameraData.camera; var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(shaderTagIdList, ref renderingData, sortFlags); context.DrawRenderers(cullResults, ref drawSettings, ref filteringSettings); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Render(ScriptableRenderContext context, ref RenderingData renderingData) { if (!asset.material) { return; } var cmd = CommandBufferPool.Get("Ray-marching"); cmd.Clear(); cmd.SetGlobalVector("_WorldCameraPos", renderingData.camera.transform.position); cmd.SetGlobalVector("_CameraClipPlane", new Vector3(renderingData.camera.nearClipPlane, renderingData.camera.farClipPlane, renderingData.camera.farClipPlane - renderingData.camera.nearClipPlane)); cmd.SetGlobalMatrix("_ViewProjectionInverseMatrix", Utility.ProjectionToWorldMatrix(renderingData.camera)); //cmd.Blit(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CameraTarget, asset.material); //cmd.DrawMesh(screenMesh, Utility.ProjectionToWorldMatrix(renderingData.camera), asset.material); context.ExecuteCommandBuffer(cmd); cmd.Clear(); CommandBufferPool.Release(cmd); }
// Here you can implement the rendering logic. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (!godRayMaterial) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_RenderTag); using (new ProfilingScope(cmd, new ProfilingSampler(k_RenderTag))) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); RenderOcculder(context, ref renderingData); RenderRadiusBlur(cmd, context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public void Setup(ScriptableRenderContext context, ref RenderingData renderingData) { int additionalLightsCount = renderingData.lightData.additionalLightsCount; bool additionalLightsPerVertex = renderingData.lightData.shadeAdditionalLightsPerVertex; CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { SetupShaderLightConstants(cmd, ref renderingData); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsVertex, additionalLightsCount > 0 && additionalLightsPerVertex); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsPixel, additionalLightsCount > 0 && !additionalLightsPerVertex); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MixedLightingSubtractive, renderingData.lightData.supportsMixedLighting && m_MixedLightingSetup == MixedLightingSetup.Subtractive); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
void CustomRender(ScriptableRenderContext context, HDCamera hd) { var camera = hd.camera; var cmd = CommandBufferPool.Get(); hd.SetupGlobalParams(cmd, 0); if (!Fisheye) { CoreUtils.SetRenderTarget(cmd, renderTarget.ColorHandle, renderTarget.DepthHandle); } CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); ScriptableCullingParameters culling; if (camera.TryGetCullingParameters(out culling)) { var cull = context.Cull(ref culling); context.SetupCameraProperties(camera); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sorting = new SortingSettings(camera); var drawing = new DrawingSettings(new ShaderTagId("SimulatorDepthPass"), sorting); var filter = new FilteringSettings(RenderQueueRange.all); context.DrawRenderers(cull, ref drawing, ref filter); } if (!Fisheye) { PointCloudManager.RenderDepth(context, cmd, hd, renderTarget.ColorHandle, renderTarget.DepthHandle); } CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { ShadowData shadowData = renderingData.shadowData; int cascadesCount = shadowData.mainLightShadowCascadesCount; bool mainLightShadows = renderingData.shadowData.supportsMainLightShadows; bool receiveShadowsNoCascade = mainLightShadows && cascadesCount == 1; bool receiveShadowsCascades = mainLightShadows && cascadesCount > 1; // Before transparent object pass, force to disable screen space shadow of main light CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowScreen, false); // then enable main light shadows with or without cascades CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, receiveShadowsNoCascade); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowCascades, receiveShadowsCascades); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); //Matrix4x4 clipToView = renderingData.cameraData.GetGPUProjectionMatrix().inverse; Matrix4x4 clipToView = GL.GetGPUProjectionMatrix(renderingData.cameraData.GetProjectionMatrix(), true).inverse; cmd.SetGlobalMatrix(clipToViewID, clipToView); if (isSourceAndDestinationSameTarget) { Blit(cmd, source, destination, settings.blitMaterial, settings.blitMaterialPassIndex); Blit(cmd, destination, source); } else { Blit(cmd, source, destination, settings.blitMaterial, settings.blitMaterialPassIndex); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); using (new ProfilingSample(cmd, m_ProfilerTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); Camera camera = renderingData.cameraData.camera; var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortFlags); CoreUtils.SetKeyword(cmd, "SHADOWS_SCREEN", renderingData.shadowData.requiresScreenSpaceShadowResolve); CoreUtils.SetKeyword(cmd, "SS_DOWNSAMPLE", renderingData.shadowData.requiresScreenSpaceShadowResolve && renderingData.shadowData.ssShadowDownSampleSize > 1); context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings); // Render objects that did not match any shader pass with error shader RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public void Setup(ScriptableRenderContext context, ref RenderingData renderingData) { int additionalLightsCount = renderingData.lightData.additionalLightsCount; bool additionalLightsPerVertex = renderingData.lightData.shadeAdditionalLightsPerVertex; CommandBuffer cmd = CommandBufferPool.Get(k_SetupLightConstants); SetupShaderLightConstants(cmd, ref renderingData); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsVertex, additionalLightsCount > 0 && additionalLightsPerVertex); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsPixel, additionalLightsCount > 0 && !additionalLightsPerVertex); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MixedLightingSubtractive, renderingData.lightData.supportsMixedLighting && m_MixedLightingSetup == MixedLightingSetup.Subtractive); bool isSurportShadowmask = renderingData.lightData.supportsMixedLighting && m_MixedLightingSetup == MixedLightingSetup.ShadowMask; CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MixedLightingShadowmask, isSurportShadowmask); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.ShadowMaskKeyword, isSurportShadowmask); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(Tag); using (new ProfilingScope(cmd, profilingSampler)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); cmd.ClearRenderTarget(true, false, Color.clear); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var cam = renderingData.cameraData.camera; var sortFlags = SortingCriteria.SortingLayer; var drawSettings = CreateDrawingSettings(shaderTagIdList, ref renderingData, sortFlags); context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { // Keywords are enabled while executing passes. CommandBuffer cmd = CommandBufferPool.Get("Clear Pipeline Keywords"); cmd.DisableShaderKeyword(ShaderKeywordStrings.MainLightShadows); cmd.DisableShaderKeyword(ShaderKeywordStrings.MainLightShadowCascades); cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightsVertex); cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightsPixel); cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightShadows); cmd.DisableShaderKeyword(ShaderKeywordStrings.SoftShadows); cmd.DisableShaderKeyword(ShaderKeywordStrings.MixedLightingSubtractive); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i) { m_ActiveRenderPassQueue[i].Execute(this, context, ref renderingData); } DisposePasses(ref context); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } Material material = renderingData.cameraData.isStereoEnabled ? null : renderer.GetMaterial(MaterialHandle.Blit); RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier(); CommandBuffer cmd = CommandBufferPool.Get(k_FinalBlitTag); using (new ProfilingSample(cmd, k_FinalBlitTag)) { cmd.SetGlobalTexture("_BlitTex", sourceRT); // We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport if (!renderingData.cameraData.isDefaultViewport) { SetRenderTarget( cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.None, Color.black, descriptor.dimension); cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmd.SetViewport(renderingData.cameraData.camera.pixelRect); ScriptableRenderer.RenderFullscreenQuad(cmd, material); } else { cmd.Blit(colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, material); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }