RenderTargetIdentifier [ ] m_ColorMRTs ;
RenderTargetIdentifier [ ] m_RTIDs = new RenderTargetIdentifier [ k_MaxGbuffer ] ;
public void InitGBuffers ( int width , int height , RenderPipelineMaterial deferredMaterial , bool enableBakeShadowMask , CommandBuffer cmd )
public void InitGBuffers ( RenderTextureDescriptor rtDesc , RenderPipelineMaterial deferredMaterial , bool enableBakeShadowMask , CommandBuffer cmd )
{
// Init Gbuffer description
gbufferCount = deferredMaterial . GetMaterialGBufferCount ( ) ;
rtDesc . depthBufferBits = 0 ;
cmd . GetTemporaryRT ( HDShaderIDs . _GBufferTexture [ gbufferIndex ] , width , height , 0 , FilterMode . Point , rtFormat [ gbufferIndex ] , rtReadWrite [ gbufferIndex ] ) ;
rtDesc . colorFormat = rtFormat [ gbufferIndex ] ;
rtDesc . sRGB = ( rtReadWrite [ gbufferIndex ] ! = RenderTextureReadWrite . Linear ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _GBufferTexture [ gbufferIndex ] , rtDesc , FilterMode . Point ) ;
m_RTIDs [ gbufferIndex ] = new RenderTargetIdentifier ( HDShaderIDs . _GBufferTexture [ gbufferIndex ] ) ;
}
cmd . GetTemporaryRT ( HDShaderIDs . _ShadowMaskTexture , width , height , 0 , FilterMode . Point , Builtin . GetShadowMaskBufferFormat ( ) , Builtin . GetShadowMaskBufferReadWrite ( ) ) ;
rtDesc . colorFormat = Builtin . GetShadowMaskBufferFormat ( ) ;
rtDesc . sRGB = ( Builtin . GetShadowMaskBufferReadWrite ( ) ! = RenderTextureReadWrite . Linear ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _ShadowMaskTexture , rtDesc , FilterMode . Point ) ;
m_RTIDs [ gbufferCount + + ] = new RenderTargetIdentifier ( HDShaderIDs . _ShadowMaskTexture ) ;
}
}
RenderTargetIdentifier [ ] m_ColorMRTs ;
RenderTargetIdentifier [ ] m_RTIDs = new RenderTargetIdentifier [ k_MaxDbuffer ] ;
public void InitDBuffers ( int width , int height , CommandBuffer cmd )
public void InitDBuffers ( RenderTextureDescriptor rtDesc , CommandBuffer cmd )
{
dbufferCount = Decal . GetMaterialDBufferCount ( ) ;
RenderTextureFormat [ ] rtFormat ;
rtDesc . depthBufferBits = 0 ;
cmd . GetTemporaryRT ( HDShaderIDs . _DBufferTexture [ dbufferIndex ] , width , height , 0 , FilterMode . Point , rtFormat [ dbufferIndex ] , rtReadWrite [ dbufferIndex ] ) ;
rtDesc . colorFormat = rtFormat [ dbufferIndex ] ;
rtDesc . sRGB = ( rtReadWrite [ dbufferIndex ] ! = RenderTextureReadWrite . Linear ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _DBufferTexture [ dbufferIndex ] , rtDesc , FilterMode . Point ) ;
m_RTIDs [ dbufferIndex ] = new RenderTargetIdentifier ( HDShaderIDs . _DBufferTexture [ dbufferIndex ] ) ;
}
}
} ;
#endif
void CreateDepthStencilBuffer ( Camera camera )
void CreateDepthStencilBuffer ( HDCamera hdCamera )
var camera = hdCamera . camera ;
m_CameraDepthStencilBuffer = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthStencilBuffer = CoreUtils . CreateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthStencilBuffer . filterMode = FilterMode . Point ;
m_CameraDepthStencilBuffer . Create ( ) ;
m_CameraDepthStencilBufferRT = new RenderTargetIdentifier ( m_CameraDepthStencilBuffer ) ;
if ( m_CameraDepthBufferCopy ! = null )
m_CameraDepthBufferCopy . Release ( ) ;
m_CameraDepthBufferCopy = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthBufferCopy = CoreUtils . CreateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthBufferCopy . filterMode = FilterMode . Point ;
m_CameraDepthBufferCopy . Create ( ) ;
m_CameraDepthBufferCopyRT = new RenderTargetIdentifier ( m_CameraDepthBufferCopy ) ;
if ( m_CameraStencilBufferCopy ! = null )
m_CameraStencilBufferCopy . Release ( ) ;
m_CameraStencilBufferCopy = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy = CoreUtils . CreateRenderTexture ( hdCamera . renderTextureDesc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy . filterMode = FilterMode . Point ;
m_CameraStencilBufferCopy . Create ( ) ;
m_CameraStencilBufferCopyRT = new RenderTargetIdentifier ( m_CameraStencilBufferCopy ) ;
void Resize ( Camera camera )
void Resize ( HDCamera hdCamera )
var camera = hdCamera . camera ;
bool resolutionChanged = camera . pixelWidth ! = m_CurrentWidth | | camera . pixelHeight ! = m_CurrentHeight ;
var desc = hdCamera . renderTextureDesc ;
var texWidth = desc . width ;
var texHeight = desc . height ;
bool resolutionChanged = ( texWidth ! = m_CurrentWidth ) | | ( texHeight ! = m_CurrentHeight ) ;
CreateDepthStencilBuffer ( camera ) ;
m_SSSBufferManager . Resize ( camera ) ;
CreateDepthStencilBuffer ( hdCamera ) ;
m_SSSBufferManager . Resize ( hdCamera ) ;
}
if ( resolutionChanged | | m_LightLoop . NeedResize ( ) )
m_LightLoop . AllocResolutionDependentBuffers ( camera . pixelWidth , camera . pixel Height) ;
m_LightLoop . AllocResolutionDependentBuffers ( texWidth , tex Height) ;
m_CurrentWidth = camera . pixel Width;
m_CurrentHeight = camera . pixel Height;
m_CurrentWidth = tex Width;
m_CurrentHeight = tex Height;
}
public void PushGlobalParams ( HDCamera hdCamera , CommandBuffer cmd , SubsurfaceScatteringSettings sssParameters )
ApplyDebugDisplaySettings ( cmd ) ;
UpdateShadowSettings ( ) ;
// TODO: Float HDCamera setup higher in order to pass stereo into GetCullingParameters
ScriptableCullingParameters cullingParams ;
if ( ! CullResults . GetCullingParameters ( camera , out cullingParams ) )
{
}
var postProcessLayer = camera . GetComponent < PostProcessLayer > ( ) ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer ) ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer , m_FrameSettings ) ;
Resize ( c amera) ;
Resize ( hdC amera) ;
renderContext . SetupCameraProperties ( camera ) ;
using ( new ProfilingSample ( cmd , "Render SSAO" , GetSampler ( CustomSamplerId . RenderSSAO ) ) )
{
// TODO: Everything here (SSAO, Shadow, Build light list, deferred shadow, material and light classification can be parallelize with Async compute)
RenderSSAO ( cmd , c amera, renderContext , postProcessLayer ) ;
RenderSSAO ( cmd , hdC amera, renderContext , postProcessLayer ) ;
}
GPUFence buildGPULightListsCompleteFence = new GPUFence ( ) ;
using ( new ProfilingSample ( cmd , "Deferred directional shadows" , GetSampler ( CustomSamplerId . RenderDeferredDirectionalShadow ) ) )
{
cmd . ReleaseTemporaryRT ( m_DeferredShadowBuffer ) ;
cmd . GetTemporaryRT ( m_DeferredShadowBuffer , camera . pixelWidth , camera . pixelHeight , 0 , FilterMode . Point , RenderTextureFormat . ARGB32 , RenderTextureReadWrite . Linear , 1 , true ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_DeferredShadowBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGB32 , RenderTextureReadWrite . Linear , 1 , true ) ;
PushFullScreenDebugTexture ( cmd , m_DeferredShadowBuffer , hdCamera . camera , renderContext , FullScreenDebugMode . DeferredShadows ) ;
PushFullScreenDebugTexture ( cmd , m_DeferredShadowBuffer , hdCamera , renderContext , FullScreenDebugMode . DeferredShadows ) ;
}
// TODO: Move this code inside LightLoop
// Fill depth buffer to reduce artifact for transparent object during postprocess
RenderTransparentDepthPostpass ( m_CullResults , camera , renderContext , cmd , ForwardPass . Transparent ) ;
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , c amera, renderContext , FullScreenDebugMode . NanTracker ) ;
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , hdC amera, renderContext , FullScreenDebugMode . NanTracker ) ;
AccumulateDistortion ( m_CullResults , c amera, renderContext , cmd ) ;
RenderDistortion ( cmd , m_Asset . renderPipelineResources ) ;
AccumulateDistortion ( m_CullResults , hdC amera, renderContext , cmd ) ;
RenderDistortion ( cmd , m_Asset . renderPipelineResources , hdCamera ) ;
// Final blit
if ( m_FrameSettings . enablePostprocess & & CoreUtils . IsPostProcessingActive ( postProcessLayer ) )
renderContext . DrawRenderers ( cull . visibleRenderers , ref drawSettings , filterSettings , stateBlock . Value ) ;
}
void AccumulateDistortion ( CullResults cullResults , Camera c amera, ScriptableRenderContext renderContext , CommandBuffer cmd )
void AccumulateDistortion ( CullResults cullResults , HDCamera hdC amera, ScriptableRenderContext renderContext , CommandBuffer cmd )
{
if ( ! m_FrameSettings . enableDistortion )
return ;
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
cmd . GetTemporaryRT ( m_DistortionBuffer , w , h , 0 , FilterMode . Point , Builtin . GetDistortionBufferFormat ( ) , Builtin . GetDistortionBufferReadWrite ( ) ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_DistortionBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetDistortionBufferFormat ( ) , Builtin . GetDistortionBufferReadWrite ( ) ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , HDShaderPassNames . s_DistortionVectorsName ) ;
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , HDShaderPassNames . s_DistortionVectorsName ) ;
void RenderDistortion ( CommandBuffer cmd , RenderPipelineResources resources )
void RenderDistortion ( CommandBuffer cmd , RenderPipelineResources resources , HDCamera hdCamera )
{
if ( ! m_FrameSettings . enableDistortion )
return ;
var size = new Vector4 ( m_CurrentWidth , m_CurrentHeight , 1f / m_CurrentWidth , 1f / m_CurrentHeight ) ;
var size = new Vector4 ( hdCamera . screenSize . x , hdCamera . screenSize . y , 1f / hdCamera . screenSize . x , 1f / hdCamera . screenSize . y ) ;
uint x , y , z ;
m_applyDistortionCS . GetKernelThreadGroupSizes ( m_applyDistortionKernel , out x , out y , out z ) ;
cmd . SetComputeTextureParam ( m_applyDistortionCS , m_applyDistortionKernel , HDShaderIDs . _DistortionTexture , m_DistortionBufferRT ) ;
}
}
void RenderSSAO ( CommandBuffer cmd , Camera camera , ScriptableRenderContext renderContext , PostProcessLayer postProcessLayer )
void RenderSSAO ( CommandBuffer cmd , HDCamera hdCamera , ScriptableRenderContext renderContext , PostProcessLayer postProcessLayer )
var camera = hdCamera . camera ;
// Apply SSAO from PostProcessLayer
if ( m_FrameSettings . enableSSAO & & postProcessLayer ! = null & & postProcessLayer . enabled )
{
{
cmd . ReleaseTemporaryRT ( HDShaderIDs . _AmbientOcclusionTexture ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _AmbientOcclusionTexture , new RenderTextureDescriptor ( camera . pixelWidth , camera . pixelHeight , RenderTextureFormat . R8 , 0 )
{
sRGB = false ,
enableRandomWrite = true
} , FilterMode . Bilinear ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera . renderTextureDesc , 0 , FilterMode . Bilinear , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear , msaaSamples : 1 , enableRandomWrite : true ) ;
PushFullScreenDebugTexture ( cmd , HDShaderIDs . _AmbientOcclusionTexture , camera , renderContext , FullScreenDebugMode . SSAO ) ;
PushFullScreenDebugTexture ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera , renderContext , FullScreenDebugMode . SSAO ) ;
return ;
}
}
// If the flag hasn't been set yet on this camera, motion vectors will skip a frame.
hdcamera . camera . depthTextureMode | = DepthTextureMode . MotionVectors | DepthTextureMode . Depth ;
// Setup stencil buffer
PushFullScreenDebugTexture ( cmd , m_VelocityBuffer , hdcamera . camera , renderContext , FullScreenDebugMode . MotionVectors ) ;
PushFullScreenDebugTexture ( cmd , m_VelocityBuffer , hdcamera , renderContext , FullScreenDebugMode . MotionVectors ) ;
}
}
using ( new ProfilingSample ( cmd , "Gaussian Pyramid Color" , GetSampler ( CustomSamplerId . GaussianPyramidColor ) ) )
{
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
int size = CalculatePyramidSize ( w , h ) ;
var colorPyramidDesc = m_GaussianPyramidColorBufferDesc ;
var pyramidSideSize = colorPyramidDesc . height ;
int lodCount = Mathf . FloorToInt ( Mathf . Log ( size , 2f ) - 3f ) ;
int lodCount = Mathf . FloorToInt ( Mathf . Log ( pyramidSideSize , 2f ) - 3f ) ;
if ( lodCount > HDShaderIDs . _GaussianPyramidColorMips . Length )
{
Debug . LogWarningFormat ( "Cannot compute all mipmaps of the color pyramid, max texture size supported: {0}" , ( 2 < < HDShaderIDs . _GaussianPyramidColorMips . Length ) . ToString ( ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _GaussianPyramidColorMipSize , new Vector4 ( size , size , lodCount , 0 ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _GaussianPyramidColorMipSize , new Vector4 ( pyramidSideSize , pyramidSideSize , lodCount , 0 ) ) ;
cmd . Blit ( m_CameraColorBufferRT , m_GaussianPyramidColorBuffer ) ;
cmd . Blit ( m_CameraColorBufferRT , m_GaussianPyramidColorBufferRT ) ;
var mipSize = size ;
colorPyramidDesc . sRGB = false ;
colorPyramidDesc . enableRandomWrite = true ;
colorPyramidDesc . useMipMap = false ;
mipSize > > = 1 ;
colorPyramidDesc . width = colorPyramidDesc . width > > 1 ;
colorPyramidDesc . height = colorPyramidDesc . height > > 1 ;
// TODO: Add proper stereo support to the compute job
cmd . GetTemporaryRT ( HDShaderIDs . _GaussianPyramidColorMips [ i + 1 ] , mipSize , mipSize , 0 , FilterMode . Bilinear , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _GaussianPyramidColorMips [ i + 1 ] , colorPyramidDesc , FilterMode . Bilinear ) ;
cmd . SetComputeVectorParam ( m_GaussianPyramidCS , "_Size" , new Vector4 ( mipSize , mipSize , 1f / mipSize , 1f / mipSize ) ) ;
cmd . DispatchCompute ( m_GaussianPyramidCS , m_GaussianPyramidKernel , mipSize / 8 , mipSize / 8 , 1 ) ;
cmd . SetComputeVectorParam ( m_GaussianPyramidCS , "_Size" , new Vector4 ( colorPyramidDesc . width , colorPyramidDesc . height , 1f / colorPyramidDesc . width , 1f / colorPyramidDesc . height ) ) ;
cmd . DispatchCompute ( m_GaussianPyramidCS , m_GaussianPyramidKernel , colorPyramidDesc . width / 8 , colorPyramidDesc . height / 8 , 1 ) ;
PushFullScreenDebugTextureMip ( cmd , m_GaussianPyramidColorBufferRT , lodCount , size , size , debugMode ) ;
PushFullScreenDebugTextureMip ( cmd , m_GaussianPyramidColorBufferRT , lodCount , m_GaussianPyramidColorBufferDesc , debugMode ) ;
// TODO: Why don't we use _GaussianPyramidColorMips[0]?
}
}
{
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
int size = CalculatePyramidSize ( w , h ) ;
var depthPyramidDesc = m_DepthPyramidBufferDesc ;
var pyramidSideSize = depthPyramidDesc . height ;
int lodCount = Mathf . FloorToInt ( Mathf . Log ( size , 2f ) - 3f ) ;
int lodCount = Mathf . FloorToInt ( Mathf . Log ( pyramidSideSize , 2f ) - 3f ) ;
if ( lodCount > HDShaderIDs . _DepthPyramidMips . Length )
{
Debug . LogWarningFormat ( "Cannot compute all mipmaps of the depth pyramid, max texture size supported: {0}" , ( 2 < < HDShaderIDs . _DepthPyramidMips . Length ) . ToString ( ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _DepthPyramidMipSize , new Vector4 ( size , size , lodCount , 0 ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _DepthPyramidMipSize , new Vector4 ( pyramidSideSize , pyramidSideSize , lodCount , 0 ) ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ 0 ] , size , size , 0 , FilterMode . Bilinear , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear , 1 , true ) ;
m_GPUCopy . SampleCopyChannel_xyzw2x ( cmd , GetDepthTexture ( ) , HDShaderIDs . _DepthPyramidMips [ 0 ] , new Vector2 ( size , size ) ) ;
cmd . CopyTexture ( HDShaderIDs . _DepthPyramidMips [ 0 ] , 0 , 0 , m_DepthPyramidBuffer , 0 , 0 ) ;
var mipSize = size ;
depthPyramidDesc . sRGB = false ;
depthPyramidDesc . enableRandomWrite = true ;
depthPyramidDesc . useMipMap = false ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ 0 ] , depthPyramidDesc , FilterMode . Bilinear ) ;
m_GPUCopy . SampleCopyChannel_xyzw2x ( cmd , GetDepthTexture ( ) , HDShaderIDs . _DepthPyramidMips [ 0 ] , new Vector2 ( depthPyramidDesc . width , depthPyramidDesc . height ) ) ;
cmd . CopyTexture ( HDShaderIDs . _DepthPyramidMips [ 0 ] , 0 , 0 , m_DepthPyramidBufferRT , 0 , 0 ) ;
int srcMipSize = mipSize ;
mipSize > > = 1 ;
var srcMipWidth = depthPyramidDesc . width ;
var srcMipHeight = depthPyramidDesc . height ;
depthPyramidDesc . width = srcMipWidth > > 1 ;
depthPyramidDesc . height = srcMipHeight > > 1 ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ i + 1 ] , mipSize , mipSize , 0 , FilterMode . Bilinear , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ i + 1 ] , depthPyramidDesc , FilterMode . Bilinear ) ;
cmd . SetComputeVectorParam ( m_DepthPyramidCS , "_SrcSize" , new Vector4 ( srcMipSize , srcMipSize , 1f / srcMipSize , 1f / srcMipSize ) ) ;
cmd . DispatchCompute ( m_DepthPyramidCS , m_DepthPyramidKernel , mipSize / 8 , mipSize / 8 , 1 ) ;
cmd . SetComputeVectorParam ( m_DepthPyramidCS , "_SrcSize" , new Vector4 ( srcMipWidth , srcMipHeight , 1f / srcMipWidth , 1f / srcMipHeight ) ) ;
cmd . DispatchCompute ( m_DepthPyramidCS , m_DepthPyramidKernel , depthPyramidDesc . width / 8 , depthPyramidDesc . height / 8 , 1 ) ;
PushFullScreenDebugDepthMip ( cmd , m_DepthPyramidBufferRT , lodCount , size , size , debugMode ) ;
PushFullScreenDebugDepthMip ( cmd , m_DepthPyramidBufferRT , lodCount , m_DepthPyramidBufferDesc , debugMode ) ;
cmd . SetGlobalTexture ( HDShaderIDs . _DepthPyramidTexture , m_DepthPyramidBuffer ) ;
cmd . SetGlobalVector ( HDShaderIDs . _DebugLightingSmoothness , debugSmoothness ) ;
}
public void PushFullScreenDebugTexture ( CommandBuffer cb , RenderTargetIdentifier textureID , Camera c amera, ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
public void PushFullScreenDebugTexture ( CommandBuffer cb , RenderTargetIdentifier textureID , HDCamera hdC amera, ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
cb . GetTemporaryRT ( m_DebugFullScreenTempRT , camera . pixelWidth , camera . pixelHeight , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
CoreUtils . CreateCmdTemporaryRT ( cb , m_DebugFullScreenTempRT , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
void PushFullScreenDebugTextureMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , int width , int height , FullScreenDebugMode debugMode )
void PushFullScreenDebugTextureMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , RenderTextureDescriptor desc , FullScreenDebugMode debugMode )
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
cmd . GetTemporaryRT ( m_DebugFullScreenTempRT , width > > mipIndex , height > > mipIndex , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ;
desc . width = desc . width > > mipIndex ;
desc . height = desc . height > > mipIndex ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ; // TODO: Support tex arrays
void PushFullScreenDebugDepthMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , int width , int height , FullScreenDebugMode debugMode )
void PushFullScreenDebugDepthMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , RenderTextureDescriptor desc , FullScreenDebugMode debugMode )
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
cmd . GetTemporaryRT ( m_DebugFullScreenTempRT , width > > mipIndex , height > > mipIndex , 0 , FilterMode . Point , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ;
desc . width = desc . width > > mipIndex ;
desc . height = desc . height > > mipIndex ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ; // TODO: Support tex arrays
public void PushFullScreenDebugTexture ( CommandBuffer cb , int textureID , Camera camera , ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
public void PushFullScreenDebugTexture ( CommandBuffer cb , int textureID , HDCamera hdCamera , ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
PushFullScreenDebugTexture ( cb , new RenderTargetIdentifier ( textureID ) , camera , renderContext , debugMode ) ;
PushFullScreenDebugTexture ( cb , new RenderTargetIdentifier ( textureID ) , hdCamera , renderContext , debugMode ) ;
}
void RenderDebug ( HDCamera camera , CommandBuffer cmd )
// Also we manage ourself the HDR format, here allocating fp16 directly.
// With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer
// These temporary surface are release automatically at the end of the scriptable render pipeline if not release explicitly
int w = hdCamera . camera . pixelWidth ;
int h = hdCamera . camera . pixelHeight ;
cmd . GetTemporaryRT ( m_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
cmd . GetTemporaryRT ( m_CameraSssDiffuseLightingBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
int s = CalculatePyramidSize ( w , h ) ;
m_GaussianPyramidColorBufferDesc . width = s ;
m_GaussianPyramidColorBufferDesc . height = s ;
m_GaussianPyramidColorBufferDesc = BuildPyramidDescriptor ( hdCamera , PyramidType . Color , m_FrameSettings . enableStereo ) ;
m_DepthPyramidBufferDesc . width = s ;
m_DepthPyramidBufferDesc . height = s ;
m_DepthPyramidBufferDesc = BuildPyramidDescriptor ( hdCamera , PyramidType . Depth , m_FrameSettings . enableStereo ) ;
cmd . ReleaseTemporaryRT ( m_DepthPyramidBuffer ) ;
cmd . GetTemporaryRT ( m_DepthPyramidBuffer , m_DepthPyramidBufferDesc , FilterMode . Trilinear ) ;
// End
m_GbufferManager . InitGBuffers ( w , h , m_DeferredMaterial , enableBakeShadowMask , cmd ) ;
m_SSSBufferManager . InitSSSBuffersFromGBuffer ( w , h , m_GbufferManager , cmd ) ;
m_GbufferManager . InitGBuffers ( hdCamera . renderTextureDesc , m_DeferredMaterial , enableBakeShadowMask , cmd ) ;
m_SSSBufferManager . InitSSSBuffersFromGBuffer ( m_GbufferManager ) ;
m_SSSBufferManager . InitSSSBuffers ( w , h , cmd ) ;
m_SSSBufferManager . InitSSSBuffers ( hdCamera . renderTextureDesc , cmd ) ;
m_DbufferManager . InitDBuffers ( w , h , cmd ) ;
m_DbufferManager . InitDBuffers ( hdCamera . renderTextureDesc , cmd ) ;
cmd . GetTemporaryRT ( m_VelocityBuffer , w , h , 0 , FilterMode . Point , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_VelocityBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
}
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT , ClearFlag . Depth ) ;
static int CalculatePyramidSize ( int w , int h )
{
return Mathf . ClosestPowerOfTwo ( Mathf . Min ( w , h ) ) ;
}
public enum PyramidType
{
Color = 0 ,
Depth = 1
}
static RenderTextureDescriptor BuildPyramidDescriptor ( HDCamera hdCamera , PyramidType pyramidType , bool stereoEnabled )
{
var desc = hdCamera . renderTextureDesc ;
desc . colorFormat = ( pyramidType = = PyramidType . Color ) ? RenderTextureFormat . ARGBHalf : RenderTextureFormat . RFloat ;
desc . depthBufferBits = 0 ;
desc . useMipMap = true ;
desc . autoGenerateMips = false ;
var pyramidSize = CalculatePyramidSize ( ( int ) hdCamera . screenSize . x , ( int ) hdCamera . screenSize . y ) ;
// for stereo double-wide, each half of the texture will represent a single eye's pyramid
//var widthModifier = 1;
//if (stereoEnabled && (desc.dimension != TextureDimension.Tex2DArray))
// widthModifier = 2; // double-wide
//desc.width = pyramidSize * widthModifier;
desc . width = pyramidSize ;
desc . height = pyramidSize ;
return desc ;
}
}
}