}
}
}
#endif
private HDRenderPipeline ( )
public Vector4 screenSize ;
public Matrix4x4 viewProjectionMatrix ;
public Matrix4x4 invViewProjectionMatrix ;
}
}
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0 ;
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0 ;
// Rendering debugging
public bool displayOpaqueObjects = true ;
public bool displayTransparentObjects = true ;
// Rendering debugging
public bool displayOpaqueObjects = true ;
public bool displayTransparentObjects = true ;
public bool useForwardRenderingOnly = false ; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false ;
public bool useDistortion = true ;
public bool useForwardRenderingOnly = false ; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false ;
public bool useDistortion = true ;
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly ( ) { return useForwardRenderingOnly | | GL . wireframe ; }
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly ( )
{
return useForwardRenderingOnly | | GL . wireframe ;
}
public class GBufferManager
{
public const int MaxGbuffer = 8 ;
public class GBufferManager
{
public const int MaxGbuffer = 8 ;
public void SetBufferDescription ( int index , string stringId , RenderTextureFormat inFormat , RenderTextureReadWrite inSRGBWrite )
{
IDs [ index ] = Shader . PropertyToID ( stringId ) ;
RTIDs [ index ] = new RenderTargetIdentifier ( IDs [ index ] ) ;
formats [ index ] = inFormat ;
sRGBWrites [ index ] = inSRGBWrite ;
}
public void SetBufferDescription ( int index , string stringId , RenderTextureFormat inFormat , RenderTextureReadWrite inSRGBWrite )
{
IDs [ index ] = Shader . PropertyToID ( stringId ) ;
RTIDs [ index ] = new RenderTargetIdentifier ( IDs [ index ] ) ;
formats [ index ] = inFormat ;
sRGBWrites [ index ] = inSRGBWrite ;
}
public void InitGBuffers ( int width , int height , CommandBuffer cmd )
public void InitGBuffers ( int width , int height , CommandBuffer cmd )
{
for ( int index = 0 ; index < gbufferCount ; index + + )
for ( int index = 0 ; index < gbufferCount ; index + + )
{
}
}
public RenderTargetIdentifier [ ] GetGBuffers ( )
public RenderTargetIdentifier [ ] GetGBuffers ( )
{
var colorMRTs = new RenderTargetIdentifier [ gbufferCount ] ;
for ( int index = 0 ; index < gbufferCount ; index + + )
var colorMRTs = new RenderTargetIdentifier [ gbufferCount ] ;
for ( int index = 0 ; index < gbufferCount ; index + + )
{
colorMRTs [ index ] = RTIDs [ index ] ;
}
colorMRTs [ index ] = RTIDs [ index ] ;
}
return colorMRTs ;
}
return colorMRTs ;
}
/ *
/ *
public void BindBuffers ( Material mat )
{
for ( int index = 0 ; index < gbufferCount ; index + + )
}
* /
public int gbufferCount { get ; set ; }
int [ ] IDs = new int [ MaxGbuffer ] ;
RenderTargetIdentifier [ ] RTIDs = new RenderTargetIdentifier [ MaxGbuffer ] ;
RenderTextureFormat [ ] formats = new RenderTextureFormat [ MaxGbuffer ] ;
RenderTextureReadWrite [ ] sRGBWrites = new RenderTextureReadWrite [ MaxGbuffer ] ;
}
public int gbufferCount { get ; set ; }
int [ ] IDs = new int [ MaxGbuffer ] ;
RenderTargetIdentifier [ ] RTIDs = new RenderTargetIdentifier [ MaxGbuffer ] ;
RenderTextureFormat [ ] formats = new RenderTextureFormat [ MaxGbuffer ] ;
RenderTextureReadWrite [ ] sRGBWrites = new RenderTextureReadWrite [ MaxGbuffer ] ;
}
{
{
private readonly HDRenderPipeline m_Owner ;
// TODO: Find a way to automatically create/iterate through deferred material
m_Owner = owner ;
m_CameraColorBuffer = Shader . PropertyToID ( "_CameraColorTexture" ) ;
m_CameraDepthBuffer = Shader . PropertyToID ( "_CameraDepthTexture" ) ;
m_CameraDepthBuffer = Shader . PropertyToID ( "_CameraDepthTexture" ) ;
m_CameraColorBufferRT = new RenderTargetIdentifier ( m_CameraColorBuffer ) ;
m_CameraDepthBufferRT = new RenderTargetIdentifier ( m_CameraDepthBuffer ) ;
m_DistortionBufferRT = new RenderTargetIdentifier ( m_DistortionBuffer ) ;
m_LitRenderLoop . Build ( ) ;
m_lightLoop = new LightLoop ( owner ) ;
m_lightLoop . Build ( owner . textureSettings ) ;
Shader . SetGlobalInt ( "_EnvLightSkyEnabled" , 1 ) ;
}
else
{
{
}
}
var cmd = new CommandBuffer { name = "Push Global Parameters" } ;
var cmd = new CommandBuffer { name = "Push Global Parameters" } ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
}
public override void Render ( ScriptableRenderContext renderContext , Camera [ ] cameras )
{
return ;
// Set camera constant buffer
// TODO...
// TODO...
CullingParameters cullingParams ;
if ( ! CullResults . GetCullingParameters ( camera , out cullingParams ) )
renderContext . SetupCameraProperties ( camera ) ;
HDCamera hdCamera = Utilities . GetHDCamera ( camera ) ;
// TODO: Find a correct place to bind these material textures
// We have to bind the material specific global parameters in this mode
m_LitRenderLoop . Bind ( ) ;
ShadowOutput shadows ;
using ( new Utilities . ProfilingSample ( "Shadow Pass" , renderContext ) )
{
{
}
}
{
{
m_lightLoop . PrepareLightsForGPU ( m_Owner . shadowSettings , cullResults , camera , ref shadows ) ;
m_lightLoop . BuildGPULightLists ( camera , renderContext , m_CameraDepthBufferRT ) ; // TODO: Use async compute here to run light culling during shadow
}
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment ( hdCamera , renderContext ) ;
// bind depth surface for editor grid/gizmo/selection rendering
if ( camera . cameraType = = CameraType . SceneView )
{
{
var cmd = new CommandBuffer ( ) ;
cmd . SetRenderTarget ( BuiltinRenderTextureType . CameraTarget , m_CameraDepthBufferRT ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
{
rendererConfiguration = rendererConfiguration ,
sorting = { flags = SortFlags . CommonOpaque }
sorting = { flags = SortFlags . CommonOpaque }
} ;
settings . inputFilter . SetQueuesOpaque ( ) ;
renderContext . DrawRenderers ( settings ) ;
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
{
rendererConfiguration = rendererConfiguration ,
sorting = { flags = SortFlags . CommonTransparent }
sorting = { flags = SortFlags . CommonTransparent }
} ;
settings . inputFilter . SetQueuesTransparent ( ) ;
renderContext . DrawRenderers ( settings ) ;
{
if ( debugParameters . ShouldUseForwardRenderingOnly ( ) )
{
return ;
return ;
}
using ( new Utilities . ProfilingSample ( "GBuffer Pass" , renderContext ) )
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" } ;
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" } ;
cmd . Blit ( null , m_CameraColorBufferRT , m_DebugViewMaterialGBuffer , 0 ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
// Last blit
{
var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" } ;
var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" } ;
cmd . Blit ( m_CameraColorBufferRT , BuiltinRenderTextureType . CameraTarget ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
{
if ( debugParameters . ShouldUseForwardRenderingOnly ( ) )
{
return ;
return ;
}
m_lightLoop . RenderDeferredLighting ( hdCamera , renderContext , m_CameraColorBuffer ) ;
{
m_SkyManager . RenderSky ( hdCamera , m_lightLoop . GetCurrentSunLight ( ) , m_CameraColorBufferRT , m_CameraDepthBufferRT , renderContext ) ;
}
void RenderForward ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext , bool renderOpaque )
{
// TODO: Currently we can't render opaque object forward when deferred is enabled
{
// If opaque velocity have been render during GBuffer no need to render it here
if ( ( ShaderConfig . s_VelocityInGbuffer = = 1 ) | | debugParameters . ShouldUseForwardRenderingOnly ( ) )
return ;
return ;
var cmd = new CommandBuffer { name = "" } ;
var cmd = new CommandBuffer { name = "" } ;
cmd . GetTemporaryRT ( m_VelocityBuffer , w , h , 0 , FilterMode . Point , Builtin . RenderLoop . GetVelocityBufferFormat ( ) , Builtin . RenderLoop . GetVelocityBufferReadWrite ( ) ) ;
cmd . SetRenderTarget ( m_VelocityBufferRT , m_CameraDepthBufferRT ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
void RenderDistortion ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext )
{
if ( ! debugParameters . useDistortion )
return ;
return ;
using ( new Utilities . ProfilingSample ( "Distortion Pass" , renderContext ) )
{
var cmd = new CommandBuffer { name = "" } ;
var cmd = new CommandBuffer { name = "" } ;
cmd . GetTemporaryRT ( m_DistortionBuffer , w , h , 0 , FilterMode . Point , Builtin . RenderLoop . GetDistortionBufferFormat ( ) , Builtin . RenderLoop . GetDistortionBufferReadWrite ( ) ) ;
cmd . SetRenderTarget ( m_DistortionBufferRT , m_CameraDepthBufferRT ) ;
cmd . ClearRenderTarget ( false , true , Color . black ) ; // TODO: can we avoid this clear for performance ?
if ( ! localActive )
{
var cmd = new CommandBuffer { name = "" } ;
var cmd = new CommandBuffer { name = "" } ;
cmd . Blit ( m_CameraColorBufferRT , BuiltinRenderTextureType . CameraTarget ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
}
// Function to prepare light structure for GPU lighting
void PrepareLightsForGPU ( ShadowSettings shadowSettings , CullResults cullResults , Camera camera , ref ShadowOutput shadowOutput )
{
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
cmd . GetTemporaryRT ( m_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
cmd . GetTemporaryRT ( m_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
{
{
}
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
}
{
{
}
}
{
{
{
{
}
}
// END TEMP
}
}