float m = PerceptualRoughnessToRoughness(perceptualRoughness);
// Remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf
float n = (2.0 / max(FLT_EPSILON, m * m)) - 2.0;
float n = (2.0 / max(FLT_EPS, m * m)) - 2.0;
n /= (4.0 * max(NdotR, FLT_EPSILON));
n /= (4.0 * max(NdotR, FLT_EPS));
// remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness)
// First ShadowContext.hlsl must declare the specific ShadowContext struct and the loader that goes along with it.
// First ShadowContext.hlsl provides a macro SHADOWCONTEXT_DECLARE that must be used in order to define the specific ShadowContext struct and accompanying loader.
// Second there are two headers for shadow algorithms, whose signatures must match any of the Get...Attenuation function prototypes.
// The first header contains engine defaults, whereas the second header is empty by default. All project specific custom shadow algorithms should go in there or leave empty.
//
// Last there's a dispatcher include. By default the Get...Attenuation functions are rerouted to their default implementations. This can be overridden for each
// shadow type in the dispatcher source. For each overridden shadow type a specific define must be defined to prevent falling back to the default functions.
//
/* Required defines: (define these to the desired numbers - must be in sync with loading and resource setup from C#)
#define SHADOWCONTEXT_MAX_TEX2DARRAY 0
#define SHADOWCONTEXT_MAX_TEXCUBEARRAY 0
#define SHADOWCONTEXT_MAX_SAMPLER 0
#define SHADOWCONTEXT_MAX_COMPSAMPLER 0
*/
/* Default values for optional defines:
#define SHADOW_SUPPORTS_DYNAMIC_INDEXING 0 // Dynamic indexing only works on >= sm 5.1
#define SHADOW_OPTIMIZE_REGISTER_USAGE 0 // Redefine this as 1 in your ShadowContext.hlsl to optimize for register usage over instruction count
// #define SHADOW_DISPATCH_USE_CUSTOM_PUNCTUAL // Enable custom implementations of GetPunctualShadowAttenuation. If not defined, a default implementation will be used.
// #define SHADOW_DISPATCH_USE_CUSTOM_DIRECTIONAL // Enable custom implementations of GetDirectionalShadowAttenuation. If not defined, a default implementation will be used.
*/
#define SHADOW_SUPPORTS_DYNAMIC_INDEXING 0 // only on >= sm 5.1
#define SHADOW_OPTIMIZE_REGISTER_USAGE 0 // redefine this as 1 in your ShadowContext.hlsl to optimize for register usage over instruction count
#ifndef SHADOW_SUPPORTS_DYNAMIC_INDEXING
#define SHADOW_SUPPORTS_DYNAMIC_INDEXING 0
#endif
#ifndef SHADOW_OPTIMIZE_REGISTER_USAGE
#define SHADOW_OPTIMIZE_REGISTER_USAGE 0
#endif
#include "../../../Core/Shadow/ShadowBase.cs.hlsl" // ShadowData definition, auto generated (don't modify)
#include "Shadow/ShadowBase.cs.hlsl" // ShadowData definition, auto generated (don't modify)
// Declares a shadow context struct with members and sampling code based on whether _...Slots > 0
// Be sure legacy HDR option is disable on camera as it cause banding in SceneView. Yes, it is a contradiction, but well, Unity...
// When HDR option is enabled, Unity render in FP16 then convert to 8bit with a stretch copy (this cause banding as it should be convert to sRGB (or other color appropriate color space)), then do a final shader with sRGB conversion
// When LDR, unity render in 8bitSRGB, then do a final shader with sRGB conversion
// What should be done is just in our Post process we convert to sRGB and store in a linear 10bit, but require C++ change...
// 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
publicreadonlyGUIContentrenderPipelineResources=newGUIContent("Render Pipeline Resources","Set of resources that need to be loaded when creating stand alone");
publicreadonlyGUIContentdefaultDiffuseMaterial=newGUIContent("Default Diffuse Material","Material to use when creating objects");
publicreadonlyGUIContentdefaultShader=newGUIContent("Default Shader","Shader to use when creating materials");
// 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)
// 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)
m_enableFptlForOpaqueWhenClustered.boolValue=true;// Force fptl to be always true if compute evaluation is enable
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Big Tile",()=>m_Asset.tileSettings.enableBigTilePrepass,(value)=>m_Asset.tileSettings.enableBigTilePrepass=(bool)value,DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Material Classification",()=>m_Asset.tileSettings.enableComputeMaterialVariants,(value)=>m_Asset.tileSettings.enableComputeMaterialVariants=(bool)value,DebugItemFlag.RuntimeOnly);
{
// Currently, Unity does not offer a way to bind the stencil buffer as a texture in a compute shader.
// Therefore, it's manually copied using a pixel shader.
// Forward opaque material always have a prepass (whether or not we use deferred, whether or not there is option like alpha test only) so we pass the right depth state here.
/* 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)
// Deferred opaque always use FPTL, forward opaque can use FPTL or cluster, transparent always use cluster
// When MSAA is enabled, we only support cluster (Fptl is too slow with MSAA), and we don't support MSAA for deferred path (mean it is ok to keep fptl)
publicboolenableFptlForForwardOpaque;
publicboolenableClustered;
publicboolenableFptlForOpaqueWhenClustered;// still useful on opaques. Should be true by default to force tile on opaque.
// 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)
//static int[] s_shadeOpaqueIndirectClusteredKernels = new int[LightDefinitions.s_NumFeatureVariants];
// Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Update the code with following comment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
cmd.SetGlobalFloat(HDShaderIDs._UseTileLightList,useFptl?1:0);// leaving this as a dynamic toggle for now for forward opaques to keep shader variants down.
// Project specific file to override the default shadow sampling routines.
// We need to define which dispatchers we're overriding, otherwise the compiler will pick default implementations which will lead to compilation errors.
// Check Shadow.hlsl right below where this header is included for the individual defines.
#ifndef TILEPASS_SHADOW_HLSL
#define TILEPASS_SHADOW_HLSL
#define SHADOW_DISPATCH_USE_CUSTOM_DIRECTIONAL
#define SHADOW_DISPATCH_USE_CUSTOM_PUNCTUAL
#include "ShadowContext.hlsl"
// This is an example of how to override the default dynamic resource dispatcher
// by hardcoding the resources used and calling the shadow sampling routines that take an explicit texture and sampler.
#define SHADOW_DISPATCH_USE_CUSTOM_DIRECTIONAL // enables hardcoded resources and algorithm for directional lights
#define SHADOW_DISPATCH_USE_CUSTOM_PUNCTUAL // enables hardcoded resources and algorithm for punctual lights
//#define SHADOW_DISPATCH_USE_SEPARATE_CASCADE_ALGOS // enables separate cascade sampling variants for each cascade
//#define SHADOW_DISPATCH_USE_SEPARATE_PUNC_ALGOS // enables separate resources and algorithms for spot and point lights
specularLighting += F * D_GGX(NdotH, 0.01) * NdotL * bsdfData.coatCoverage;
// Change the Fresnel term to account for transmission through Clear Coat and reflection on the base layer
F = Sqr(-F * bsdfData.coatCoverage + 1.0);
F = Sq(-F * bsdfData.coatCoverage + 1.0);
// Change the Light and View direction to account for IOR change.
// Update the half vector accordingly
float NdotL = saturate(dot(bsdfData.normalWS, L)); // Must have the same value without the clamp
float NdotV = preLightData.NdotV; // Get the unaltered (geometric) version
float LdotV = dot(L, V);
float invLenLV = rsqrt(max(2 * LdotV + 2, FLT_SMALL)); // invLenLV = rcp(length(L + V)) - caution about the case where V and L are opposite, it can happen, use max to avoid this
float invLenLV = rsqrt(max(2 * LdotV + 2, FLT_EPS)); // invLenLV = rcp(length(L + V)) - caution about the case where V and L are opposite, it can happen, use max to avoid this
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS + offset, N, lightData.shadowIndex, L_dist, posInput.unPositionSS);
#ifdef SHADOWS_SHADOWMASK
// Note: Legacy Unity have two shadow mask mode. ShadowMask (ShadowMask contain static objects shadow and ShadowMap contain only dynamic objects shadow, final result is the minimun of both value)
// and ShadowMask_Distance (ShadowMask contain static objects shadow and ShadowMap contain everything and is blend with ShadowMask based on distance (Global distance setup in QualitySettigns)).
// Note: When we are in this SubsurfaceScattering shader we know that we are a SSS material. This shader is strongly coupled with the deferred Lit.shader.
// We can use the material classification facility to help the compiler to know we use SSS material and optimize the code (and don't require to read gbuffer with materialId).
publicstaticGUIContentalphaCutoffText=newGUIContent("Alpha Cutoff","Threshold for alpha cutoff");
publicstaticGUIContentalphaCutoffShadowText=newGUIContent("Alpha Cutoff Shadow","Threshold for alpha cutoff in case of shadow pass");
publicstaticGUIContentalphaCutoffPrepassText=newGUIContent("Alpha Cutoff Prepass","Threshold for alpha cutoff in case of depth prepass");
publicstaticGUIContenttransparentDepthPrepassEnableText=newGUIContent("Enable transparent depth prepass","It allow to ");
publicstaticGUIContentalphaCutoffPostpassText=newGUIContent("Alpha Cutoff Postpass","Threshold for alpha cutoff in case of depth postpass");
publicstaticGUIContenttransparentDepthPrepassEnableText=newGUIContent("Enable transparent depth prepass","It allow to to fill depth buffer to improve sorting");
publicstaticGUIContenttransparentDepthPostpassEnableText=newGUIContent("Enable transparent depth postpass","It allow to fill depth buffer for postprocess effect like DOF");
publicstaticGUIContenttransparentBackfaceEnableText=newGUIContent("Enable back then front rendering","It allow to better sort transparent mesh by first rendering back faces then front faces in two separate drawcall");
publicstaticGUIContentenableTransparentFogText=newGUIContent("Enable fog","Enable fog on transparent material");
publicstaticGUIContentenableBlendModePreserveSpecularLightingText=newGUIContent("Blend preserve specular lighting","Blend mode will only affect diffuse lighting, allowing correct specular lighting (reflection) on transparent object");
Transparent
}
// Enum values are hardcoded for retrocompatibility. Don't change them.
// Enum values are hardcoded for retro-compatibility. Don't change them.
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
_EmissionColor("Color", Color) = (1, 1, 1)
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
_MainTex("Albedo", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 vulkan metal // TEMP: until we go further in dev
#pragma only_renderers d3d11 ps4 vulkan metal // TEMP: until we go further in dev