public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage) { int gBufferCount; bool supportShadowMask; bool supportLightLayers; GetGBufferOptions(asset, out gBufferCount, out supportShadowMask, out supportLightLayers); RTFormat = new RenderTextureFormat[gBufferCount]; sRGBFlag = new bool[gBufferCount]; gBufferUsage = new GBufferUsage[gBufferCount]; RTFormat[0] = RenderTextureFormat.ARGB32; // Albedo sRGB / SSSBuffer sRGBFlag[0] = true; gBufferUsage[0] = GBufferUsage.SubsurfaceScattering; RTFormat[1] = RenderTextureFormat.ARGB32; // Normal Buffer sRGBFlag[1] = false; gBufferUsage[1] = GBufferUsage.Normal; RTFormat[2] = RenderTextureFormat.ARGB32; // Data sRGBFlag[2] = false; gBufferUsage[2] = GBufferUsage.None; RTFormat[3] = Builtin.GetLightingBufferFormat(); sRGBFlag[3] = Builtin.GetLightingBufferSRGBFlag(); gBufferUsage[3] = GBufferUsage.None; int index = 4; if (supportLightLayers) { RTFormat[index] = RenderTextureFormat.ARGB32; sRGBFlag[index] = false; gBufferUsage[index] = GBufferUsage.LightLayers; index++; } // All buffer above are fixed. However shadow mask buffer can be setup or not depends on light in view. // Thus it need to be the last one, so all indexes stay the same if (supportShadowMask) { RTFormat[index] = Builtin.GetShadowMaskBufferFormat(); sRGBFlag[index] = Builtin.GetShadowMaskBufferSRGBFlag(); gBufferUsage[index] = GBufferUsage.ShadowMask; index++; } }
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out GraphicsFormat[] RTFormat, out GBufferUsage[] gBufferUsage, out bool[] enableWrite) { int gBufferCount; bool supportShadowMask; bool supportLightLayers; GetGBufferOptions(asset, out gBufferCount, out supportShadowMask, out supportLightLayers); RTFormat = new GraphicsFormat[gBufferCount]; gBufferUsage = new GBufferUsage[gBufferCount]; enableWrite = new bool[gBufferCount]; RTFormat[0] = GraphicsFormat.R8G8B8A8_SRGB; // Albedo sRGB / SSSBuffer gBufferUsage[0] = GBufferUsage.SubsurfaceScattering; enableWrite[0] = false; RTFormat[1] = GraphicsFormat.R8G8B8A8_UNorm; // Normal Buffer gBufferUsage[1] = GBufferUsage.Normal; enableWrite[1] = true; // normal buffer is used as RWTexture to composite decals in forward RTFormat[2] = GraphicsFormat.R8G8B8A8_UNorm; // Data gBufferUsage[2] = GBufferUsage.None; enableWrite[2] = false; RTFormat[3] = Builtin.GetLightingBufferFormat(); gBufferUsage[3] = GBufferUsage.None; enableWrite[3] = false; int index = 4; if (supportLightLayers) { RTFormat[index] = GraphicsFormat.R8G8B8A8_UNorm; gBufferUsage[index] = GBufferUsage.LightLayers; index++; } // All buffer above are fixed. However shadow mask buffer can be setup or not depends on light in view. // Thus it need to be the last one, so all indexes stay the same if (supportShadowMask) { RTFormat[index] = Builtin.GetShadowMaskBufferFormat(); gBufferUsage[index] = GBufferUsage.ShadowMask; index++; } }
public void InitSharedBuffers(GBufferManager gbufferManager, RenderPipelineSettings settings, RenderPipelineResources resources) { // Set the flags m_MSAASupported = settings.supportMSAA; m_MSAASamples = m_MSAASupported ? settings.msaaSampleCount : MSAASamples.None; m_MotionVectorsSupport = settings.supportMotionVectors; m_ReuseGBufferMemory = settings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.ForwardOnly; // Create the depth/stencil buffer m_CameraDepthStencilBuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth32, filterMode: FilterMode.Point, xrInstancing: true, useDynamicScale: true, name: "CameraDepthStencil"); // Create the mip chain buffer m_CameraDepthBufferMipChainInfo = new HDUtils.PackedMipChainInfo(); m_CameraDepthBufferMipChainInfo.Allocate(); m_CameraDepthBufferMipChain = RTHandles.Alloc(ComputeDepthBufferMipChainSize, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R32_SFloat), filterMode: FilterMode.Point, enableRandomWrite: true, xrInstancing: true, useDynamicScale: true, name: "CameraDepthBufferMipChain"); if (settings.lowresTransparentSettings.enabled) { // Create the half res depth buffer used for low resolution transparency m_CameraHalfResDepthBuffer = RTHandles.Alloc(Vector2.one * 0.5f, depthBufferBits: DepthBits.Depth32, filterMode: FilterMode.Point, xrInstancing: true, useDynamicScale: true, name: "LowResDepthBuffer"); } // Technically we won't need this buffer in some cases, but nothing that we can determine at init time. m_CameraStencilBufferCopy = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.None, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R8_UNorm), filterMode: FilterMode.Point, enableRandomWrite: true, xrInstancing: true, useDynamicScale: true, name: "CameraStencilCopy"); // DXGI_FORMAT_R8_UINT is not supported by Unity if (m_MotionVectorsSupport) { m_MotionVectorsRT = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: Builtin.GetMotionVectorFormat(), xrInstancing: true, useDynamicScale: true, name: "MotionVectors"); if (m_MSAASupported) { m_MotionVectorsMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: Builtin.GetMotionVectorFormat(), enableMSAA: true, bindTextureMS: true, xrInstancing: true, useDynamicScale: true, name: "MotionVectorsMSAA"); } } // Allocate the additional textures only if MSAA is supported if (m_MSAASupported) { // Let's create the MSAA textures m_CameraDepthStencilMSAABuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth24, filterMode: FilterMode.Point, bindTextureMS: true, enableMSAA: true, xrInstancing: true, useDynamicScale: true, name: "CameraDepthStencilMSAA"); m_CameraDepthValuesBuffer = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R32G32B32A32_SFloat), xrInstancing: true, useDynamicScale: true, name: "DepthValuesBuffer"); m_DepthAsColorMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R32_SFloat), bindTextureMS: true, enableMSAA: true, xrInstancing: true, useDynamicScale: true, name: "DepthAsColorMSAA"); // We need to allocate this texture as long as msaa is supported because on both mode, one of the cameras can be forward only using the framesettings m_NormalMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R8G8B8A8_UNorm), enableMSAA: true, bindTextureMS: true, xrInstancing: true, useDynamicScale: true, name: "NormalBufferMSAA"); // Create the required resolve materials m_DepthResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.depthValuesPS); m_ColorResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.colorResolvePS); } // If we are in the forward only mode if (!m_ReuseGBufferMemory) { // In case of full forward we must allocate the render target for normal buffer (or reuse one already existing) // TODO: Provide a way to reuse a render target m_NormalRT = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R8G8B8A8_UNorm), enableRandomWrite: true, xrInstancing: true, useDynamicScale: true, name: "NormalBuffer"); } else { // When not forward only we should are using the normal buffer of the gbuffer // In case of deferred, we must be in sync with NormalBuffer.hlsl and lit.hlsl files and setup the correct buffers m_NormalRT = gbufferManager.GetNormalBuffer(0); // Normal + Roughness } }
public void InitSharedBuffers(GBufferManager gbufferManager, RenderPipelineSettings settings, RenderPipelineResources resources) { // Set the flags m_MSAASupported = settings.supportMSAA; m_MSAASamples = m_MSAASupported ? settings.msaaSampleCount : MSAASamples.None; m_VelocitySupport = settings.supportMotionVectors; m_ReuseGBufferMemory = settings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.ForwardOnly; // Create the depth/stencil buffer m_CameraDepthStencilBuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth32, colorFormat: RenderTextureFormat.Depth, filterMode: FilterMode.Point, name: "CameraDepthStencil"); // Create the mip chain buffer m_CameraDepthBufferMipChainInfo = new HDUtils.PackedMipChainInfo(); m_CameraDepthBufferMipChainInfo.Allocate(); m_CameraDepthBufferMipChain = RTHandles.Alloc(ComputeDepthBufferMipChainSize, colorFormat: RenderTextureFormat.RFloat, filterMode: FilterMode.Point, sRGB: false, enableRandomWrite: true, name: "CameraDepthBufferMipChain"); // Technically we won't need this buffer in some cases, but nothing that we can determine at init time. m_CameraStencilBufferCopy = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.None, colorFormat: RenderTextureFormat.R8, sRGB: false, filterMode: FilterMode.Point, enableRandomWrite: true, name: "CameraStencilCopy"); // DXGI_FORMAT_R8_UINT is not supported by Unity if (m_VelocitySupport) { m_VelocityRT = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: Builtin.GetVelocityBufferFormat(), sRGB: Builtin.GetVelocityBufferSRGBFlag(), name: "Velocity"); if (m_MSAASupported) { m_VelocityMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: Builtin.GetVelocityBufferFormat(), sRGB: Builtin.GetVelocityBufferSRGBFlag(), enableMSAA: true, bindTextureMS: true, name: "VelocityMSAA"); } } // Allocate the additional textures only if MSAA is supported if (m_MSAASupported) { // Let's create the MSAA textures m_CameraDepthStencilMSAABuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.Depth24, colorFormat: RenderTextureFormat.Depth, filterMode: FilterMode.Point, bindTextureMS: true, enableMSAA: true, name: "CameraDepthStencilMSAA"); m_CameraDepthValuesBuffer = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBFloat, sRGB: false, name: "DepthValuesBuffer"); m_DepthAsColorMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.RFloat, sRGB: false, bindTextureMS: true, enableMSAA: true, name: "DepthAsColorMSAA"); // We need to allocate this texture as long as msaa is supported because on both mode, one of the cameras can be forward only using the framesettings m_NormalMSAART = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGB32, sRGB: false, enableMSAA: true, bindTextureMS: true, name: "NormalBufferMSAA"); // Create the required resolve materials m_DepthResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.depthValuesPS); m_ColorResolveMaterial = CoreUtils.CreateEngineMaterial(resources.shaders.colorResolvePS); } // If we are in the forward only mode if (!m_ReuseGBufferMemory) { // In case of full forward we must allocate the render target for normal buffer (or reuse one already existing) // TODO: Provide a way to reuse a render target m_NormalRT = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGB32, sRGB: false, enableRandomWrite: true, name: "NormalBuffer"); } else { // When not forward only we should are using the normal buffer of the gbuffer // In case of deferred, we must be in sync with NormalBuffer.hlsl and lit.hlsl files and setup the correct buffers m_NormalRT = gbufferManager.GetNormalBuffer(0); // Normal + Roughness } }
public override void CreateBuffers() { RenderTextureFormat[] rtFormat; bool[] sRGBFlags; m_DeferredMaterial.GetMaterialGBufferDescription(out rtFormat, out sRGBFlags); for (int gbufferIndex = 0; gbufferIndex < m_GBufferCount; ++gbufferIndex) { m_RTs[gbufferIndex] = RTHandle.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point, name: string.Format("GBuffer{0}", gbufferIndex)); m_RTIDs[gbufferIndex] = m_RTs[gbufferIndex].nameID; m_TextureShaderIDs[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex]; m_RTIDsNoShadowMask[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex]; } if (m_SupportShadowMask) { m_RTs[m_GBufferCount] = RTHandle.Alloc(Vector2.one, colorFormat: Builtin.GetShadowMaskBufferFormat(), sRGB: Builtin.GetShadowMaskSRGBFlag(), filterMode: FilterMode.Point, name: "GBufferShadowMask"); m_RTIDs[m_GBufferCount] = new RenderTargetIdentifier(m_RTs[m_GBufferCount]); m_TextureShaderIDs[m_GBufferCount] = HDShaderIDs._ShadowMaskTexture; } }