Added ShadowScope;
Renamed PBRScope to SurfaceInputsScope;
This commit is contained in:
@@ -154,7 +154,7 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
|
||||
float3 specularColor = 1;
|
||||
float anisotropy = 0;
|
||||
|
||||
#ifdef _MASK_MAP
|
||||
#ifdef _MASKMAP
|
||||
float4 _MaskMap_var = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
|
||||
metallic = _MaskMap_var.x;
|
||||
metallic = lerp(_MetallicRemapMin, _MetallicRemapMax, metallic);
|
||||
|
||||
@@ -171,7 +171,6 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
|
||||
shadow *= GetHairShadow(posInput, L);
|
||||
#endif
|
||||
shadow = saturate(lerp(1.0, shadow, _Set_SystemShadowsToBase));
|
||||
|
||||
#if _SHADING_MODE_SDF
|
||||
float angle;
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#define SATURATE_BASE_COLOR_IF_SDR(x) saturate(x)
|
||||
#endif
|
||||
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsMaterialEvaluation.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl"
|
||||
|
||||
const float rateR = 0.299;
|
||||
const float rateG = 0.587;
|
||||
const float rateB = 0.114;
|
||||
@@ -44,7 +47,11 @@ DirectLighting UtsEvaluateBSDF_Directional(LightLoopContext lightLoopContext, Po
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
float3 L = -lightData.forward;
|
||||
SHADOW_TYPE shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.geomNormalWS);
|
||||
|
||||
SHADOW_TYPE shadow = 1.0;
|
||||
#if _RECEIVE_LIGHT_SHADOW_ON
|
||||
shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.geomNormalWS);
|
||||
#endif
|
||||
|
||||
if (lightData.lightDimmer > 0.0)
|
||||
{
|
||||
@@ -70,10 +77,10 @@ DirectLighting UtsEvaluateBSDF_Punctual(LightLoopContext lightLoopContext, Posit
|
||||
float4 distances; // {d, d^2, 1/d, d_proj}
|
||||
GetPunctualLightVectors(posInput.positionWS, lightData, L, distances);
|
||||
|
||||
PositionInputs shadowPositionInputs = posInput;
|
||||
shadowPositionInputs.positionWS = posInput.positionWS + L * _ShadowBias;
|
||||
|
||||
SHADOW_TYPE shadow = EvaluateShadow_Punctual(lightLoopContext, shadowPositionInputs, lightData, builtinData, bsdfData.geomNormalWS, L, distances);
|
||||
SHADOW_TYPE shadow = 1.0;
|
||||
#if _RECEIVE_LIGHT_SHADOW_ON
|
||||
shadow = UtsEvaluateShadow_Punctual(lightLoopContext, posInput, lightData, builtinData, UtsGetShadowNormal(bsdfData), L, distances);
|
||||
#endif
|
||||
|
||||
if (lightData.lightDimmer > 0.0)
|
||||
{
|
||||
@@ -123,19 +130,19 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
|
||||
float3 normalWS = float3(0.0, 0.0, 1.0);
|
||||
#else
|
||||
float3 normalWS = bsdfData.normalWS;
|
||||
#endif
|
||||
float3 backNormalWS = -normalWS;
|
||||
|
||||
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|
||||
if (_EnableProbeVolumes)
|
||||
{
|
||||
// Reflect normal to get lighting for reflection probe tinting
|
||||
float3 R = reflect(-V, bsdfData.normalWS);
|
||||
|
||||
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
|
||||
float3 normalWS = 0.0;
|
||||
float3 backNormalWS = 0.0;
|
||||
#else
|
||||
float3 normalWS = bsdfData.normalWS;
|
||||
float3 backNormalWS = -bsdfData.normalWS;
|
||||
#endif
|
||||
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS),
|
||||
bsdfData.normalWS, -bsdfData.normalWS,
|
||||
R, V,
|
||||
@@ -144,8 +151,8 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
|
||||
}
|
||||
else // If probe volume is disabled we fallback on the ambient probes
|
||||
{
|
||||
builtinData.bakeDiffuseLighting = EvaluateAmbientProbe(bsdfData.normalWS);
|
||||
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(-bsdfData.normalWS);
|
||||
builtinData.bakeDiffuseLighting = EvaluateAmbientProbe(normalWS);
|
||||
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -193,11 +200,6 @@ IndirectLighting UtsEvaluateBSDF_Env(LightLoopContext lightLoopContext, Position
|
||||
IndirectLighting lighting;
|
||||
ZERO_INITIALIZE(IndirectLighting, lighting);
|
||||
|
||||
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
|
||||
{
|
||||
return lighting;
|
||||
}
|
||||
|
||||
float3 envLighting;
|
||||
float3 positionWS = posInput.positionWS;
|
||||
float weight = 1.0;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Macros.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/PhysicalCamera.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsMaterialEvaluation.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsLightEvaluation.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Models/SurfaceFeatureFlags.cs.hlsl"
|
||||
|
||||
@@ -74,7 +73,7 @@ bool UtsUseScreenSpaceShadow(DirectionalLightData light, float3 normalWS)
|
||||
bool rayTracedShadow = (light.screenSpaceShadowIndex & RAY_TRACED_SCREEN_SPACE_SHADOW_FLAG) != 0.0;
|
||||
return (validScreenSpaceShadow && ((rayTracedShadow && visibleLight) || !rayTracedShadow));
|
||||
#else
|
||||
return ( (light.screenSpaceShadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK) != INVALID_SCREEN_SPACE_SHADOW);
|
||||
return ((light.screenSpaceShadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK) != INVALID_SCREEN_SPACE_SHADOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -91,7 +90,8 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
|
||||
// Initialize the contactShadow and contactShadowFade fields
|
||||
InitContactShadow(posInput, context);
|
||||
|
||||
|
||||
#if _RECEIVE_LIGHT_SHADOW_ON
|
||||
// First of all we compute the shadow value of the directional light to reduce the VGPR pressure
|
||||
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
|
||||
{
|
||||
@@ -100,8 +100,8 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
{
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
||||
if (UseScreenSpaceShadow(light, bsdfData.normalWS))
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_RECEIVE_SCREEN_SPACE_SHADOW_ON)
|
||||
if (UtsUseScreenSpaceShadow(light, bsdfData.normalWS))
|
||||
{
|
||||
context.shadowValue = GetScreenSpaceColorShadow(posInput, light.screenSpaceShadowIndex).SHADOW_TYPE_SWIZZLE;
|
||||
}
|
||||
@@ -115,12 +115,13 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
dot(bsdfData.normalWS, L) > 0.0)
|
||||
{
|
||||
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
|
||||
posInput.positionSS, posInput.positionWS + L * _ShadowBias, bsdfData.normalWS,
|
||||
posInput.positionSS, posInput.positionWS + L * _ShadowDistanceBias, UtsGetShadowNormal(bsdfData),
|
||||
light.shadowIndex, L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
PreLightData preLightData = GetPreLightData_UTS(V, posInput, bsdfData);
|
||||
|
||||
|
||||
77
Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl
Normal file
77
Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef UTS_SHADOW_EVALUATION
|
||||
#define UTS_SHADOW_EVALUATION
|
||||
|
||||
float3 UtsGetShadowNormal(UtsBSDFData bsdfData)
|
||||
{
|
||||
#if _MATERIAL_TYPE_FACE
|
||||
return normalize(mul(UNITY_MATRIX_M, float4(0.0, 0.0, 1.0, 0.0))).xyz;
|
||||
#else
|
||||
return bsdfData.geomNormalWS * (1.0 + _ShadowNormalBias);
|
||||
#endif
|
||||
}
|
||||
|
||||
// distances = {d, d^2, 1/d, d_proj}, where d_proj = dot(lightToSample, light.forward).
|
||||
SHADOW_TYPE UtsEvaluateShadow_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput, LightData light, BuiltinData builtinData, float3 N, float3 L, float4 distances)
|
||||
{
|
||||
#ifndef LIGHT_EVALUATION_NO_SHADOWS
|
||||
float shadow = 1.0;
|
||||
float shadowMask = 1.0;
|
||||
float NdotL = dot(N, L); // Disable contact shadow and shadow mask when facing away from light (i.e transmission)
|
||||
|
||||
#ifdef SHADOWS_SHADOWMASK
|
||||
// shadowMaskSelector.x is -1 if there is no shadow mask
|
||||
// Note that we override shadow value (in case we don't have any dynamic shadow)
|
||||
shadow = shadowMask = (light.shadowMaskSelector.x >= 0.0 && NdotL > 0.0) ? dot(BUILTIN_DATA_SHADOW_MASK, light.shadowMaskSelector) : 1.0;
|
||||
#endif
|
||||
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_RECEIVE_SCREEN_SPACE_SHADOW_ON)
|
||||
if ((light.screenSpaceShadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK) != INVALID_SCREEN_SPACE_SHADOW)
|
||||
{
|
||||
shadow = GetScreenSpaceShadow(posInput, light.screenSpaceShadowIndex);
|
||||
shadow = lerp(shadowMask, shadow, light.shadowDimmer);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if ((light.shadowIndex >= 0) && (light.shadowDimmer > 0))
|
||||
{
|
||||
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, posInput.positionSS, posInput.positionWS + L * _ShadowDistanceBias, N, light.shadowIndex, L, distances.x, light.lightType == GPULIGHTTYPE_POINT, light.lightType != GPULIGHTTYPE_PROJECTOR_BOX);
|
||||
|
||||
#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)).
|
||||
// HDRenderPipeline change this behavior. Only ShadowMask mode is supported but we support both blend with distance AND minimun of both value. Distance is control by light.
|
||||
// The following code do this.
|
||||
// The min handle the case of having only dynamic objects in the ShadowMap
|
||||
// The second case for blend with distance is handled with ShadowDimmer. ShadowDimmer is define manually and by shadowDistance by light.
|
||||
// With distance, ShadowDimmer become one and only the ShadowMask appear, we get the blend with distance behavior.
|
||||
shadow = light.nonLightMappedOnly ? min(shadowMask, shadow) : shadow;
|
||||
#endif
|
||||
|
||||
shadow = lerp(shadowMask, shadow, light.shadowDimmer);
|
||||
}
|
||||
|
||||
// Transparents have no contact shadow information
|
||||
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(LIGHT_EVALUATION_NO_CONTACT_SHADOWS)
|
||||
{
|
||||
// In certain cases (like hair) we allow to force the contact shadow sample.
|
||||
#ifdef LIGHT_EVALUATION_CONTACT_SHADOW_DISABLE_NDOTL
|
||||
const bool allowContactShadow = true;
|
||||
#else
|
||||
const bool allowContactShadow = NdotL > 0.0;
|
||||
#endif
|
||||
|
||||
shadow = min(shadow, allowContactShadow ? GetContactShadow(lightLoopContext, light.contactShadowMask, light.isRayTracedContactShadow) : 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_DISPLAY
|
||||
if (_DebugShadowMapMode == SHADOWMAPDEBUGMODE_SINGLE_SHADOW && light.shadowIndex == _DebugSingleShadowIndex)
|
||||
g_DebugShadowAttenuation = shadow;
|
||||
#endif
|
||||
return shadow;
|
||||
#else // LIGHT_EVALUATION_NO_SHADOWS
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58ed9f8b53f6c414991b5223756b2938
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -21,15 +21,16 @@ float _SDFShadowLevel;
|
||||
float _SDFShadowSmoothLevel;
|
||||
float _SDFHighlightStrength;
|
||||
|
||||
// Shadow
|
||||
float _ShadowDistanceBias;
|
||||
float _ShadowNormalBias;
|
||||
|
||||
float _utsTechnique;
|
||||
float4 _Color;
|
||||
fixed _Set_SystemShadowsToBase;
|
||||
|
||||
float _SurfaceFeatures;
|
||||
|
||||
float _Tweak_SystemShadowsLevel;
|
||||
float _ShadowBias;
|
||||
|
||||
float _EyeParallaxAmount;
|
||||
float _HairBlendingFactor;
|
||||
|
||||
@@ -146,7 +146,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
||||
#endif
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex));
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
|
||||
|
||||
surfaceData.baseColor = _MainTex_var.xyz;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user