public ToonForwardRenderer(ToonForwardRendererData data) : base(data) { m_BlitMaterial = CoreUtils.CreateEngineMaterial(data.shaders.blitPS); m_CopyDepthMaterial = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS); m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.shaders.samplingPS); m_ScreenspaceShadowsMaterial = CoreUtils.CreateEngineMaterial(data.shaders.screenSpaceShadowPS); StencilStateData stencilData = data.defaultStencilState; m_DefaultStencilState = StencilState.defaultValue; m_DefaultStencilState.enabled = stencilData.overrideStencilState; m_DefaultStencilState.SetCompareFunction(stencilData.stencilCompareFunction); m_DefaultStencilState.SetPassOperation(stencilData.passOperation); m_DefaultStencilState.SetFailOperation(stencilData.failOperation); m_DefaultStencilState.SetZFailOperation(stencilData.zFailOperation); // Note: Since all custom render passes inject first and we have stable sort, // we inject the builtin passes in the before events. m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrepasses, RenderQueueRange.opaque, data.opaqueLayerMask); m_ScreenSpaceShadowResolvePass = new ScreenSpaceShadowResolvePass(RenderPassEvent.BeforeRenderingPrepasses, m_ScreenspaceShadowsMaterial); m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingPrepasses, data.postProcessData); m_RenderOutlineForwardPass = new DrawOutlinePass("Render Outline", true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference); m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference); m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.AfterRenderingSkybox, m_CopyDepthMaterial); m_DrawSkyboxPass = new DrawSkyboxPass(RenderPassEvent.BeforeRenderingSkybox); m_CopyColorPass = new CopyColorPass(RenderPassEvent.BeforeRenderingTransparents, m_SamplingMaterial); m_TransparentSettingsPass = new TransparentSettingsPass(RenderPassEvent.BeforeRenderingTransparents, data.shadowTransparentReceive); m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, data.transparentLayerMask, m_DefaultStencilState, stencilData.stencilReference); m_OnRenderObjectCallbackPass = new InvokeOnRenderObjectCallbackPass(RenderPassEvent.BeforeRenderingPostProcessing); m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData, m_BlitMaterial); m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRendering + 1, data.postProcessData, m_BlitMaterial); m_CapturePass = new CapturePass(RenderPassEvent.AfterRendering); m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial); #if POST_PROCESSING_STACK_2_0_0_OR_NEWER m_OpaquePostProcessPassCompat = new PostProcessPassCompat(RenderPassEvent.BeforeRenderingOpaques, true); m_PostProcessPassCompat = new PostProcessPassCompat(RenderPassEvent.BeforeRenderingPostProcessing); #endif #if UNITY_EDITOR m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); #endif // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) // Samples (MSAA) depend on camera and pipeline m_CameraColorAttachment.Init("_CameraColorTexture"); m_CameraDepthAttachment.Init("_CameraDepthAttachment"); m_DepthTexture.Init("_CameraDepthTexture"); m_OpaqueColor.Init("_CameraOpaqueTexture"); m_AfterPostProcessColor.Init("_AfterPostProcessTexture"); m_ColorGradingLut.Init("_InternalGradingLut"); m_ForwardLights = new ForwardLights(); supportedRenderingFeatures = new RenderingFeatures() { cameraStacking = true, }; }
public DeferredRenderer(DeferredRendererData data) : base(data) { m_BlitMaterial = CoreUtils.CreateEngineMaterial(data.shaders.blitPS); m_CopyDepthMaterial = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS); m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.shaders.samplingPS); m_ScreenspaceShadowsMaterial = CoreUtils.CreateEngineMaterial(data.shaders.screenSpaceShadowPS); m_TileDepthInfoMaterial = CoreUtils.CreateEngineMaterial(data.shaders.tileDepthInfoPS); m_TileDeferredMaterial = CoreUtils.CreateEngineMaterial(data.shaders.tileDeferredPS); m_StencilDeferredMaterial = CoreUtils.CreateEngineMaterial(data.shaders.stencilDeferredPS); StencilStateData stencilData = data.defaultStencilState; m_DefaultStencilState = StencilState.defaultValue; m_DefaultStencilState.enabled = stencilData.overrideStencilState; m_DefaultStencilState.SetCompareFunction(stencilData.stencilCompareFunction); m_DefaultStencilState.SetPassOperation(stencilData.passOperation); m_DefaultStencilState.SetFailOperation(stencilData.failOperation); m_DefaultStencilState.SetZFailOperation(stencilData.zFailOperation); m_ForwardLights = new ForwardLights(); m_DeferredLights = new DeferredLights(m_TileDepthInfoMaterial, m_TileDeferredMaterial, m_StencilDeferredMaterial); //m_DeferredLights.LightCulling = data.lightCulling; m_DeferredLights.AccurateGbufferNormals = data.accurateGbufferNormals; //m_DeferredLights.TiledDeferredShading = data.tiledDeferredShading; m_DeferredLights.TiledDeferredShading = false; m_PreferDepthPrepass = data.preferDepthPrepass; // Note: Since all custom render passes inject first and we have stable sort, // we inject the builtin passes in the before events. m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrepasses, RenderQueueRange.opaque, data.opaqueLayerMask); m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); m_ScreenSpaceShadowResolvePass = new ScreenSpaceShadowResolvePass(RenderPassEvent.BeforeRenderingPrepasses, m_ScreenspaceShadowsMaterial); m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingPrepasses, data.postProcessData); m_GBufferPass = new GBufferPass(RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference, m_DeferredLights); m_CopyDepthPass0 = new CopyDepthPass(RenderPassEvent.BeforeRenderingOpaques + 1, m_CopyDepthMaterial); m_TileDepthRangePass = new TileDepthRangePass(RenderPassEvent.BeforeRenderingOpaques + 2, m_DeferredLights, 0); m_TileDepthRangeExtraPass = new TileDepthRangePass(RenderPassEvent.BeforeRenderingOpaques + 3, m_DeferredLights, 1); m_DeferredPass = new DeferredPass(RenderPassEvent.BeforeRenderingOpaques + 4, m_DeferredLights); // Forward only pass: // - If a material can be rendered either forward or deferred, then it should declare a UniversalForward and a UniversalGBuffer pass. // - If a material cannot be lit in deferred (unlit, bakedLit, special material such as hair, skin shader), then it should declare UniversalForwardOnly pass // - Legacy materials have unamed pass, which is implicitely renamed as SRPDefaultUnlit. In that case, they are considered forward-only too. // TO declare a material with unnamed pass and UniversalForward/UniversalForwardOnly pass is an ERROR, as the material will be rendered twice. m_RenderOpaqueForwardOnlyPass = new DrawObjectsPass("Render Opaques Forward Only", new ShaderTagId[] { new ShaderTagId("SRPDefaultUnlit"), new ShaderTagId("UniversalForwardOnly") }, true, RenderPassEvent.BeforeRenderingOpaques + 5, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference); m_CopyDepthPass1 = new CopyDepthPass(RenderPassEvent.AfterRenderingSkybox, m_CopyDepthMaterial); m_DrawSkyboxPass = new DrawSkyboxPass(RenderPassEvent.BeforeRenderingSkybox); m_CopyColorPass = new CopyColorPass(RenderPassEvent.BeforeRenderingTransparents, m_SamplingMaterial); m_TransparentSettingsPass = new TransparentSettingsPass(RenderPassEvent.BeforeRenderingTransparents, data.shadowTransparentReceive); m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, data.transparentLayerMask, m_DefaultStencilState, stencilData.stencilReference); m_OnRenderObjectCallbackPass = new InvokeOnRenderObjectCallbackPass(RenderPassEvent.BeforeRenderingPostProcessing); m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData, m_BlitMaterial); m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRendering + 1, data.postProcessData, m_BlitMaterial); m_CapturePass = new CapturePass(RenderPassEvent.AfterRendering); m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial); #if UNITY_EDITOR m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, m_CopyDepthMaterial); #endif // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc) // Samples (MSAA) depend on camera and pipeline // string shaderProperty passed to Init() is use to refer to a texture from shader code m_CameraColorTexture.Init("_CameraColorTexture"); m_CameraDepthTexture.Init("_CameraDepthTexture"); m_CameraDepthAttachment.Init("_CameraDepthAttachment"); m_GBufferAttachments = new RenderTargetHandle[m_DeferredLights.GBufferSliceCount]; m_GBufferAttachments[m_DeferredLights.GBufferAlbedoIndex].Init("_GBuffer0"); m_GBufferAttachments[m_DeferredLights.GBufferSpecularMetallicIndex].Init("_GBuffer1"); m_GBufferAttachments[m_DeferredLights.GBufferNormalSmoothnessIndex].Init("_GBuffer2"); //m_GBufferAttachments[m_DeferredLights.GBufferLightingIndex].Init("_GBuffer3"); // RenderTarget bound as output #3 during the GBuffer pass is the LightingGBuffer m_ActiveCameraColorAttachment, initialized as m_CameraColorTexture above m_OpaqueColor.Init("_CameraOpaqueTexture"); m_AfterPostProcessColor.Init("_AfterPostProcessTexture"); m_ColorGradingLut.Init("_InternalGradingLut"); m_DepthInfoTexture.Init("_DepthInfoTexture"); m_TileDepthInfoTexture.Init("_TileDepthInfoTexture"); supportedRenderingFeatures = new RenderingFeatures() { cameraStacking = false, msaa = false, }; }