int m_VelocityBuffer ;
int m_DistortionBuffer ;
RenderTargetIdentifier s _CameraColorBufferRT;
RenderTargetIdentifier s _CameraDepthBufferRT;
RenderTargetIdentifier s _VelocityBufferRT;
RenderTargetIdentifier s _DistortionBufferRT;
RenderTargetIdentifier m _CameraColorBufferRT;
RenderTargetIdentifier m _CameraDepthBufferRT;
RenderTargetIdentifier m _VelocityBufferRT;
RenderTargetIdentifier m _DistortionBufferRT;
public class LightList
m_CameraColorBuffer = Shader . PropertyToID ( "_CameraColorTexture" ) ;
m_CameraDepthBuffer = Shader . PropertyToID ( "_CameraDepthTexture" ) ;
s _CameraColorBufferRT = new RenderTargetIdentifier ( s _CameraColorBuffer) ;
s _CameraDepthBufferRT = new RenderTargetIdentifier ( s _CameraDepthBuffer) ;
m _CameraColorBufferRT = new RenderTargetIdentifier ( m _CameraColorBuffer) ;
m _CameraDepthBufferRT = new RenderTargetIdentifier ( m _CameraDepthBuffer) ;
m_SkyRenderer = new SkyRenderer ( ) ;
m_SkyRenderer . Rebuild ( ) ;
m_gbufferManager . SetBufferDescription ( m_gbufferManager . gbufferCount , "_VelocityTexture" , Builtin . RenderLoop . GetVelocityBufferFormat ( ) , Builtin . RenderLoop . GetVelocityBufferReadWrite ( ) ) ;
m_gbufferManager . gbufferCount + + ;
}
s _VelocityBufferRT = new RenderTargetIdentifier ( s _VelocityBuffer) ;
m _VelocityBufferRT = new RenderTargetIdentifier ( m _VelocityBuffer) ;
s _DistortionBufferRT = new RenderTargetIdentifier ( s _DistortionBuffer) ;
m _DistortionBufferRT = new RenderTargetIdentifier ( m _DistortionBuffer) ;
m_LitRenderLoop . Rebuild ( ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
Utilities . SetRenderTarget ( renderLoop , s_CameraColorBufferRT , s _CameraDepthBufferRT, ClearFlag . ClearDepth ) ;
Utilities . SetRenderTarget ( renderLoop , m_CameraColorBufferRT , m _CameraDepthBufferRT, ClearFlag . ClearDepth ) ;
}
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
Utilities . SetRenderTarget ( renderLoop , s_CameraColorBufferRT , s _CameraDepthBufferRT, ClearFlag . ClearColor , Color . black , "Clear HDR target" ) ;
Utilities . SetRenderTarget ( renderLoop , m_CameraColorBufferRT , m _CameraDepthBufferRT, ClearFlag . ClearColor , Color . black , "Clear HDR target" ) ;
Utilities . SetRenderTarget ( renderLoop , m_gbufferManager . GetGBuffers ( ) , s _CameraDepthBufferRT, ClearFlag . ClearColor , Color . black , "Clear GBuffer" ) ;
Utilities . SetRenderTarget ( renderLoop , m_gbufferManager . GetGBuffers ( ) , m _CameraDepthBufferRT, ClearFlag . ClearColor , Color . black , "Clear GBuffer" ) ;
}
// END TEMP
// TODO: Must do opaque then alpha masked for performance!
// TODO: front to back for opaque and by materal for opaque tested when we split in two
Utilities . SetRenderTarget ( renderLoop , s _CameraDepthBufferRT, "Depth Prepass" ) ;
Utilities . SetRenderTarget ( renderLoop , m _CameraDepthBufferRT, "Depth Prepass" ) ;
RenderOpaqueRenderList ( cull , camera , renderLoop , "DepthOnly" ) ;
}
}
// setup GBuffer for rendering
Utilities . SetRenderTarget ( renderLoop , m_gbufferManager . GetGBuffers ( ) , s _CameraDepthBufferRT, "GBuffer Pass" ) ;
Utilities . SetRenderTarget ( renderLoop , m_gbufferManager . GetGBuffers ( ) , m _CameraDepthBufferRT, "GBuffer Pass" ) ;
// render opaque objects into GBuffer
RenderOpaqueRenderList ( cull , camera , renderLoop , "GBuffer" , Utilities . kRendererConfigurationBakedLighting ) ;
}
return ;
// TODO: Use the render queue index to only send the forward opaque!
Utilities . SetRenderTarget ( renderLoop , s _CameraDepthBufferRT, "Clear HDR target" ) ;
Utilities . SetRenderTarget ( renderLoop , m _CameraDepthBufferRT, "Clear HDR target" ) ;
RenderOpaqueRenderList ( cull , camera , renderLoop , "DepthOnly" ) ;
}
{
Utilities . SetRenderTarget ( renderLoop , s_CameraColorBufferRT , s _CameraDepthBufferRT, Utilities . kClearAll , Color . black , "DebugView Material Mode Pass" ) ;
Utilities . SetRenderTarget ( renderLoop , m_CameraColorBufferRT , m _CameraDepthBufferRT, Utilities . kClearAll , Color . black , "DebugView Material Mode Pass" ) ;
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) debugParameters . debugViewMaterial ) ;
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" } ;
cmd . Blit ( null , s _CameraColorBufferRT, m_DebugViewMaterialGBuffer , 0 ) ;
cmd . Blit ( null , m _CameraColorBufferRT, m_DebugViewMaterialGBuffer , 0 ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
// Last blit
{
var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" } ;
cmd . Blit ( s _CameraColorBufferRT, BuiltinRenderTextureType . CameraTarget ) ;
cmd . Blit ( m _CameraColorBufferRT, BuiltinRenderTextureType . CameraTarget ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "Deferred Ligthing Pass" } ;
cmd . Blit ( null , s _CameraColorBufferRT, m_DeferredMaterial , 0 ) ;
cmd . Blit ( null , m _CameraColorBufferRT, m_DeferredMaterial , 0 ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}
m_SkyRenderer . RenderSky ( camera , m_SkyParameters , s_CameraColorBufferRT , s _CameraDepthBufferRT, renderLoop ) ;
m_SkyRenderer . RenderSky ( camera , m_SkyParameters , m_CameraColorBufferRT , m _CameraDepthBufferRT, renderLoop ) ;
}
void RenderForward ( CullResults cullResults , Camera camera , RenderLoop renderLoop )
Utilities . SetRenderTarget ( renderLoop , s_CameraColorBufferRT , s _CameraDepthBufferRT, "Forward Pass" ) ;
Utilities . SetRenderTarget ( renderLoop , m_CameraColorBufferRT , m _CameraDepthBufferRT, "Forward Pass" ) ;
if ( debugParameters . useForwardRenderingOnly )
{
// Bind material data
m_LitRenderLoop . Bind ( ) ;
Utilities . SetRenderTarget ( renderLoop , s_CameraColorBufferRT , s _CameraDepthBufferRT, "Forward Unlit Pass" ) ;
Utilities . SetRenderTarget ( renderLoop , m_CameraColorBufferRT , m _CameraDepthBufferRT, "Forward Unlit Pass" ) ;
RenderOpaqueRenderList ( cullResults , camera , renderLoop , "ForwardUnlit" ) ;
RenderTransparentRenderList ( cullResults , camera , renderLoop , "ForwardUnlit" ) ;
}
var cmd = new CommandBuffer { name = "Velocity Pass" } ;
cmd . GetTemporaryRT ( m_VelocityBuffer , w , h , 0 , FilterMode . Point , Builtin . RenderLoop . GetVelocityBufferFormat ( ) , Builtin . RenderLoop . GetVelocityBufferReadWrite ( ) ) ;
cmd . SetRenderTarget ( s_VelocityBufferRT , s _CameraDepthBufferRT) ;
cmd . SetRenderTarget ( m_VelocityBufferRT , m _CameraDepthBufferRT) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
var cmd = new CommandBuffer { name = "Distortion Pass" } ;
cmd . GetTemporaryRT ( m_DistortionBuffer , w , h , 0 , FilterMode . Point , Builtin . RenderLoop . GetDistortionBufferFormat ( ) , Builtin . RenderLoop . GetDistortionBufferReadWrite ( ) ) ;
cmd . SetRenderTarget ( s_DistortionBufferRT , s _CameraDepthBufferRT) ;
cmd . SetRenderTarget ( m_DistortionBufferRT , m _CameraDepthBufferRT) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
var cmd = new CommandBuffer { name = "FinalPass" } ;
// Resolve our HDR texture to CameraTarget.
cmd . Blit ( s _CameraColorBufferRT, BuiltinRenderTextureType . CameraTarget , m_FinalPassMaterial , 0 ) ;
cmd . Blit ( m _CameraColorBufferRT, BuiltinRenderTextureType . CameraTarget , m_FinalPassMaterial , 0 ) ;
renderLoop . ExecuteCommandBuffer ( cmd ) ;
cmd . Dispose ( ) ;
}