public bool displayOpaqueObjects = true ;
public bool displayTransparentObjects = true ;
public bool useForwardRenderingOnly = false ;
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 enableTonemap = true ;
public float exposure = 0 ;
// TODO: Find a way to automatically create/iterate through these kind of class
Lit . RenderLoop m_LitRenderLoop ;
Builtin . RenderLoop m_BuiltinRenderLoop ;
// Debug
Material m_DebugViewMaterialGBuffer ;
static private int s_CameraColorBuffer ;
static private int s_CameraDepthBuffer ;
static private int s_VelocityBuffer ;
#if VELOCITY_IN_GBUFFER
private const bool m_velocityInGBuffer = true ;
#else
private const bool m_velocityInGBuffer = false ;
#endif
private bool m_requireVelocityBuffer = false ;
static private ComputeBuffer s_punctualLightList ;
static private ComputeBuffer s_envLightList ;
// Init Lit material buffer - GBuffer and init
m_LitRenderLoop = new Lit . RenderLoop ( ) ; // Our object can be garbacge collected, so need to be allocate here
m_BuiltinRenderLoop = new Builtin . RenderLoop ( ) ;
m_gbufferManager . gbufferCount = m_LitRenderLoop . GetGBufferCount ( ) ;
for ( int gbufferIndex = 0 ; gbufferIndex < m_gbufferManager . gbufferCount ; + + gbufferIndex )
// In forward we still name the buffer as if they were gbuffer, it doesn't matter
int previousGbufferCount = m_gbufferManager . gbufferCount ;
m_gbufferManager . gbufferCount + = m_BuiltinRenderLoop . GetGBufferCount ( ) ;
for ( int gbufferIndex = previousGbufferCount ; gbufferIndex < m_gbufferManager . gbufferCount ; + + gbufferIndex )
{
m_gbufferManager . SetBufferDescription ( gbufferIndex , "_CameraGBufferTexture" + gbufferIndex , m_BuiltinRenderLoop . RTFormat [ gbufferIndex ] , m_BuiltinRenderLoop . RTReadWrite [ gbufferIndex ] ) ;
}
s_VelocityBuffer = Shader . PropertyToID ( "_VelocityTexture" ) ;
if ( m_velocityInGBuffer )
{
int gbufferIndex = m_gbufferManager . gbufferCount ;
m_gbufferManager . gbufferCount + + ;
m_gbufferManager . SetBufferDescription ( gbufferIndex , "_VelocityTexture" , m_BuiltinRenderLoop . RTFormat [ gbufferIndex ] , m_BuiltinRenderLoop . RTReadWrite [ gbufferIndex ] ) ;
}
m_BuiltinRenderLoop . Rebuild ( ) ;
}
void OnDisable ( )
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
cmd . GetTemporaryRT ( s_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Default ) ;
cmd . GetTemporaryRT ( s_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
m_gbufferManager . InitGBuffers ( w , h , cmd ) ;
if ( ! debugParameters . useForwardRenderingOnly )
{
m_gbufferManager . InitGBuffers ( w , h , cmd ) ;
}
cmd . SetRenderTarget ( new RenderTargetIdentifier ( s_CameraColorBuffer ) , new RenderTargetIdentifier ( s_CameraDepthBuffer ) ) ;
cmd . ClearRenderTarget ( true , false , new Color ( 0 , 0 , 0 , 0 ) ) ;
// END TEMP
}
// TODO: Create an opaque and transparent list!
void RenderOpaqueRenderList ( CullResults cull , Camera camera , RenderLoop renderLoop , string passName )
{
if ( ! debugParameters . displayOpaqueObjects )
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
{
rendererConfiguration = RendererConfiguration . PerObjectLightProbe | RendererConfiguration . PerObjectReflectionProbes ,
sorting = { sortOptions = SortOptions . SortByMaterialThenMesh }
rendererConfiguration = RendererConfiguration . PerObjectLightProbe | RendererConfiguration . PerObjectReflectionProbes | RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbeProxyVolume ,
sorting = { sortOptions = SortOptions . BackToFront }
} ;
settings . inputFilter . SetQueuesTransparent ( ) ;
renderLoop . DrawRenderers ( ref settings ) ;
{
if ( debugParameters . useForwardRenderingOnly )
{
return ;
return ;
}
// Bind material data
RenderTransparentRenderList ( cullResults , camera , renderLoop , "ForwardUnlit" ) ;
}
void RenderVelocity ( CullResults cullResults , Camera camera , RenderLoop renderLoop )
{
int w = camera . pixelWidth ;
int h = camera . pixelHeight ;
var cmd = new CommandBuffer { name = "Velocity Pass" } ;
// If we are not using the velocity buffer inside GBuffer, allocate one
if ( m_requireVelocityBuffer )
{
cmd . GetTemporaryRT ( s_VelocityBuffer , w , h , 0 , FilterMode . Point , m_BuiltinRenderLoop . GetVelocityBufferFormat ( ) , m_BuiltinRenderLoop . GetVelocityBufferReadWrite ( ) ) ;
}
cmd . SetRenderTarget ( new RenderTargetIdentifier ( s_VelocityBuffer ) , new RenderTargetIdentifier ( s_CameraDepthBuffer ) ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
// If opaque haven't been render during gbuffer pass, render them now
if ( m_requireVelocityBuffer )
{
RenderOpaqueRenderList ( cullResults , camera , renderLoop , "MotionVectors" ) ;
}
RenderTransparentRenderList ( cullResults , camera , renderLoop , "MotionVectors" ) ;
}
void FinalPass ( RenderLoop renderLoop )
{
// Those could be tweakable for the neutral tonemapper, but in the case of the LookDev we don't need that
m_LitRenderLoop . RenderInit ( renderLoop ) ;
}
// Allocate a velocity buffer if we are forward only or if we haven't set the velocity buffer to be part of GBuffer
m_requireVelocityBuffer = debugParameters . useForwardRenderingOnly | | ( ! debugParameters . useForwardRenderingOnly & & ! m_velocityInGBuffer ) ;
// Do anything we need to do upon a new frame.
NewFrame ( ) ;
RenderForward ( cullResults , camera , renderLoop ) ;
RenderForwardUnlit ( cullResults , camera , renderLoop ) ;
// Render as late as possible to benefit from an up to date depth buffer (TODO: could use equal depth test ?)
RenderVelocity ( cullResults , camera , renderLoop ) ;
FinalPass ( renderLoop ) ;
}
// Post effects
}
#if UNITY_EDITOR
#if UNITY_EDITOR
public override UnityEditor . SupportedRenderingFeatures GetSupportedRenderingFeatures ( )
{
var features = new UnityEditor . SupportedRenderingFeatures
return features ;
}
#endif
#endif
}
}