**NOTE**: this is a testbed for a Unity feature that has not shipped yet! The project will not work with any public
**NOTE**: this is a testbed for a Unity feature that has not shipped yet! The project does not work with any public
Unity version, and things in it might and will be broken.
"Scriptable Render Loops" is a potential future Unity feature, think "Command Buffers, take two". We plan to ship the feature, and a
There's a more detailed overview document here: [ScriptableRenderLoop google doc](https://docs.google.com/document/d/1e2jkr_-v5iaZRuHdnMrSv978LuJKYZhsIYnrDkNAuvQ/edit?usp=sharing)
Did we mention it's a very WIP, no promises, may or might not ship feature, anything and everything in it can change? It totally is.
## For Unity 5.6 beta users
* Unity 5.6 beta 1 and beta 2 should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.
// const variable produce warning like this one: warning CS0162: Unreachable code detected
// If we want to avoid them we can add #pragma warning disable 162, however doing that make the debugger shift his line count when debugging which is really annoying
// so here we decalare two kind of variable, one const that can be use in enum init and one static so the compiler doesn't complain. It mean that the conditional code will stay
// but it is usually small, so we are fine with it (until someone at microsoft fix the debuggger).
// TODO: This is the max value allowed for emissive (bad name - but keep for now to retrieve it) (It is 8^2.2 (gamma) and 8 is the limit of punctual light slider...), comme from UnityCg.cginc. Fix it!
// Ask Jesper if this can be change for HDRenderLoop
// Ask Jesper if this can be change for HDRenderPipeline
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
vargpuVP=gpuProj*worldToViewMatrix*Matrix4x4.Scale(newVector3(1.0f,1.0f,-1.0f));// Need to scale -1.0 on Z to match what is being done in the camera.wolrdToCameraMatrix API.
Debug.LogWarning("RenderCubemapGGXConvolution: Cubemap size is too small for GGX convolution, needs at least "+((int)EnvConstants.SpecCubeLodStep+1)+" mip levels");
return;
}
// Copy the first mip.
// TEMP code until CopyTexture is implemented for command buffer
// All parameters are neutral because exposure/multiplier have already been applied in the first copy.
// TODO: can we have some kind of hash value here ? +> use or override GetHashCode() + include a refresh rate value in parameters
// TODO: we could apply multiplier/exposure and rotation on the final result (i.e on the sky ibl and on lightprobe / lightmap, but can be tricky as Unity seems to merge sky information with
publicbooluseForwardRenderingOnly=false;// TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
publicbooluseDepthPrepass=false;
publicbooluseDistortion=true;
publicboolenableTonemap=true;
publicfloatexposure=0;
publicTextureSettingstextureSettings
{
get{returnm_TextureSettings;}
set{m_TextureSettings=value;}
}
// Various set of material use in render loop
intm_VelocityBuffer;
intm_DistortionBuffer;
publicboolm_Dirty=false;
RenderTargetIdentifierm_CameraColorBufferRT;
RenderTargetIdentifierm_CameraDepthBufferRT;
RenderTargetIdentifierm_VelocityBufferRT;
intm_WidthOnRecord;
intm_HeightOnRecord;
intm_currentWidth;
intm_currentHeight;
// This must be allocate outside of Rebuild() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
// Keep these settings safe to recover when leaving the render pipeline
boolpreviousLightsUseLinearIntensity;
boolpreviousLightsUseCCT;
// This must be allocate outside of Build() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
BaseLightLoopm_lightLoop=newTilePass.LightLoop();
publicBaseLightLooplightLoop
// TODO: Find a way to automatically create/iterate through deferred material
// TODO TO CHECK: SebL I move allocation from Rebuild() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?
// TODO TO CHECK: SebL I move allocation from Build() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?
publicvoidOnValidate()
publicstructHDCamera
// Calling direction Rebuild() here cause this warning:
// "SendMessage cannot be called during Awake, CheckConsistency, or OnValidate UnityEngine.Experimental.ScriptableRenderLoop.HDRenderLoop:OnValidate()"
// Workaround is to declare this dirty flag and call REbuild in Render()
m_Dirty=true;
publicCameracamera;
publicVector4screenSize;
publicMatrix4x4viewProjectionMatrix;
publicMatrix4x4invViewProjectionMatrix;
publicoverridevoidRebuild()
CommonSettingsm_CommonSettings=null;
publicCommonSettingscommonSettings
// We call Cleanup() here because Rebuild() can be call by OnValidate(), i.e when inspector is touch
// Note that module don't need to do the same as the call here is propagated correctly
// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyRenderer.Resize(m_SkyParameters);// TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
m_SkyManager.Resize();// TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
RenderVelocity(cullResults,camera,renderLoop);// Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
RenderVelocity(cullResults,camera,renderContext);// Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
// Contain value return by SV_POSITION (That is name positionCS in PackedVarying).
// xy: unormalized screen position (offset by 0.5), z: device depth, w: depth in view space
// Note: SV_POSITION is the result of the clip space position provide to the vertex shaders that is transform by the viewport
float4 unPositionSS; // In case depth offset is use, positionWS.w is equal to depth offset
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
float4 vertexColor;
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
// CAUTION: Only use with velocity currently, null else
// Note: Z component is not use currently
// This is the clip space position. Warning, do not confuse with the value of positionCS in PackedVarying which is SV_POSITION and store in unPositionSS