Debug.Assert(bFoundAvailOrExistingSlice,"The texture cache doesn't have enough space to store all textures. Please either increase the size of the texture cache, or use fewer unique textures.");
if(bFoundAvailOrExistingSlice)
{
m_SliceArray[sliceIndex].countLRU=0;// mark slice as in use this frame
publicfloatlightLength=0.0f;// Area & projector lights
[FormerlySerializedAs("lightLength")]
publicfloatshapeLength=0.5f;
// Only for Rectangle/projector lights
publicfloatlightWidth=0.0f;// Area & projector lights
[FormerlySerializedAs("lightWidth")]
publicfloatshapeWidth=0.5f;
// Only for Sphere/Disc
publicfloatshapeRadius=0.0f;
// Only for Spot/Point - use to cheaply fake specular spherical area light
publicfloatmaxSmoothness=1.0f;// this is use with punctual light to fake an area lights
publicfloatmaxSmoothness=1.0f;
// If true, we apply the smooth attenuation factor on the range attenuation to get 0 value, else the attenuation is just inverse square and never reach 0
publicboolapplyRangeAttenuation=true;
// This is specific for the LightEditor GUI and not use at runtime
publicbooluseOldInspector=false;
publicboolshowAdditionalSettings=true;// TODO: Maybe we can remove if if we decide to always show additional settings
#if UNITY_EDITOR
publicboolapplyRangeAttenuation=true;// If true, we apply the smooth attenuation factor on the range attenuation to get 0 value, else the attenuation is juste inverse square and never reach 0
privatevoidDrawGizmos(boolselected)
{
varlight=gameObject.GetComponent<Light>();
vargizmoColor=light.color;
gizmoColor.a=selected?1.0f:0.3f;// Fade for the gizmo
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs. Please don't edit by hand.
publicbooluseForwardRenderingOnly=false;// TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
// We have to fall back to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
Materialm_CameraMotionVectorsMaterial;
// Debug material
#if UNITY_EDITOR
Materialm_ErrorMaterial;
#endif
// Various buffer
readonlyintm_CameraColorBuffer;
readonlyintm_VelocityBuffer;
readonlyintm_DistortionBuffer;
readonlyintm_DeferredShadowBuffer;
// 'm_CameraColorBuffer' does not contain diffuse lighting of SSS materials until the SSS pass. It is stored within 'm_CameraSssDiffuseLightingBuffer'.
// These need to be Runtime Only because those values are hold by the HDRenderPipeline asset so if user change them through the editor debug menu they might change the value in the asset without noticing it.
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Big Tile",()=>(bool)m_Asset.tileSettings.enableBigTilePrepass,(value)=>m_Asset.tileSettings.enableBigTilePrepass=(bool)value,DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Material Classification",()=>(bool)m_Asset.tileSettings.enableComputeMaterialVariants,(value)=>m_Asset.tileSettings.enableComputeMaterialVariants=(bool)value,DebugItemFlag.RuntimeOnly);
// When doing a prepass, we don't need to write the depth anymore.
// Moreover, we need to use DepthEqual because for alpha tested materials we don't do the clip in the shader anymore (otherwise HiZ does not work on PS4)
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// 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,cmd);
// Don't update the sky environment if we are rendering a cubemap (it should be update already)
if(camera.cameraType!=CameraType.Reflection)
{
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// 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,cmd);
}
// For opaque forward we have split rendering in two categories
// Material that are always forward and material that can be deferred or forward depends on render pipeline options (like switch to rendering forward only mode)
// Material that are always forward are unlit and complex (Like Hair) and don't require sorting, so it is ok to split them.
RenderForward(m_CullResults,camera,renderContext,cmd,true);// Render deferred or forward opaque
// RenderDepthPrepass render both opaque and opaque alpha tested based on engine configuration.
// Forward only renderer: We always render everything
// Deferred renderer: We render a depth prepass only if engine request it. We can decide if we render everything or only opaque alpha tested object.
// Forward opaque with deferred renderer (ForwardOnlyOpaqueDepthOnly pass): We always render everything
if(!m_Asset.renderingSettings.useDepthPrepass)
// Guidelines: To be able to switch from deferred to forward renderer we need to have forward opaque material with both DepthOnly and ForwardOnlyOpaqueDepthOnly pass.
// This is also required if we want to support optional depth prepass dynamically.
// This is what is assume here. But users may want to reduce number of shader combination once they have made their choice.
// In case of forward only renderer we have a depth prepass. In case of deferred renderer, it is optional
// In case of deferred renderer, we can have forward opaque material. These materials need to be render in the depth buffer to correctly build the light list. And they will tag the stencil to not be lit during the deferred lighting pass.
// Caution: If a DepthPrepass is enabled for deferred then the object will be rendered with the pass DepthPrepass. See guidelines. This allow to switch dynamically between both mode.
// So we don't need to render the ForwardOnlyOpaqueDepthOnly pass
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
// This is handeled automatically with the RenderQueue value (OpaqueAlphaTested have a different value and thus are sorted after Opaque)
// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore
// during Gbuffer pass. This is handled in the shader and the depth test (equal and no depth write) is done here.
// Guidelines: To be able to switch from deferred to forward renderer we need to have forward opaque material with both Forward and ForwardOnlyOpaque pass.
// This is what is assume here. But users may want to reduce number of shader combination once they have made their choice.
// In case of deferred we can still have forward opaque object
// It mean that addForwardOnlyOpaquePass = !addForwardPass which is a simplification of: renderOpaque && !m_Asset.renderingSettings.ShouldUseForwardRenderingOnly()
// There is no need to store this case as we don't need to test for it
// TODO: Currently we can't render velocity vector into GBuffer, neither during forward pass (in case of forward opaque), so it is always a separate pass
// Note that we if we have forward only opaque with deferred rendering, it must also support the rendering of velocity vector to be correct with following test.
if((ShaderConfig.s_VelocityInGbuffer==1))
{
Debug.LogWarning("Velocity in Gbuffer is currently not supported");
}
// These flags are still required in SRP or the engine won't compute previous model matrices...
// If the flag hasn't been set yet on this camera, motion vectors will skip a frame.
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs. Please don't edit by hand.
/* Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
if (_EnableSSSAndTransmission != 0 && bsdfData.materialId == MATERIALID_LIT_SSS)
if (_EnableSSSAndTransmission != 0 && bsdfData.materialId == MATERIALID_LIT_SSS && HasMaterialFeatureFlag(MATERIALFEATUREFLAGS_LIT_SSS))
{
// We SSSSS is enabled with use split lighting.
// SSSSS algorithm need to know which pixels contribute to SSS and which doesn't. We could use the stencil for that but it mean that it will increase the cost of SSSSS
bound.boxAxisZ.Set(0,0,isNegDeterminant?(-range):range);// transform to camera space (becomes a left hand coordinate frame in Unity since Determinant(worldToView)<0)
bound.center=positionVS;
bound.boxAxisX=vx*range;
bound.boxAxisY=vy*range;
bound.boxAxisZ=vz*range;
// represents a left hand coordinate system in world space since det(worldToView)<0
// TODO: Don't know why but If we use Shader.GetGlobalTexture(HDShaderIDs._GBufferTexture0) instead of HDShaderIDs._GBufferTexture0 the screen start to flicker in SceneView...
// Need to investigate what is happening. But this may be unnecessary as development of SetGlobalTexture for compute shader have begin
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
publicreadonlyGUIContentvertexColorModeText=newGUIContent("Vertex Color Mode","Mode multiply: vertex color is multiply with the mask. Mode additive: vertex color values are remapped between -1 and 1 and added to the mask (neutral at 0.5 vertex color).");
publicreadonlyGUIContentlayerCountText=newGUIContent("Layer Count","Number of layers.");
publicreadonlyGUIContentlayerTilingBlendMaskText=newGUIContent("Tiling","Tiling for the blend mask.");
publicreadonlyGUIContentobjectScaleAffectTileText=newGUIContent("Lock layers tiling and object Scale","Tiling of each layers will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText2=newGUIContent("Lock influenced layers tiling and object Scale","Tiling of each influenced layers (all except main layer) will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText=newGUIContent("Lock layers 0123 tiling with object Scale","Tiling of each layers will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText2=newGUIContent("Lock layers 123 tiling with object Scale","Tiling of each influenced layers (all except main layer) will be affected by the object scale.");
publicreadonlyGUIContentlayerTexWorldScaleText=newGUIContent("World Scale","Tiling factor applied to Planar/Trilinear mapping");
publicreadonlyGUIContentUVBlendMaskText=newGUIContent("BlendMask UV Mapping","Base UV Mapping mode of the layer.");
publicreadonlyGUIContentuseHeightBasedBlendText=newGUIContent("Use Height Based Blend","Layer will be blended with the underlying layer based on the height.");
publicreadonlyGUIContentuseMainLayerInfluenceModeText=newGUIContent("Main Layer Influence","Switch between regular layers mode and base/layers mode");
publicreadonlyGUIContentopacityAsDensityText=newGUIContent("Use Opacity as Density","Use Opacity as Density.");
publicreadonlyGUIContentopacityAsDensityText=newGUIContent("Opacity map use as Density map","Use opacity map as (alpha channel of base color) as Density map.");
publicreadonlyGUIContentinheritBaseNormalText=newGUIContent("Normal influence","Inherit the normal from the base layer.");
publicreadonlyGUIContentinheritBaseHeightText=newGUIContent("Heightmap influence","Inherit the height from the base layer.");
publicreadonlyGUIContentinheritBaseColorText=newGUIContent("BaseColor influence","Inherit the base color from the base layer.");
// This pass is the same as GBuffer only it does not do alpha test (the clip instruction is removed)
// This is due to the fact that on GCN, any shader with a clip instruction cannot benefit from HiZ so when we do a prepass, in order to get the most performance, we need to make a special case in the subsequent GBuffer pass.
Pass
{
Name "GBufferWithPrepass" // Name is not used
Tags { "LightMode" = "GBufferWithPrepass" } // This will be only for opaque object based on the RenderQueue index
// This pass is the same as GBuffer only it does not do alpha test (the clip instruction is removed)
// This is due to the fact that on GCN, any shader with a clip instruction cannot benefit from HiZ so when we do a prepass, in order to get the most performance, we need to make a special case in the subsequent GBuffer pass.
Pass
{
Name "GBufferWithPrepass" // Name is not used
Tags { "LightMode" = "GBufferWithPrepass" } // This will be only for opaque object based on the RenderQueue index
publicstaticGUIContentppdMinSamplesText=newGUIContent("Minimum steps","Minimum steps (texture sample) to use with per pixel displacement mapping");
publicstaticGUIContentppdMaxSamplesText=newGUIContent("Maximum steps","Maximum steps (texture sample) to use with per pixel displacement mapping");
publicstaticGUIContentppdLodThresholdText=newGUIContent("Fading mip level start","Starting heightmap mipmap lod number where the parallax occlusion mapping effect start to disappear");
publicstaticGUIContentperPixelDisplacementObjectScaleText=newGUIContent("Lock with object scale","Per Pixel displacement will take into account the tiling scale - Only work with uniform positive scale");
publicstaticGUIContentenableVertexDisplacementText=newGUIContent("Enable vertex displacement","Use heightmap as a displacement map. Displacement map is use to move vertex position in local space");
publicstaticGUIContentvertexDisplacementObjectScaleText=newGUIContent("Lock with object scale","Vertex displacement will take into account the object scale - Only work with uniform positive scale");
publicstaticGUIContentvertexDisplacementTilingScaleText=newGUIContent("Lock with heightmap tiling","Vertex displacement will take into account the tiling scale - Only work with uniform positive scale");
publicstaticGUIContenttessellationFactorTriangleSizeText=newGUIContent("Triangle size","Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
publicstaticGUIContenttessellationShapeFactorText=newGUIContent("Shape factor","Strength of Phong tessellation shape (lerp factor)");
publicstaticGUIContenttessellationBackFaceCullEpsilonText=newGUIContent("Triangle culling Epsilon","If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
publicstaticGUIContenttessellationObjectScaleText=newGUIContent("Lock with object scale","Tessellation displacement will take into account the object scale - Only work with uniform positive scale");
publicstaticGUIContenttessellationTilingScaleText=newGUIContent("Lock with heightmap tiling","Tessellation displacement will take into account the tiling scale - Only work with uniform positive scale");
// We don't store any materialId for aniso but instead deduce it from LitStandard + value of specular + anisotropy parameters
// Consequence is that when querying materialId alone, it will read 2 RT and not only one. This may be a performance hit when only materialId is desired (like in material classification pass)
// Alternative is to use a materialId slot, if any are available.
LitAniso=4,
LitAniso=2,
LitClearCoat=3,
LitSpecular=5,
LitSpecular=4,
};
// If change, be sure it match what is done in Lit.hlsl: MaterialFeatureFlagsFromGBuffer
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs. Please don't edit by hand.
// This method allows us to know at compile time what shader features should be removed from the code when the materialID cannot be known on the whole tile (any combination of 2 or more differnet materials in the same tile)
// This is only useful for classification during lighting, so it's not needed in EncodeIntoGBuffer and ConvertSurfaceDataToBSDFData (where we always know exactly what the MaterialID is)
/* 30 */ LIGHT_FEATURE_MASK_FLAGS | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
/* 26 */ LIGHT_FEATURE_MASK_FLAGS | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
};
uint FeatureFlagsToTileVariant(uint featureFlags)
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = surfaceData.specularColor;
}
else if (bsdfData.materialId == MATERIALID_LIT_SSS)
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{
outGBuffer1.a = PackMaterialId(MATERIALID_LIT_STANDARD); // Encode MATERIALID_LIT_SPECULAR as MATERIALID_LIT_STANDARD + GBUFFER_LIT_STANDARD_SPECULAR_COLOR_ID value in GBuffer2
outGBuffer1.a = PackMaterialId(MATERIALID_LIT_STANDARD); // Encode MATERIALID_LIT_SPECULAR as MATERIALID_LIT_STANDARD + GBUFFER_LIT_STANDARD_ANISOTROPIC_ID value in GBuffer2
// This pass is the same as GBuffer only it does not do alpha test (the clip instruction is removed)
// This is due to the fact that on GCN, any shader with a clip instruction cannot benefit from HiZ so when we do a prepass, in order to get the most performance, we need to make a special case in the subsequent GBuffer pass.
Pass
{
Name "GBufferWithPrepass" // Name is not used
Tags { "LightMode" = "GBufferWithPrepass" } // This will be only for opaque object based on the RenderQueue index
maxDisplacement = abs(_HeightAmplitude); // _HeightAmplitude can be negative if min and max are inverted, but the max displacement must be positive
#endif
return maxDisplacement;
}
// Note: The TBN is not normalize as it is based on mikkt. We should normalize it, but POM is always use on simple enough surfarce that mean it is not required (save 2 normalize). Tag: SURFACE_GRADIENT
// We will add smoothly the contribution of the normal map by lerping between vertex normal ( (0,0,1) in tangent space) and the actual normal from the main layer depending on the influence factor.
// Note: that we don't take details map into account here.
// This pass is the same as GBuffer only it does not do alpha test (the clip instruction is removed)
// This is due to the fact that on GCN, any shader with a clip instruction cannot benefit from HiZ so when we do a prepass, in order to get the most performance, we need to make a special case in the subsequent GBuffer pass.
Pass
{
Name "GBufferWithPrepass" // Name is not used
Tags { "LightMode" = "GBufferWithPrepass" } // This will be only for opaque object based on the RenderQueue index
publicstaticGUIContentalphaCutoffEnableText=newGUIContent("Alpha Cutoff Enable","Threshold for alpha cutoff");
publicstaticGUIContentalphaCutoffText=newGUIContent("Alpha Cutoff","Threshold for alpha cutoff");
publicstaticGUIContentalphaCutoffShadowText=newGUIContent("Alpha Cutoff Shadow","Threshold for alpha cutoff");
// YIBING BEGIN
publicstaticGUIContentalphaCutoffShadowText=newGUIContent("Alpha Cutoff Shadow","Threshold for alpha cutoff");
publicstaticGUIContenttransparentDepthWritePrepassEnableText=newGUIContent("Enable transparent depth write prepass","Threshold for alpha cutoff");
publicstaticGUIContenttransparentDepthWritePrepassEnableText=newGUIContent("Enable transparent depth write prepass","Threshold for alpha cutoff");
// YIBING END
publicstaticGUIContentdoubleSidedEnableText=newGUIContent("Double Sided","This will render the two face of the objects (disable backface culling) and flip/mirror normal");
publicstaticGUIContentdistortionEnableText=newGUIContent("Distortion","Enable distortion on this shader");
publicstaticGUIContentdistortionOnlyText=newGUIContent("Distortion Only","This shader will only be use to render distortion");
// TODO: deal with camera center rendering and instancing (This is the reason why we always perform two steps transform to clip space + instancing matrix)
// This code is disabled for velocity pass for now because at the moment we cannot have Normals with the velocity pass (this attributes holds last frame data)
// TODO: Remove the velocity pass test when velocity is properly handled.
// TODO: This should be an uniform for the object, this code should be remove (and is specific to Lit.shader) once we have it. - Workaround for now
output.objectScale = objectScale;
// TODO: deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
// TODO: TEMP: Velocity has a flow as it doens't have normal. This need to be fix. In the mean time, generate fix normal so compiler doesn't complain - When fix, think to also enable ATTRIBUTES_NEED_NORMAL in LitVelocityPass.hlsl
#if SHADERPASS == SHADERPASS_VELOCITY
output.normalWS = float3(0.0, 0.0, 1.0);
output.tangentWS = tangentWS;
#endif
#else
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)