public void RenderLights(ScriptableRenderContext context, CullResults cullResults, LightData lightData) { CommandBuffer cmd = CommandBufferPool.Get("Render Deferred Lights"); List <VisibleLight> visibleLights = lightData.visibleLights; for (int i = 0; i < visibleLights.Count; ++i) { VisibleLight currLight = visibleLights[i]; if (currLight.lightType != LightType.Directional) { continue; } Vector4 lightDirection = -currLight.localToWorld.GetRow(2); Vector4 lightColor = currLight.finalColor; m_LightPropertiesBlock.Clear(); m_LightPropertiesBlock.SetVector("_MainLightPosition", lightDirection); m_LightPropertiesBlock.SetVector("_MainLightColor", lightColor); cmd.DrawMesh(LightweightPipeline.fullscreenMesh, Matrix4x4.identity, m_DeferredShadingMaterial, 0, 0, m_LightPropertiesBlock); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(k_profilingTag); using (new ProfilingScope(cmd, profilingSampler)) { if (width != textureDescriptor.width || height != textureDescriptor.height) { if (width == -1 || height == -1) { RenderTexture.Destroy(depthRT); } width = textureDescriptor.width; height = textureDescriptor.height; depthRT = new RenderTexture(textureDescriptor.width, textureDescriptor.height, 0, RenderTextureFormat.RFloat, Mathf.CeilToInt(Mathf.Log(width, 2))) { name = "HiZDepth", useMipMap = true, autoGenerateMips = false }; DepthTexture = depthRT; depthRT.Create(); } cmd.SetRenderTarget(depthRT); cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, blitMaterial); cmd.SetRenderTarget(renderingData.cameraData.targetTexture); //复原 //正常mipmap要自己写生成的取周围点的做max/min 但是这里我偷懒了 cmd.GenerateMips(depthRT); } 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.MainCharacterShadows); cmd.DisableShaderKeyword(ShaderKeywordStrings.DeepShadowMaps); 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(ScriptableRenderContext context, ref RenderingData renderingData) { if (m_BlitMaterial == null) { Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_BlitMaterial, GetType().Name); return; } bool requiresSRGBConvertion = Display.main.requiresSrgbBlitToBackbuffer; CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); if (requiresSRGBConvertion) { cmd.EnableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion); } else { cmd.DisableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion); } // Note: We need to get the cameraData.targetTexture as this will get the targetTexture of the camera stack. // Overlay cameras need to output to the target described in the base camera while doing camera stack. ref CameraData cameraData = ref renderingData.cameraData;
public static RenderTexture CreateColorRenderTexture(TextureDimension dim, Color color) { RenderTexture rt = new RenderTexture(1, 1, 0, GraphicsFormat.R8G8B8A8_UNorm, 1) { volumeDepth = 1, dimension = dim, enableRandomWrite = true, hideFlags = HideFlags.HideAndDontSave }; rt.Create(); var cmd = CommandBufferPool.Get(); for (int i = 0; i < GetSliceCount(rt); i++) { cmd.SetRenderTarget(rt, 0, (CubemapFace)i, i); cmd.ClearRenderTarget(false, true, color); } Graphics.ExecuteCommandBuffer(cmd); return(rt); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var cmd = CommandBufferPool.Get("BlurPass"); if (_passesCount > 0) { cmd.Blit(_source, _tmpBlurRT1, _blurMaterial, 0); for (int i = 0; i < _passesCount - 1; i++) { cmd.Blit(_tmpBlurRT1, _tmpBlurRT2, _blurMaterial, 0); var t = _tmpBlurRT1; _tmpBlurRT1 = _tmpBlurRT2; _tmpBlurRT2 = t; } cmd.Blit(_tmpBlurRT1, _destination.Identifier()); } else { cmd.Blit(_source, _destination.Identifier()); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (m_ScreenSpaceShadowsMaterial == null) { Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_ScreenSpaceShadowsMaterial, GetType().Name); return; } if (renderingData.lightData.mainLightIndex == -1) { return; } Camera camera = renderingData.cameraData.camera; CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.ResolveShadows))) { if (!renderingData.cameraData.xr.enabled) { cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_ScreenSpaceShadowsMaterial); cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix); } else { // Avoid setting and restoring camera view and projection matrices when in stereo. RenderTargetIdentifier screenSpaceOcclusionTexture = m_ScreenSpaceShadowmap.Identifier(); Blit(cmd, screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, m_ScreenSpaceShadowsMaterial); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) { if (renderingData.shadowData.renderedDirectionalShadowQuality == LightShadows.None) { return; } CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows"); cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, FilterMode.Bilinear); SetShadowCollectPassKeywords(cmd, ref renderingData.shadowData); // 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, m_ScreenSpaceShadowsMaterial); 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); }
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag); using (new ProfilingSample(cmd, k_RenderGrabPassTag)) { // copy screen into temporary RT int screenCopyID = Shader.PropertyToID("_ScreenCopyTexture"); RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData); cmd.GetTemporaryRT(screenCopyID, opaqueDesc, FilterMode.Bilinear); cmd.Blit(m_ColorHandle.Identifier(), screenCopyID); // get two smaller RTs opaqueDesc.width /= 2; opaqueDesc.height /= 2; cmd.GetTemporaryRT(m_BlurTemp1, opaqueDesc, FilterMode.Bilinear); cmd.GetTemporaryRT(m_BlurTemp2, opaqueDesc, FilterMode.Bilinear); // downsample screen copy into smaller RT, release screen RT cmd.Blit(screenCopyID, m_BlurTemp1); cmd.ReleaseTemporaryRT(screenCopyID); opaqueDesc.width /= 2; opaqueDesc.height /= 2; // Setup blur commands m_Blur.SetupCommandBuffer(cmd, m_BlurTemp1, m_BlurTemp2); // Set texture id so we can use it later cmd.SetGlobalTexture("_GrabBlurTexture", m_BlurTemp1); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("ComputeShaderRGBAdjust"); int tempCameraColorTexID = Shader.PropertyToID("tempCameraColorTexID"); RenderTextureDescriptor desc = renderingData.cameraData.cameraTargetDescriptor; desc.enableRandomWrite = true; cmd.GetTemporaryRT(tempCameraColorTexID, desc); cmd.SetComputeFloatParam(CS, "_Bright", Myset.Bright); cmd.SetComputeFloatParam(CS, "_Saturate", Myset.Saturate); cmd.SetComputeFloatParam(CS, "_Constrast", Myset.Constrast); cmd.SetComputeTextureParam(CS, 0, "_Result", tempCameraColorTexID); cmd.SetComputeTextureParam(CS, 0, "_Sour", Sour); cmd.DispatchCompute(CS, 0, (int)desc.width / 8, (int)desc.height / 8, 1); cmd.Blit(tempCameraColorTexID, Sour); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (!Active) { return; } if (material == null) { var shader = Shader.Find("Custom/PeopleOcclusion"); if (!shader) { return; } material = new Material(shader); } var commandBuffer = CommandBufferPool.Get(Tag); var renderTextureId = Shader.PropertyToID("_SampleLWRPScriptableRenderer"); var cameraData = renderingData.cameraData; var w = cameraData.camera.scaledPixelWidth; var h = cameraData.camera.scaledPixelHeight; int shaderPass = 0; if (PostProcessHelper.GetInstance() != null) { PostProcessHelper.GetInstance().UpdateShaderProperty(material); } commandBuffer.GetTemporaryRT(renderTextureId, w, h, 0, FilterMode.Point, RenderTextureFormat.Default); commandBuffer.Blit(currentTarget, renderTextureId); commandBuffer.Blit(renderTextureId, currentTarget, material, shaderPass); context.ExecuteCommandBuffer(commandBuffer); CommandBufferPool.Release(commandBuffer); }
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(); cmd.SetRenderTarget(renderingData.ColorTarget, renderingData.DepthTarget); if (!asset.UseDepthPeeling) { RenderDefaultTransparent(context, ref renderingData); } else { RenderDepthPeeling(context, ref renderingData); } } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); using (new ProfilingScope(cmd, m_ProfilingSampler)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, sortFlags); drawSettings.perObjectData = PerObjectData.None; ref CameraData cameraData = ref renderingData.cameraData; Camera camera = cameraData.camera; if (cameraData.isStereoEnabled) { context.StartMultiEye(camera); } m_FilteringSettings.layerMask = camera.cullingMask; context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings); }
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 screen space shadow for main light to disable 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); }
Execute(ScriptableRenderContext context, ref RenderingData renderingData) //类似OnRenderimagePass { CommandBuffer cmd = CommandBufferPool.Get(passTag); RenderTextureDescriptor opaquedesc = renderingData.cameraData.cameraTargetDescriptor; int width = opaquedesc.width / passdownsample; int height = opaquedesc.height / passdownsample; opaquedesc.depthBufferBits = 0; cmd.GetTemporaryRT(buffer1.id, width, height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); cmd.GetTemporaryRT(buffer2.id, width, height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); cmd.SetGlobalFloat("_KawaseBlur", 1f); cmd.Blit(passSource, buffer1.id, passMat); for (int t = 1; t < passloop; t++) { cmd.SetGlobalFloat("_KawaseBlur", t * passblur + 1); cmd.Blit(buffer1.id, buffer2.id, passMat); var temRT = buffer1; buffer1 = buffer2; buffer2 = temRT; } cmd.SetGlobalFloat("_KawaseBlur", passloop * passblur + 1); cmd.Blit(buffer1.id, passSource, passMat); cmd.ReleaseTemporaryRT(buffer1.id); cmd.ReleaseTemporaryRT(buffer2.id); context.ExecuteCommandBuffer(cmd); //执行命令缓冲区的该命令 CommandBufferPool.Release(cmd); //释放该命令 }
//这里你可以实现渲染逻辑。 //使用<c>ScriptableRenderContext</c>来发出绘图命令或执行命令缓冲区 // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html //你不必调用ScriptableRenderContext。提交时,渲染管道会在管道中的特定点调用它。 public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { // 获取命令缓冲区 CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); using (new ProfilingScope(cmd, new ProfilingSampler(m_ProfilerTag))) { // 执行命令缓存 context.ExecuteCommandBuffer(cmd); // 清楚数据缓存 cmd.Clear(); // 相机的排序标志 var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; // 创建绘制设置 var drawSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, sortFlags); // 设置对象数据 drawSettings.perObjectData = PerObjectData.None; // 检测是否是VR设备 ref CameraData cameraData = ref renderingData.cameraData; Camera camera = cameraData.camera; if (cameraData.isStereoEnabled) { context.StartMultiEye(camera); } // 设置覆盖材质 drawSettings.overrideMaterial = depthNormalsMaterial; // 绘制渲染器 context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings); // 设置全局纹理 cmd.SetGlobalTexture("_CameraDepthNormalsTexture", depthAttachmentHandle.id); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } // For now, we can't combine Skybox and Opaques into a single render pass if there's a custom render pass injected // between them. if (!m_CombineWithRenderOpaquesPass) { CommandBuffer cmd = CommandBufferPool.Get("Draw Skybox (Set RT's)"); 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); CommandBufferPool.Release(cmd); } context.DrawSkybox(renderingData.cameraData.camera); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { // Why can't we rely on the API implied lifecycle? if (m_Material == null) { return; } var target = renderingData.cameraData.renderer.cameraColorTargetHandle; var descriptor = renderingData.cameraData.cameraTargetDescriptor; var cmd = CommandBufferPool.Get(k_CommandBufferName); cmd.GetTemporaryRT(ShaderProperties._TempTex, descriptor); cmd.SetRenderTarget(ShaderProperties._TempTex); cmd.SetGlobalTexture(ShaderProperties._SourceTex, target); cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_Material, 0, 0); cmd.Blit(ShaderProperties._TempTex, target); cmd.ReleaseTemporaryRT(ShaderProperties._TempTex); context.ExecuteCommandBuffer(cmd); 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 (material == null) { Debug.LogError("Material has not been correctly initialized..."); return; } var cmd = CommandBufferPool.Get("CameraNormals"); var sourceTexId = Shader.PropertyToID("_SourceTex"); cmd.GetTemporaryRT(sourceTexId, sourceDesc); Blit(cmd, source, sourceTexId); CoreUtils.SetRenderTarget(cmd, renderTarget); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, new Color(0.5f, 0.5f, 1f)); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var drawingSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags); drawingSettings.overrideMaterial = material; drawingSettings.overrideMaterialPassIndex = 0; context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings, ref m_RenderStateBlock); Blit(cmd, sourceTexId, source); cmd.ReleaseTemporaryRT(sourceTexId); cmd.SetGlobalTexture(Shader.PropertyToID("_CameraNormalsTexture"), renderTarget); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var cmd = CommandBufferPool.Get(PASS_NAME); using (new ProfilingScope(cmd, this.profilingSampler)) { // Create ShrinkBuffer cmd.Clear(); if (UniversalRenderPipeline.asset.supportsHDR) { cmd.GetTemporaryRT(this.tempBufferHandle.id, this.settings.resolution.x, this.settings.resolution.y, 32, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); } else { cmd.GetTemporaryRT(this.tempBufferHandle.id, this.settings.resolution.x, this.settings.resolution.y, 32, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); } cmd.SetRenderTarget(new RenderTargetIdentifier(this.tempBufferHandle.id)); cmd.ClearRenderTarget(false, true, Color.black); cmd.Blit(this.depthAttachment, this.tempBufferHandle.id, this.copyDepth); context.ExecuteCommandBuffer(cmd); // Rendering by LayerMask(e.g. any VFX) var drawingSettings = CreateDrawingSettings(SHADER_TAG_ID, ref renderingData, SortingCriteria.CommonTransparent); var filteringSettings = new FilteringSettings(RenderQueueRange.transparent, this.settings.LayerMask); var renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings, ref renderStateBlock); // Combine ShrinkBuffer to ColorAttachment cmd.Clear(); cmd.Blit(this.tempBufferHandle.id, this.colorAttachment, this.settings.blitMaterial); cmd.ReleaseTemporaryRT(this.tempBufferHandle.id); cmd.SetRenderTarget(this.colorAttachment, this.depthAttachment); context.ExecuteCommandBuffer(cmd); } CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { // NOTE: Do NOT mix ProfilingScope with named CommandBuffers i.e. CommandBufferPool.Get("name"). // Currently there's an issue which results in mismatched markers. CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, sortFlags); drawSettings.perObjectData = PerObjectData.None; ref CameraData cameraData = ref renderingData.cameraData; Camera camera = cameraData.camera; if (cameraData.isStereoEnabled) { context.StartMultiEye(camera, eyeIndex); } context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { SortingCriteria sortingCriteria = renderingData.cameraData.defaultOpaqueSortFlags; DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria); CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); if (isDeferred) { cmd.SetGlobalTexture("_CameraNormalsTexture", deferredLights.GbufferAttachmentIdentifiers[deferredLights.GBufferNormalSmoothnessIndex]); } CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DBufferMRT1, m_Settings.surfaceData == DecalSurfaceData.Albedo); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DBufferMRT2, m_Settings.surfaceData == DecalSurfaceData.AlbedoNormal); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DBufferMRT3, m_Settings.surfaceData == DecalSurfaceData.AlbedoNormalMAOS); // TODO: This should be replace with mrt clear once we support it // Clear render targets ClearDBuffers(cmd, renderingData.cameraData); // Split here allows clear to be executed before DrawRenderers context.ExecuteCommandBuffer(cmd); cmd.Clear(); m_DrawSystem.Execute(cmd); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings); } 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)) { 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; XRUtils.DrawOcclusionMesh(cmd, camera, renderingData.cameraData.isStereoEnabled); var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawingSettings(camera, sortFlags, rendererConfiguration, renderingData.supportsDynamicBatching, renderingData.lightData.mainLightIndex); context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_OpaqueFilterSettings); // Render objects that did not match any shader pass with error shader renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_OpaqueFilterSettings, SortingCriteria.None); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
void FinalBlitPass(ref ScriptableRenderContext context, ref CameraData cameraData) { Material material = cameraData.isStereoEnabled ? null : m_BlitMaterial; RenderTargetIdentifier sourceRT = GetSurface(colorAttachmentHandle); CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass"); cmd.SetGlobalTexture("_BlitTex", sourceRT); if (!cameraData.isDefaultViewport) { SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.All, Color.black); cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmd.SetViewport(cameraData.camera.pixelRect); LightweightPipeline.DrawFullScreen(cmd, material); } else { cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, material); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var cmd = CommandBufferPool.Get(CommandBufferTag); try{ ReflectPlanar.GetVisiblePlanarGroups(_planarRendererGroups); foreach (var group in _planarRendererGroups.rendererGroups) { cmd.Clear(); var planarDescriptor = group.descriptor; var renderers = group.renderers; _ssprTexGenerator.Render(cmd, ref renderingData, ref planarDescriptor); cmd.SetRenderTarget(this.colorAttachment, this.depthAttachment); foreach (var rd in renderers) { cmd.DrawRenderer(rd, _material); } _ssprTexGenerator.ReleaseTemporary(cmd); context.ExecuteCommandBuffer(cmd); } }finally{ CommandBufferPool.Release(cmd); } }
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(k_DepthPrepassTag); using (new ProfilingSample(cmd, k_DepthPrepassTag)) { cmd.GetTemporaryRT(depthAttachmentHandle.id, descriptor, FilterMode.Point); SetRenderTarget( cmd, depthAttachmentHandle.Identifier(), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Depth, Color.black, descriptor.dimension); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sortFlags = renderingData.cameraData.defaultOpaqueSortFlags; var drawSettings = CreateDrawRendererSettings(renderingData.cameraData.camera, sortFlags, RendererConfiguration.None, renderingData.supportsDynamicBatching); if (renderingData.cameraData.isStereoEnabled) { Camera camera = renderingData.cameraData.camera; context.StartMultiEye(camera); context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings); context.StopMultiEye(camera); } else { context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings); } } context.ExecuteCommandBuffer(cmd); 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 UnityEngine.Rendering.Universal.RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("WorldSpaceRipple Pass"); RenderTextureDescriptor opaqueDescriptor = renderingData.cameraData.cameraTargetDescriptor; opaqueDescriptor.depthBufferBits = 0; if (destination == UnityEngine.Rendering.Universal.RenderTargetHandle.CameraTarget) { cmd.GetTemporaryRT(temporaryColorTexture.id, opaqueDescriptor, FilterMode.Point); Blit(cmd, source, temporaryColorTexture.Identifier(), rippleMaterial, 0); Blit(cmd, temporaryColorTexture.Identifier(), source); } else { Blit(cmd, source, destination.Identifier(), rippleMaterial, 0); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
private void NormalRendering(ScriptableRenderContext context, Camera camera) { var cullResults = context.Cull(ref _cullParam); context.SetupCameraProperties(camera); var cmdBuf = CommandBufferPool.Get(_normalCmdName); cmdBuf.ClearRenderTarget(true, false, camera.backgroundColor); context.ExecuteCommandBuffer(cmdBuf); cmdBuf.Clear(); context.DrawRenderers(cullResults, ref _opaqueDrawing, ref _opaqueFiltering); context.DrawRenderers(cullResults, ref _transparentDrawing, ref _transparentFiltering); #if UNITY_EDITOR if (CameraType.SceneView == camera.cameraType) { context.DrawGizmos(camera, GizmoSubset.PreImageEffects); context.DrawGizmos(camera, GizmoSubset.PostImageEffects); } #endif context.Submit(); }
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor; opaqueDesc.depthBufferBits = 0; // Can't read and write to same color target, use a TemporaryRT if (destination == RenderTargetHandle.CameraTarget) { cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode); Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, blitShaderPassIndex); Blit(cmd, m_TemporaryColorTexture.Identifier(), source); } else { Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
private void BeginForwardRendering(Camera camera, ref ScriptableRenderContext context) { m_RenderToIntermediateTarget = GetRenderToIntermediateTarget(camera); var cmd = CommandBufferPool.Get("SetCameraRenderTarget"); if (m_RenderToIntermediateTarget) { if (camera.activeTexture == null) { cmd.GetTemporaryRT(m_CameraRTProperty, Screen.width, Screen.height, kCameraDepthBufferBits, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, m_Asset.MSAASampleCount); cmd.SetRenderTarget(m_CameraRTID); } else { cmd.SetRenderTarget(new RenderTargetIdentifier(camera.activeTexture)); } } else { cmd.SetRenderTarget(BuiltinRenderTextureType.None); } // Clear RenderTarget to avoid tile initialization on mobile GPUs // https://community.arm.com/graphics/b/blog/posts/mali-performance-2-how-to-correctly-handle-framebuffers if (camera.clearFlags != CameraClearFlags.Nothing) { bool clearDepth = (camera.clearFlags != CameraClearFlags.Nothing); bool clearColor = (camera.clearFlags == CameraClearFlags.Color); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }