Folder clean up;

Added Emissive;
This commit is contained in:
Misaki
2025-01-29 12:27:09 +09:00
parent 1a82022a6f
commit 018300e046
81 changed files with 120 additions and 399 deletions

View File

@@ -0,0 +1,340 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#include "Packages/com.misaki.hdrp-toon/Runtime/HDRP/Shaders/Includes/Common/UtsPBR.hlsl"
#ifndef DirectionalShadowType
# if (SHADEROPTIONS_RAYTRACING && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL))
# define DirectionalShadowType float3
# else
# define DirectionalShadowType float
# endif
#endif
void UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, UTSLightData utsLightData, SurfaceData surfaceData, BSDFData bsdfData, out float inverseClipping, out float channelOutAlpha, out UTSData utsData, inout UTSAggregateLighting utsAggregateLighting)
{
inverseClipping = 0;
channelOutAlpha = 1.0f;
ZERO_INITIALIZE(UTSData, utsData);
// We don't have to calculate lighting here if we are using sdf shadow
#ifndef _SDFShadow
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
/* todo. these should be put int a struct */
float4 Set_UV0 = input.texCoord0;
float3x3 tangentTransform = input.tangentToWorld;
utsData.normalDirection = surfaceData.normalWS; // Perturbed normals
float4 _MainTex_var = float4(surfaceData.baseColor.r, surfaceData.baseColor.g, surfaceData.baseColor.b, surfaceData.coatMask);
utsData.viewDirection = V;
/* to here todo. these should be put int a struct */
//v.2.0.4
#ifdef _IS_TRANSCLIPPING_OFF
//
#elif _IS_TRANSCLIPPING_ON
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
float Set_MainTexAlpha = _MainTex_var.a;
float _IsBaseMapAlphaAsClippingMask_var = lerp(_ClippingMask_var.r, Set_MainTexAlpha, _IsBaseMapAlphaAsClippingMask);
float _Inverse_Clipping_var = lerp(_IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping);
float Set_Clipping = saturate((_Inverse_Clipping_var + _Clipping_Level));
clip(Set_Clipping - 0.5);
inverseClipping = _Inverse_Clipping_var;
#endif
SHADOW_TYPE shadowAttenuation = lightLoopContext.shadowValue;
//v.2.0.6
//Minimal value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
#if !defined (UTS_USE_RAYTRACING_SHADOW)
shadowAttenuation *= 2.0f;
shadowAttenuation = saturate(shadowAttenuation);
#endif
float3 mainLightDirection = utsLightData.lightDirection;
float3 mainLightColor = utsLightData.lightColor;
//v.2.0.4
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
//v.2.0.5
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLightDirection.xyz, any(mainLightDirection.xyz)));
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
float3 originalLightColor = mainLightColor.rgb;
originalLightColor = lerp(originalLightColor, clamp(originalLightColor, ConvertFromEV100(_ToonEvAdjustmentValueMin), ConvertFromEV100(_ToonEvAdjustmentValueMax)), _ToonEvAdjustmentCurve);
float3 lightColor = lerp(max(defaultLightColor, originalLightColor), max(defaultLightColor, saturate(originalLightColor)), max(_Is_Filter_LightColor, _ToonLightHiCutFilter)) * _Light_Intensity_Multiplier;
////// Lighting:
float3 halfDirection = normalize(utsData.viewDirection + lightDirection);
//v.2.0.5
_Color = _BaseColor;
float3 Set_LightColor = lightColor.rgb;
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
float Set_BaseColorAlpha = _BaseColorVisible;
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 1)
{
clippingColor = Set_BaseColor;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
float4 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
Set_BaseColor = lerp(Set_BaseColor, overridingColor.rgb, maskEnabled);
Set_BaseColor *= _BaseColorVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
//v.2.0.5
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _MainTex_var, _Use_BaseAs1st);
float3 _Is_LightColor_1st_Shade_var = lerp((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb), ((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
float _HalfLambert_var = 0.5 * dot(utsData.normalDirection, lightDirection) + 0.5; // Half Lambert
//v.2.0.6
float4 _ShadingGradeMap_var = tex2Dlod(_ShadingGradeMap, float4(TRANSFORM_TEX(Set_UV0, _ShadingGradeMap), 0.0, _BlurLevelSGM));
float _SystemShadowsLevel_var = (shadowAttenuation * 0.5f) + 0.5f + _Tweak_SystemShadowsLevel > 0.001f ? (shadowAttenuation * 0.5f)+0.5f+_Tweak_SystemShadowsLevel : 0.0001f;
float _ShadingGradeMapLevel_var = _ShadingGradeMap_var.r < 0.95 ? _ShadingGradeMap_var.r + _Tweak_ShadingGradeMapLevel : 1;
float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(_SystemShadowsLevel_var)), _Set_SystemShadowsToBase );
// float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase);
float _1stColorFeatherForMask = lerp(_1st_ShadeColor_Feather, 0.0f, max(_ComposerMaskMode, _FirstShadeOverridden));
//
float Set_FinalShadowMask = saturate((1.0 + ((Set_ShadingGrade - (_1st_ShadeColor_Step - _1stColorFeatherForMask)) * -1) / (_1st_ShadeColor_Step - (_1st_ShadeColor_Step - _1stColorFeatherForMask)))); // Base and 1st Shade Mask
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 2)
{
clippingColor = _Is_LightColor_1st_Shade_var;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
_Is_LightColor_1st_Shade_var = lerp(_Is_LightColor_1st_Shade_var, overridingColor.rgb, maskEnabled);
_Is_LightColor_1st_Shade_var = lerp(_Is_LightColor_1st_Shade_var, Set_BaseColor, 1.0f - _FirstShadeVisible);
}
float Set_1st_ShadeAlpha = _FirstShadeVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
float3 _BaseColor_var = lerp(Set_BaseColor, _Is_LightColor_1st_Shade_var, Set_FinalShadowMask);
//v.2.0.5
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_2nd_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap)), _1st_ShadeMap_var, _Use_1stAs2nd);
float _2ndColorFeatherForMask = lerp(_2nd_ShadeColor_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
float Set_ShadeShadowMask = saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - 1).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask)))); // 1st and 2nd Shades Mask
//Composition: 3 Basic Colors as Set_FinalBaseColor
#ifdef UTS_LAYER_VISIBILITY
float3 diffuseTerm;
{
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
float3 _Is_LightColor_2nd_Shade_var = lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
_Is_LightColor_2nd_Shade_var = lerp(_Is_LightColor_2nd_Shade_var, overridingColor.rgb, maskEnabled);
_Is_LightColor_2nd_Shade_var = lerp(_Is_LightColor_2nd_Shade_var, Set_BaseColor, 1.0f - _SecondShadeVisible);
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
diffuseTerm =
lerp(_BaseColor_var,
lerp(_Is_LightColor_1st_Shade_var, _Is_LightColor_2nd_Shade_var
, Set_ShadeShadowMask)
, Set_FinalShadowMask);
channelOutAlpha =
lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, Set_ShadeShadowMask),Set_FinalShadowMask);
}
#else
float3 Set_FinalBaseColor =
lerp(_BaseColor_var,
lerp(_Is_LightColor_1st_Shade_var,
lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor)
, _Is_LightColor_2nd_Shade)
, Set_ShadeShadowMask)
, Set_FinalShadowMask);
#endif //#ifdef UTS_LAYER_VISIBILITY
float albedoIntensity = max(0.1, (1 - sqrt(surfaceData.metallic)) * (1.7 - 0.7 * (1 - sqrt(surfaceData.metallic))));
diffuseTerm = diffuseTerm * albedoIntensity;
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 3)
{
clippingColor = lerp((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb), ((_2nd_ShadeMap_var.rgb * _2nd_ShadeColor.rgb) * Set_LightColor)
, _Is_LightColor_2nd_Shade);
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
float _Specular_var = 0.5 * dot(halfDirection, utsData.normalDirection) + 0.5; // Specular
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
//Composition: 3 Basic Colors and HighColor as Set_HighColor
float3 _HighColorWithOutTweak_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
float3 _HighColor_var = _HighColorWithOutTweak_var * _TweakHighColorMask_var;
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 4)
{
clippingColor = _HighColorWithOutTweak_var;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
float3 Set_HighColor;
{
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
_HighColor_var *= _HighlightVisible;
Set_HighColor =
lerp(SATURATE_IF_SDR(diffuseTerm - _TweakHighColorMask_var), diffuseTerm,
lerp(_Is_BlendAddToHiColor, 1.0
, _Is_SpecularToHighColor));
float3 addColor =
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
, _Is_UseTweakHighColorOnShadow);
Set_HighColor += addColor;
if (any(addColor))
{
Set_HighColor = lerp(Set_HighColor, overridingColor.rgb, maskEnabled);
channelOutAlpha = _HighlightVisible;
}
}
#else
float3 Set_HighColor = (lerp(SATURATE_IF_SDR((Set_FinalBaseColor - _TweakHighColorMask_var)), Set_FinalBaseColor, lerp(_Is_BlendAddToHiColor, 1.0, _Is_SpecularToHighColor)) + lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow));
#endif
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
float _RimArea_var = dot(utsData.normalDirection, utsData.viewDirection);
_RimArea_var = lerp(_RimArea_var, 1 - _RimArea_var,_Is_BlendAddToRimColor);
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
float _VertHalfLambert_var = 0.5 * dot(utsData.normalDirection, lightDirection) + 0.5;
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
//Composition: HighColor and RimLight as _RimLight_var
#ifdef UTS_LAYER_VISIBILITY
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
float Set_RimLightAlpha = _RimLightVisible;
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
Set_RimLight *= _RimLightVisible;
Set_RimLight *= _RimLight_Strength;
float3 _RimLight_var = lerp(lerp(Set_HighColor, (Set_HighColor * Set_RimLight), _RimLight), lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight), _Is_BlendAddToRimColor);
if (any(Set_RimLight) * maskRimEnabled)
{
_RimLight_var = overridingRimColor;
channelOutAlpha = Set_RimLightAlpha;
}
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
#else
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
Set_RimLight *= _RimLight_Strength;
float3 _RimLight_var = lerp(lerp(Set_HighColor, (Set_HighColor * Set_RimLight), _RimLight), lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight), _Is_BlendAddToRimColor);
_RimLight_var = lerp(_RimLight_var, (_RimLight_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow);
#endif
//v.2.0.4
#ifdef _IS_ANGELRING_OFF
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 5)
{
clippingColor = float3(0.0f,0.0f,0.0f);
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
//float3 diffuseTerm = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
//
#elif _IS_ANGELRING_ON
//float3 diffuseTerm = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before AR
//v.2.0.7 AR Camera Rolling Stabilizer
float3 _AR_OffsetU_var = lerp(mul(UNITY_MATRIX_V, float4(utsData.normalDirection, 0)).xyz, float3(0, 0, 1), _AR_OffsetU);
float2 AR_VN = _AR_OffsetU_var.xy * 0.5 + float2(0.5, 0.5);
float2 AR_VN_Rotate = RotateUV(AR_VN, -(utsData.cameraDir * utsData.cameraRoll), float2(0.5, 0.5), 1.0);
float2 _AR_OffsetV_var = float2(AR_VN_Rotate.x, lerp(input.texCoord1.y, AR_VN_Rotate.y, _AR_OffsetV));
float4 _AngelRing_Sampler_var = tex2D(_AngelRing_Sampler, TRANSFORM_TEX(_AR_OffsetV_var, _AngelRing_Sampler));
float3 _Is_LightColor_AR_var = lerp((_AngelRing_Sampler_var.rgb * _AngelRing_Color.rgb), ((_AngelRing_Sampler_var.rgb * _AngelRing_Color.rgb) * Set_LightColor), _Is_LightColor_AR);
_Is_LightColor_AR_var = _Is_LightColor_AR_var * max(_AR_ShadowIntensity, (1 - Set_FinalShadowMask));
float3 Set_AngelRing = _Is_LightColor_AR_var * _AR_Intensity;
float Set_ARtexAlpha = _AngelRing_Sampler_var.a;
float3 Set_AngelRingWithAlpha = (_Is_LightColor_AR_var * _AngelRing_Sampler_var.a);
//Composition: MatCap and AngelRing as diffuseTerm
# ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_AngelRingMaskColor, float4(_AngelRingMaskColor.w, _AngelRingMaskColor.w, _AngelRingMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_AngelRingOverridden, _ComposerMaskMode);
_AngelRing *= _AngelRingVisible;
diffuseTerm = lerp(diffuseTerm, lerp((diffuseTerm + Set_AngelRing), ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
if (any(Set_AngelRing) * maskEnabled)
{
diffuseTerm = lerp(diffuseTerm, lerp(overridingColor.xyz, ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
channelOutAlpha = _AngelRingVisible;
}
}
# else
diffuseTerm = lerp(diffuseTerm, lerp((diffuseTerm + Set_AngelRing), ((diffuseTerm * (1.0 - Set_ARtexAlpha)) + Set_AngelRingWithAlpha), _ARSampler_AlphaOn), _AngelRing);// Final Composition before Emissive
# endif //#ifdef UTS_LAYER_VISIBILITY
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 5)
{
clippingColor = _Is_LightColor_AR_var;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
//diffuseTerm = Set_AngelRing * 10 * (1 - Set_FinalShadowMask);
#endif //#ifdef _IS_ANGELRING_OFF
// PBR----------------------------------------------------------------------------------------------------------------
//Specular Term
//float3 specularTerm = ComputeSpecularTerm(V, lightDirection, bsdfData) * (1 - Set_FinalShadowMask) * PI * surfaceData.specularColor * Set_LightColor;
float3 specularTerm = 0;
//SSS
float3 sssColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, FitWithCurveApprox(1 - Set_FinalShadowMask, 1));
sssColor *= _BaseColor.rgb * _MainTex_var.rgb * Set_LightColor;
specularTerm *= lerp((1 - Set_FinalShadowMask), FitWithCurveApprox(1 - Set_FinalShadowMask, 1).r, _Use_SSSLut);
diffuseTerm = lerp(diffuseTerm, sssColor, _Use_SSSLut);
utsAggregateLighting.directDiffuse += diffuseTerm * utsLightData.diffuseDimmer;
utsAggregateLighting.directSpecular += specularTerm * utsLightData.specularDimmer;
#endif // _SDFShadow
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b18b203f15b921a47a7cf30e26007d1a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,258 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#include "Packages/com.misaki.hdrp-toon/Runtime/HDRP/Shaders/Includes/Common/UtsPBR.hlsl"
void UTS_OtherLights(LightLoopContext lightLoopContext, FragInputs input, UTSLightData utsLightData, SurfaceData surfaceData, BSDFData bsdfData, int lightType, float3 i_normalDir, float notDirectional,
out float channelOutAlpha, inout UTSAggregateLighting utsAggregateLighting)
{
channelOutAlpha = 1.0f;
// We dont have to calculate lighting here if we are using sdf shadow
#ifndef _SDFShadow
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode != 0)
{
return float3(0.0f, 0.0f, 0.0f);
}
#endif // _IS_CLIPPING_MATTE
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
/* todo. these should be put into struct */
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
float3 lightDirection = utsLightData.lightDirection;
float3 additionalLightColor = utsLightData.lightColor * _Light_Intensity_Multiplier;
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
float4 Set_UV0 = input.texCoord0;
float3x3 tangentTransform = input.tangentToWorld;
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
float3 normalDirection = surfaceData.normalWS; // Perturbed normals
float3 viewDirection = V;
float4 _MainTex_var = float4(surfaceData.baseColor.r, surfaceData.baseColor.g, surfaceData.baseColor.b, surfaceData.coatMask);
/* end of todo.*/
SHADOW_TYPE shadowAttenuation = lightLoopContext.shadowValue;
#if !defined (UTS_USE_RAYTRACING_SHADOW)
shadowAttenuation *= 2.0f;
shadowAttenuation = saturate(shadowAttenuation);
#endif
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
//v.2.0.5:
float3 addPassLightColor;
if (lightType == GPULIGHTTYPE_TUBE)
{
addPassLightColor = (0.5f * preLightData.diffuseFGD + 0.5f) / PI * additionalLightColor.rgb;
}
else if (lightType == GPULIGHTTYPE_RECTANGLE)
{
addPassLightColor = preLightData.diffuseFGD * additionalLightColor.rgb;
}
else
{
addPassLightColor = _HalfLambert_var * additionalLightColor.rgb;
}
float pureIntensity = max(0.001, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b));
float3 lightColor = max(float3(0.0, 0.0, 0.0), lerp(addPassLightColor, lerp(float3(0.0, 0.0, 0.0), min(addPassLightColor, addPassLightColor / pureIntensity), notDirectional), _Is_Filter_LightColor));
float3 halfDirection = normalize(viewDirection + lightDirection); // has to be recalced here.
//v.2.0.5:
_1st_ShadeColor_Step = saturate(_1st_ShadeColor_Step + _StepOffset);
_2nd_ShadeColor_Step = saturate(_2nd_ShadeColor_Step + _StepOffset);
//
//v.2.0.5: If Added lights is directional, set 0 as _LightIntensity
float _LightIntensity = lerp(0, pureIntensity, notDirectional);
//v.2.0.5: Filtering the high intensity zone of PointLights
float3 Set_LightColor = lightColor;
//
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb * _LightIntensity), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
#ifdef UTS_LAYER_VISIBILITY
float Set_BaseColorAlpha = _BaseColorVisible;
float4 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
Set_BaseColor = lerp(Set_BaseColor, overridingColor, maskEnabled);
Set_BaseColor *= _BaseColorVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
//v.2.0.5
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _MainTex_var, _Use_BaseAs1st);
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb * _LightIntensity), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor, maskEnabled);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
}
float Set_1st_ShadeAlpha = _FirstShadeVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
//v.2.0.5
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_2nd_ShadeMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap)), _1st_ShadeMap_var, _Use_1stAs2nd);
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb * _LightIntensity), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor, maskEnabled);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
}
#endif //#ifdef UTS_LAYER_VISIBILITY
// //v.2.0.5:
//SGM
//v.2.0.6
float4 _ShadingGradeMap_var = tex2Dlod(_ShadingGradeMap, float4(TRANSFORM_TEX(Set_UV0, _ShadingGradeMap), 0.0, _BlurLevelSGM));
//v.2.0.6
//Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
float _SystemShadowsLevel_var = (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel > 0.001 ? (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel : 0.0001;
float _ShadingGradeMapLevel_var = _ShadingGradeMap_var.r < 0.95 ? _ShadingGradeMap_var.r + _Tweak_ShadingGradeMapLevel : 1;
float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var)*lerp( _HalfLambert_var, (_HalfLambert_var * saturate(_SystemShadowsLevel_var)), _Set_SystemShadowsToBase );
//float Set_ShadingGrade = saturate(_ShadingGradeMapLevel_var) * lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase);
float _1stColorFeatherForMask = lerp(_1st_ShadeColor_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
float _2ndColorFeatherForMask = lerp(_2nd_ShadeColor_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
//
float Set_FinalShadowMask = saturate(1.0 + (Set_ShadingGrade - (_1st_ShadeColor_Step - _1stColorFeatherForMask)) * (0.0 - 1.0) / (_1st_ShadeColor_Step - (_1st_ShadeColor_Step - _1stColorFeatherForMask)));
float Set_ShadeShadowMask = saturate(1.0 + (Set_ShadingGrade - (_2nd_ShadeColor_Step - _2ndColorFeatherForMask)) * (0.0 - 1.0) / (_2nd_ShadeColor_Step - (_2nd_ShadeColor_Step - _2ndColorFeatherForMask))); // 1st and 2nd Shades Mask
//SGM
//Composition: 3 Basic Colors as diffuseTerm
float3 diffuseTerm =
lerp(
Set_BaseColor,
lerp(
Set_1st_ShadeColor,
Set_2nd_ShadeColor,
Set_ShadeShadowMask
),
Set_FinalShadowMask);
#ifdef UTS_LAYER_VISIBILITY
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
channelOutAlpha =
lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, Set_ShadeShadowMask), Set_FinalShadowMask);
#endif
//v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
float3 _HighColor_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
float _RimArea_var = dot(surfaceData.normalWS, V);
_RimArea_var = lerp(_RimArea_var, 1 - _RimArea_var, _Is_BlendAddToRimColor);
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
float _VertHalfLambert_var = 0.5 * dot(surfaceData.normalWS, lightDirection) + 0.5;
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
//Composition: HighColor and RimLight as _RimLight_var
#ifdef UTS_LAYER_VISIBILITY
float4 overrideColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
float isMaskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
//_HighColor_var *= _TweakHighColorMask_var;
//_HighColor_var *= _HighlightVisible;
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
float Set_RimLightAlpha = _RimLightVisible;
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
Set_RimLight *= _RimLightVisible;
Set_RimLight *= _RimLight_Strength;
if (any(Set_RimLight) * maskRimEnabled)
{
//_HighColor_var = overridingRimColor;
channelOutAlpha = Set_RimLightAlpha;
}
/*
diffuseTerm =
lerp(saturate(diffuseTerm - _TweakHighColorMask_var), diffuseTerm,
lerp(_Is_BlendAddToHiColor, 1.0
, _Is_SpecularToHighColor));
float3 addColor =
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
, _Is_UseTweakHighColorOnShadow);
diffuseTerm += addColor;
if (any(addColor))
{
diffuseTerm = lerp(diffuseTerm, overrideColor, isMaskEnabled);
channelOutAlpha = _HighlightVisible;
}
*/
// Rim light
diffuseTerm = lerp(lerp(diffuseTerm, (diffuseTerm * Set_RimLight), _RimLight), lerp(diffuseTerm, (diffuseTerm + Set_RimLight), _RimLight), _Is_BlendAddToRimColor);
#else
_HighColor_var *= _TweakHighColorMask_var;
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
Set_RimLight *= _RimLight_Strength;
diffuseTerm = diffuseTerm + lerp(lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow), float3(0, 0, 0), _Is_Filter_HiCutPointLightColor);
// Rim light
diffuseTerm = lerp(lerp(diffuseTerm, (diffuseTerm * Set_RimLight), _RimLight), lerp(diffuseTerm, (diffuseTerm + Set_RimLight), _RimLight), _Is_BlendAddToRimColor);
#endif
// PBR----------------------------------------------------------------------------------------------------------------
float albedoIntensity = max(0.1, (1 - sqrt(surfaceData.metallic)) * (1.7 - 0.7 * (1 - sqrt(surfaceData.metallic))));
//Specular Term
float3 specularTerm = 0;
#ifndef _PBR_Mode_OFF
if(lightType == GPULIGHTTYPE_RECTANGLE || lightType == GPULIGHTTYPE_TUBE)
{
specularTerm = preLightData.specularFGD * Set_LightColor;
#ifdef _PBR_Mode_TOON
specularTerm = StepFeatherToon(specularTerm, _ToonSpecularStep, _ToonSpecularFeather);
#endif
}
else
{
//specularTerm = ComputeSpecularTerm(V, lightDirection, bsdfData) * Set_LightColor;
}
#endif
specularTerm = specularTerm * (1.0 - Set_FinalShadowMask) * PI * surfaceData.specularColor;
diffuseTerm = diffuseTerm * albedoIntensity;
utsAggregateLighting.directDiffuse += diffuseTerm * utsLightData.diffuseDimmer;
utsAggregateLighting.directSpecular += specularTerm * utsLightData.specularDimmer;
#endif // _SDFShadow
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e0d6ddf3fb34bef48b91a2fb9cae8cb1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,220 @@
#ifndef UTS_AREA_LIGHT_INLCUDE
#define UTS_AREA_LIGHT_INLCUDE
// The output is *not* normalized by the factor of 1/TWO_PI (this is done by the PolygonFormFactor function).
real3 UTS_ComputeEdgeFactor(real3 V1, real3 V2)
{
real V1oV2 = dot(V1, V2);
real3 V1xV2 = cross(V1, V2); // Plane normal (tangent to the unit sphere)
real sqLen = saturate(1 - V1oV2 * V1oV2); // length(V1xV2) = abs(sin(angle))
real rcpLen = rsqrt(max(FLT_EPS, sqLen)); // Make sure it is finite
#if 0
real y = rcpLen * acos(V1oV2);
#else
// Let y[x_] = ArcCos[x] / Sqrt[1 - x^2].
// Range reduction: since ArcCos[-x] == Pi - ArcCos[x], we only need to consider x on [0, 1].
real x = abs(V1oV2);
// Limit[y[x], x -> 1] == 1,
// Limit[y[x], x -> 0] == Pi/2.
// The approximation is exact at the endpoints of [0, 1].
// Max. abs. error on [0, 1] is 1.33e-6 at x = 0.0036.
// Max. rel. error on [0, 1] is 8.66e-7 at x = 0.0037.
real y = HALF_PI + x * (-0.99991 + x * (0.783393 + x * (-0.649178 + x * (0.510589 + x * (-0.326137 + x * (0.137528 + x * -0.0270813))))));
if (V1oV2 < 0)
{
y = rcpLen * PI - y;
}
#endif
return V1xV2 * y;
}
// Input: 3-5 vertices in the coordinate frame centered at the shaded point.
// Output: signed vector irradiance.
// No horizon clipping is performed.
real3 UTS_PolygonFormFactor(real4x3 L, real3 L4, uint n, bool isDiffuse)
{
// The length cannot be zero since we have already checked
// that the light has a non-zero effective area,
// and thus its plane cannot pass through the origin.
L[0] = normalize(L[0]);
L[1] = normalize(L[1]);
L[2] = normalize(L[2]);
switch (n)
{
case 3:
L[3] = L[0];
break;
case 4:
L[3] = normalize(L[3]);
L4 = L[0];
break;
case 5:
L[3] = normalize(L[3]);
L4 = normalize(L4);
break;
}
// If the magnitudes of a pair of edge factors are
// nearly the same, catastrophic cancellation may occur:
// https://en.wikipedia.org/wiki/Catastrophic_cancellation
// For the same reason, the value of the cross product of two
// nearly collinear vectors is prone to large errors.
// Therefore, the algorithm is inherently numerically unstable
// for area lights that shrink to a line (or a point) after
// projection onto the unit sphere.
real3 F = UTS_ComputeEdgeFactor(L[0], L[1]);
F += UTS_ComputeEdgeFactor(L[1], L[2]);
F += UTS_ComputeEdgeFactor(L[2], L[3]);
if (n >= 4)
F += UTS_ComputeEdgeFactor(L[3], L4);
if (n == 5)
F += UTS_ComputeEdgeFactor(L4, L[0]);
return lerp(INV_TWO_PI * F, HALF_PI * F, isDiffuse); // The output may be projected onto the tangent plane (F.z) to yield signed irradiance.
}
// See "Real-Time Area Lighting: a Journey from Research to Production", slide 102.
// Turns out, despite the authors claiming that this function "calculates an approximation of
// the clipped sphere form factor", that is simply not true.
// First of all, above horizon, the function should then just return 'F.z', which it does not.
// Secondly, if we use the correct function called DiffuseSphereLightIrradiance(), it results
// in severe light leaking if the light is placed vertically behind the camera.
// So this function is clearly a hack designed to work around these problems.
real UTS_PolygonIrradianceFromVectorFormFactor(float3 F, bool isDiffuse)
{
float l = length(F);
float z = lerp(F.z , INV_TWO_PI * F.z, isDiffuse);
return max(0, (l * l + z) / (l + 1));
}
// Expects non-normalized vertex positions.
// Output: F is the signed vector irradiance.
real UTS_PolygonIrradiance(real4x3 L, bool isDiffuse, out real3 F)
{
//APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT
F = UTS_PolygonFormFactor(L, float3(0,0,1), 4, isDiffuse);
return UTS_PolygonIrradianceFromVectorFormFactor(F, isDiffuse); // Accounts for the horizon.
}
// This function assumes that inputs are well-behaved, e.i.
// that the line does not pass through the origin and
// that the light is (at least partially) above the surface.
float UTS_Diffuse_Line(float3 C, float3 A, float hl)
{
// Solve C.z + h * A.z = 0.
float h = -C.z * rcp(A.z); // May be Inf, but never NaN
// Clip the line segment against the z-plane if necessary.
float h2 = (A.z >= 0) ? max( hl, h)
: min( hl, h); // P2 = C + h2 * A
float h1 = (A.z >= 0) ? max(-hl, h)
: min(-hl, h); // P1 = C + h1 * A
// Normalize the tangent.
float as = dot(A, A); // |A|^2
float ar = rsqrt(as); // 1/|A|
float a = as * ar; // |A|
float3 T = A * ar; // A/|A|
// Orthogonal 2D coordinates:
// P(n, t) = n * N + t * T.
float tc = dot(T, C); // C = n * N + tc * T
float3 P0 = C - tc * T; // P(n, 0) = n * N
float ns = dot(P0, P0); // |P0|^2
float nr = rsqrt(ns); // 1/|P0|
float n = ns * nr; // |P0|
float Nz = P0.z * nr; // N.z = P0.z/|P0|
// P(n, t) - C = P0 + t * T - P0 - tc * T
// = (t - tc) * T = h * A = (h * a) * T.
float t2 = tc + h2 * a; // P2.t
float t1 = tc + h1 * a; // P1.t
float s2 = ns + t2 * t2; // |P2|^2
float s1 = ns + t1 * t1; // |P1|^2
float mr = rsqrt(s1 * s2); // 1/(|P1|*|P2|)
float r2 = s1 * (mr * mr); // 1/|P2|^2
float r1 = s2 * (mr * mr); // 1/|P1|^2
// I = (i1 + i2 + i3) / Pi.
// i1 = N.z * (P2.t / |P2|^2 - P1.t / |P1|^2).
// i2 = -T.z * (P2.n / |P2|^2 - P1.n / |P1|^2).
// i3 = N.z * ArcCos[Dot[P1, P2] / (|P1| * |P2|)] / |P0|.
float i12 = (Nz * t2 - (T.z * n)) * r2
- (Nz * t1 - (T.z * n)) * r1;
// Guard against numerical errors.
float dt = min(1, (ns + t1 * t2) * mr);
float i3 = acos(dt) * (Nz * nr); // angle * cos(θ) / r^2
//return T.z * n ;
// Guard against numerical errors.
return INV_PI * max(0, i12 + i3);
}
float4 UTS_EvaluateLTC_Area(bool isRectLight, float3 center, float3 right, float3 up, float halfLength, float halfHeight,
float3x3 invM, float perceptualRoughness, bool isDiffuse, int cookieMode, float4 cookieScaleOffset)
{
float3 ortho = cross(center, right);
float orthoSq = dot(ortho, ortho);
// Check whether the light is in a vertical orientation.
bool quit = (orthoSq == 0);
// Check whether the light is entirely below the surface.
// We must test twice, since a linear transformation
// may bring the light above the surface (a side-effect).
quit = quit || (center.z + halfLength * abs(right.z) + halfHeight * abs(up.z) <= 0);
float4 ltcValue = float4(1, 1, 1, 0);
if (quit && !isDiffuse)
{
return ltcValue;
}
// Perform a sparse matrix multiplication.
float3 C = mul(invM, center);
float3 A = mul(invM, right);
float3 B = mul(invM, up);
// Check whether the light is entirely below the surface.
// We must test twice, since a linear transformation
// may bring the light below the surface (as expected).
if (C.z + halfLength * abs(A.z) + halfHeight * abs(B.z) <= 0 && !isDiffuse)
{
return ltcValue;
}
if (isRectLight)
{
float4x3 lightVerts;
lightVerts[0] = C - halfLength * A - halfHeight * B; // LL
lightVerts[1] = lightVerts[0] + (2 * halfHeight) * B; // UL
lightVerts[2] = lightVerts[1] + (2 * halfLength) * A; // UR
lightVerts[3] = lightVerts[2] - (2 * halfHeight) * B; // LR
// Polygon irradiance in the transformed configuration.
float3 fromFactor;
ltcValue.a = UTS_PolygonIrradiance(lightVerts, isDiffuse, fromFactor);
if (cookieMode != COOKIEMODE_NONE)
{
ltcValue.rgb = SampleAreaLightCookie(cookieScaleOffset, lightVerts, fromFactor, perceptualRoughness);
}
}
else // Line light
{
float w = ComputeLineWidthFactor(invM, ortho, orthoSq);
ltcValue.a = UTS_Diffuse_Line(C, A, halfLength) * w;
}
return ltcValue;
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: afada69a218dd594ea0f17e7c639c533
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,231 @@
#ifndef UTS_ENV
#define UTS_ENV
#include "Packages/com.misaki.hdrp-toon/Runtime/HDRP/Shaders/Includes/Common/UtsCommon.hlsl"
// _preIntegratedFGD and _CubemapLD are unique for each BRDF
float3 EvaluateBSDF_ReflectionProbe(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, EnvLightData lightData, UtsBSDFData bsdfData,
int influenceShapeType,
inout float hierarchyWeight)
{
float weight = 1.0;
float3 R = reflect(-V, bsdfData.normalWS);
EvaluateLight_EnvIntersection(posInput.positionWS, bsdfData.normalWS, lightData, influenceShapeType, R, weight);
// No distance based roughness for simple lit
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections, lightData.rangeCompressionFactorCompensation, posInput.positionNDC);
weight *= preLD.a; // Used by planar reflection to discard pixel
//envLighting = F_Schlick(bsdfData.fresnel0, dot(bsdfData.normalWS, V)) * preLD.rgb;
float3 envLighting = preLD.rgb;
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
envLighting *= weight * lightData.multiplier;
return envLighting;
}
float4 ComputeReflection(LightLoopContext context, PositionInputs posInput, PreLightData preLightData, BuiltinData builtinData, UtsBSDFData bsdfData, float3 V)
{
float3 refcolor = 0;
float reflectionHierarchyWeight = 0.0; // Max: 1.0
uint envLightStart, envLightCount;
// Fetch first env light to provide the scene proxy for screen space computation
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
GetCountAndStart(posInput, LIGHTCATEGORY_ENV, envLightStart, envLightCount);
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
envLightCount = _EnvLightCount;
envLightStart = 0;
#endif
bool fastPath = false;
#if SCALARIZE_LIGHT_LOOP
uint envStartFirstLane;
fastPath = IsFastPath(envLightStart, envStartFirstLane);
#endif
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
#if SCALARIZE_LIGHT_LOOP
if (fastPath)
{
envLightStart = envStartFirstLane;
}
#endif
// Scalarized loop, same rationale of the punctual light version
uint v_envLightListOffset = 0;
uint v_envLightIdx = envLightStart;
#if NEED_TO_CHECK_HELPER_LANE
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
// sure it will not happen.
bool isHelperLane = WaveIsHelperLane();
while (!isHelperLane && v_envLightListOffset < envLightCount)
#else
while (v_envLightListOffset < envLightCount)
#endif
{
v_envLightIdx = FetchIndex(envLightStart, v_envLightListOffset);
#if SCALARIZE_LIGHT_LOOP
uint s_envLightIdx = ScalarizeElementIndex(v_envLightIdx, fastPath);
#else
uint s_envLightIdx = v_envLightIdx;
#endif
if (s_envLightIdx == -1)
break;
EnvLightData s_envLightData = FetchEnvLight(s_envLightIdx); // Scalar load.
// If current scalar and vector light index match, we process the light. The v_envLightListOffset for current thread is increased.
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// end up with a unique v_envLightIdx value that is smaller than s_envLightIdx hence being stuck in a loop. All the active lanes will not have this problem.
if (s_envLightIdx >= v_envLightIdx)
{
v_envLightListOffset++;
if (reflectionHierarchyWeight < 1.0)
{
if (IsMatchingLightLayer(s_envLightData.lightLayers, builtinData.renderingLayers))
{
float RefProbeLighting = EvaluateBSDF_ReflectionProbe(context, V, posInput, preLightData, s_envLightData, bsdfData, s_envLightData.influenceShapeType, reflectionHierarchyWeight);
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
float3 lightInReflDir = float3(-1, -1, -1);
if (s_envLightData.normalizeWithAPV > 0 && all(lightInReflDir >= 0))
{
float factor = GetReflectionProbeNormalizationFactor(lightInReflDir, bsdfData.normalWS, s_envLightData.L0L1, s_envLightData.L2_1, s_envLightData.L2_2);
RefProbeLighting *= factor;
}
#endif
refcolor += RefProbeLighting;
}
}
}
}
return float4(refcolor.r, refcolor.g, refcolor.b, reflectionHierarchyWeight);
}
float3 ComputeFresnelLerp(float3 c0, float3 c1, float cosA)
{
float t = pow(1 - cosA, 5);
return lerp(c0, c1, t);
}
float3 EvaluateIndirectDiffusePBR(PositionInputs posInput, UtsBSDFData bsdfData, float3 V)
{
float3 indirectDiffuse = 0.0;
#ifdef _PBR_Mode_ANISO
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
#endif
float NdotV = saturate(dot(bsdfData.normalWS, V));
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
BuiltinData apvBuiltinData;
ZERO_INITIALIZE(BuiltinData, apvBuiltinData);
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), 0.0, 0.0, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
#else
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), bsdfData.normalWS, -bsdfData.normalWS, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
#endif
float3 probeDiffuse = apvBuiltinData.bakeDiffuseLighting * GetCurrentExposureMultiplier();
indirectDiffuse = probeDiffuse;
#else
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
indirectDiffuse = EvaluateAmbientProbe(0.0) * GetCurrentExposureMultiplier();
#else
indirectDiffuse = EvaluateAmbientProbe(bsdfData.normalWS) * GetCurrentExposureMultiplier();
#endif
#endif
//SSGI
if(_ReceivesSSGI == 1)
{
float4 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS);
ssgiLighting *= _GIMultiplier;
indirectDiffuse = lerp(indirectDiffuse, ssgiLighting.rgb, ssgiLighting.a);
}
//Complete the indirect lighting
indirectDiffuse *= bsdfData.diffuseColor.rgb * _BaseColor.rgb;
//SSAO
if(_ReceivesSSAO == 1)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
indirectDiffuse *= lerp(_AO_Factor, 1, aoFactor.indirectAmbientOcclusion);
}
indirectDiffuse *= bsdfData.ambientOcclusion;
return indirectDiffuse;
}
float3 EvaluateIndirectDiffuse(PositionInputs posInput, UtsBSDFData bsdfData, float3 V)
{
float3 indirectDiffuse = 0.0;
indirectDiffuse = EvaluateIndirectDiffusePBR(posInput, bsdfData,V);
return indirectDiffuse * _ID_Intensity;
}
float3 EvaluateIndirectSpecular(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, float3 V)
{
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
return 0;
#else
float3 indirectSpecular = 0;
#ifdef _PBR_Mode_ANISO
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
#endif
float mip = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
float NdotV = saturate(dot(bsdfData.normalWS, V));
indirectSpecular = SampleSkyTexture(reflect(-V, bsdfData.normalWS), mip, 0).rgb;\
//Reflection Probe
float4 refProbe = ComputeReflection(lightLoopContext, posInput, preLightData, builtinData, bsdfData, V);
indirectSpecular = lerp(indirectSpecular, refProbe.rgb, refProbe.a);
//SSR
if(_ReceivesSSR == 1)
{
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS);
InversePreExposeSsrLighting(ssrLighting);
ApplyScreenSpaceReflectionWeight(ssrLighting);
indirectSpecular = lerp(indirectSpecular, ssrLighting.rgb * preLightData.specularFGD, ssrLighting.a);
}
//Complete the indirect lighting
float grazingTerm = saturate((1 - bsdfData.perceptualRoughness) + (1 - bsdfData.reflectivity));
indirectSpecular *= ComputeFresnelLerp(bsdfData.fresnel0, grazingTerm, NdotV) * GetCurrentExposureMultiplier();
// Occlusion
if(_ReceivesSSAO == 1)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
indirectSpecular *= lerp(_AO_Factor, 1, aoFactor.indirectSpecularOcclusion);
}
indirectSpecular *= bsdfData.specularOcclusion;
return indirectSpecular * _IR_Intensity;
#endif
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 52ab7245a70fe6a4e80663ca80f9811b
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,264 @@
#ifndef UTS_LIGHT_EVALUATION
#define UTS_LIGHT_EVALUATION
#if FP_BUFFER
#define SATURATE_IF_SDR(x) (x)
#define SATURATE_BASE_COLOR_IF_SDR(x) (x)
#else
#define SATURATE_IF_SDR(x) saturate(x)
#define SATURATE_BASE_COLOR_IF_SDR(x) saturate(x)
#endif
const float rateR = 0.299;
const float rateG = 0.587;
const float rateB = 0.114;
struct UTSLightData
{
float3 lightDirection;
float3 lightColor;
float diffuseDimmer;
float specularDimmer;
float3 shadowTint;
float penumbraTint;
SHADOW_TYPE shadowValue;
};
float GetColorAttenuation(float3 lightColor)
{
float lightAttenuation = rateR * lightColor.r + rateG * lightColor.g + rateB * lightColor.b;
return lightAttenuation;
}
float3 GetLimitedLightColor(float3 lightColor)
{
lightColor = ApplyCurrentExposureMultiplier(lightColor);
float3 result = lerp(lightColor, saturate(lightColor), _Is_Filter_LightColor);
return result;
}
DirectLighting UtsEvaluateBSDF_Directional(LightLoopContext lightLoopContext, PositionInputs posInput, BuiltinData builtinData, DirectionalLightData lightData, UtsBSDFData bsdfData, PreLightData preLightData, float3 V, float2 uv0)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 L = -lightData.forward;
SHADOW_TYPE shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.geomNormalWS);
if (lightData.lightDimmer > 0.0)
{
// TODO: Colored shadow will overwrite the first and second shading diffuse color
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
float4 lightColor = EvaluateLight_Directional(lightLoopContext, posInput, lightData);
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _Light_Intensity_Multiplier);
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
lighting = UtsShadeSurface(posInput, bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
}
return lighting;
}
DirectLighting UtsEvaluateBSDF_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput, BuiltinData builtinData, LightData lightData, UtsBSDFData bsdfData, PreLightData preLightData, float3 V, float2 uv0)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 L;
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);
if (lightData.lightDimmer > 0.0)
{
// TODO: Colored shadow will overwrite the first and second shading diffuse color
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
float4 lightColor = EvaluateLight_Punctual(lightLoopContext, posInput, lightData, L, distances);
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _Light_Intensity_Multiplier);
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
lighting = UtsShadeSurface(posInput, bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
}
return lighting;
}
IndirectLighting UtsEvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, PreLightData preLightData, inout float reflectionHierarchyWeight)
{
IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
// TODO: this texture is sparse (mostly black). Can we avoid reading every texel? How about using Hi-S?
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS);
InversePreExposeSsrLighting(ssrLighting);
// Apply the weight on the ssr contribution (if required)
ApplyScreenSpaceReflectionWeight(ssrLighting);
reflectionHierarchyWeight = ssrLighting.a;
lighting.specularReflected = ssrLighting.rgb * preLightData.specularFGD;
return lighting;
}
void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, float3 V, inout BuiltinData builtinData, out float3 lightInReflDir)
{
lightInReflDir = 0.0;
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
lightInReflDir = float3(-1, -1, -1); // This variable is used with APV for reflection probe normalization - see code for LIGHTFEATUREFLAGS_ENV
#endif
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
{
builtinData.bakeDiffuseLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
}
else
#endif
{
#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,
posInput.positionSS, builtinData.renderingLayers,
builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting, lightInReflDir);
}
else // If probe volume is disabled we fallback on the ambient probes
{
builtinData.bakeDiffuseLighting = EvaluateAmbientProbe(bsdfData.normalWS);
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(-bsdfData.normalWS);
}
#endif
}
}
void UtsEvaluateBSDF_MatCapDiffuse(float3 positionWS, float3 normalWS, inout BuiltinData builtinData)
{
float3 positionVS = mul(UNITY_MATRIX_V, float4(positionWS, 1.0)).xyz;
float3 normalVS = mul(UNITY_MATRIX_V, float4(normalWS, 1.0)).xyz;
float3 PcrossN = cross(normalize(positionVS), normalVS);
float2 uv = PcrossN.yx;
uv.x *= -1;
uv = uv * 0.5 + 0.5;
builtinData.bakeDiffuseLighting = SAMPLE_TEXTURE2D_LOD(_MatCapMap, s_linear_clamp_sampler, uv, UNITY_SPECCUBE_LOD_STEPS).rgb * GetInverseCurrentExposureMultiplier();
}
IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData bsdfData, PreLightData preLightData)
{
IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
float3 positionVS = mul(UNITY_MATRIX_V, float4(positionWS, 1.0)).xyz;
float3 normalVS = mul(UNITY_MATRIX_V, float4(bsdfData.normalWS, 1.0)).xyz;
float3 PcrossN = cross(normalize(positionVS), normalVS);
float2 uv = PcrossN.yx;
uv.x *= -1;
uv = uv * 0.5 + 0.5;
lighting.specularReflected = SAMPLE_TEXTURE2D_LOD(_MatCapMap, s_linear_clamp_sampler, uv, PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness)).rgb;
lighting.specularReflected *= preLightData.specularFGD * GetInverseCurrentExposureMultiplier();
return lighting;
}
void UtsEvaluateBSDF_Ramp(PositionInputs posInput, UtsBSDFData bsdfData, float3 L, inout BuiltinData builtinData)
{
// TODO
}
IndirectLighting UtsEvaluateBSDF_Env(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, EnvLightData lightData, UtsBSDFData bsdfData, int influenceShapeType, int GPUImageBasedLightingType, inout float hierarchyWeight)
{
IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
{
return lighting;
}
float3 envLighting;
float3 positionWS = posInput.positionWS;
float weight = 1.0;
float3 R = preLightData.iblR;
if (!IsEnvIndexTexture2D(lightData.envIndex)) // ENVCACHETYPE_CUBEMAP
{
R = GetSpecularDominantDir(bsdfData.normalWS, R, preLightData.iblPerceptualRoughness, ClampNdotV(preLightData.NdotV));
// When we are rough, we tend to see outward shifting of the reflection when at the boundary of the projection volume
// Also it appear like more sharp. To avoid these artifact and at the same time get better match to reference we lerp to original unmodified reflection.
// Formula is empirical.
float roughness = PerceptualRoughnessToRoughness(preLightData.iblPerceptualRoughness);
R = lerp(R, preLightData.iblR, saturate(smoothstep(0, 1, roughness * roughness)));
}
// Note: using influenceShapeType and projectionShapeType instead of (lightData|proxyData).shapeType allow to make compiler optimization in case the type is know (like for sky)
float intersectionDistance = EvaluateLight_EnvIntersection(positionWS, bsdfData.normalWS, lightData, influenceShapeType, R, weight);
float3 F = preLightData.specularFGD;
float4 preLD = SampleEnvWithDistanceBaseRoughness(lightLoopContext, posInput, lightData, R, preLightData.iblPerceptualRoughness, intersectionDistance);
weight *= preLD.a; // Used by planar reflection to discard pixel
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
{
envLighting = F * preLD.rgb;
// Apply the main lobe weight and update main reflection hierarchyWeight:
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
envLighting *= weight;
}
envLighting *= lightData.multiplier;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
{
lighting.specularReflected = envLighting;
}
return lighting;
}
void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
builtinData.bakeDiffuseLighting = APPLY_WEIGHT(builtinData.bakeDiffuseLighting, aoFactor.indirectAmbientOcclusion, _AO_Factor);
lighting.indirect.specularReflected = APPLY_WEIGHT(lighting.indirect.specularReflected, aoFactor.indirectSpecularOcclusion, _AO_Factor);
lighting.direct.diffuse = APPLY_WEIGHT(lighting.direct.diffuse, aoFactor.directAmbientOcclusion, _AO_Factor);
lighting.direct.specular = APPLY_WEIGHT(lighting.direct.specular, aoFactor.directSpecularOcclusion, _AO_Factor);
builtinData.bakeDiffuseLighting = ApplyCurrentExposureMultiplier(builtinData.bakeDiffuseLighting * bsdfData.diffuseColor * preLightData.diffuseFGD * _ID_Intensity);
lighting.indirect.specularReflected = ApplyCurrentExposureMultiplier(lighting.indirect.specularReflected * bsdfData.fresnel0 * _IR_Intensity);
lightLoopOutput.diffuseLighting = lighting.direct.diffuse + builtinData.bakeDiffuseLighting;
lightLoopOutput.specularLighting = lighting.direct.specular + lighting.indirect.specularReflected;
// Rescale the GGX to account for the multiple scattering.
lightLoopOutput.specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation;
ApplyExposureAdjustment(lightLoopOutput.diffuseLighting);
ApplyExposureAdjustment(lightLoopOutput.specularLighting);
lightLoopOutput.diffuseLighting += builtinData.emissiveColor;
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a7716c23dcdc6a544908969e8d507320
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,474 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#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"
// Channel mask enum.
// this must be same to UI cs code
// HDRPToonGUI._ChannelEnum
int eBaseColor = 0;
int eFirstShade = 1;
int eSecondShade = 2;
int eHighlight = 3;
int eAngelRing = 4;
int eRimLight = 5;
int eOutline = 6;
int GetNextDirectionalLightIndex(BuiltinData builtinData, int currentIndex, int mainLightIndex)
{
int i = 0; // Declare once to avoid the D3D11 compiler warning.
for (i = 0; i < (int)_DirectionalLightCount; ++i)
{
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
if (mainLightIndex != i)
{
if (currentIndex < i)
{
return i;
}
}
}
}
return -1; // not found
}
int GetUtsMainLightIndex(BuiltinData builtinData)
{
int mainLightIndex = -1;
float3 lightColor = float3(0.0f, 0.0f, 0.0f);
float lightAttenuation = 0.0f;
uint i = 0; // Declare once to avoid the D3D11 compiler warning.
for (i = 0; i < _DirectionalLightCount; ++i)
{
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
float3 currentLightColor = _DirectionalLightDatas[i].color;
float currentLightAttenuation = GetColorAttenuation(currentLightColor);
if (mainLightIndex == -1 || (currentLightAttenuation > lightAttenuation))
{
mainLightIndex = i;
lightAttenuation = currentLightAttenuation;
lightColor = currentLightColor;
}
}
}
return mainLightIndex;
}
bool UtsUseScreenSpaceShadow(DirectionalLightData light, float3 normalWS)
{
#if defined(RAY_TRACED_SCREEN_SPACE_SHADOW_FLAG)
// Two different options are possible here
// - We have a ray trace shadow in which case we have no valid signal for a transmission and we need to fallback on the rasterized shadow
// - We have a screen space shadow and it already contains the transmission shadow and we can use it straight away
bool visibleLight = 0.5 * dot(normalWS, -light.forward) + 0.5 > 0.0;
bool validScreenSpaceShadow = (light.screenSpaceShadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK) != INVALID_SCREEN_SPACE_SHADOW;
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);
#endif
}
void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bsdfData, BuiltinData builtinData,
float3 V, uint featureFlags, out LightLoopOutput lightLoopOutput)
{
LightLoopContext context;
context.shadowContext = InitShadowContext();
context.shadowValue = 1;
context.sampleReflection = 0;
#ifdef APPLY_FOG_ON_SKY_REFLECTIONS
context.positionWS = posInput.positionWS;
#endif
// Initialize the contactShadow and contactShadowFade fields
InitContactShadow(posInput, context);
// First of all we compute the shadow value of the directional light to reduce the VGPR pressure
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
{
// Evaluate sun shadows.
if (_DirectionalShadowIndex >= 0)
{
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT)
if (UseScreenSpaceShadow(light, bsdfData.normalWS))
{
context.shadowValue = GetScreenSpaceColorShadow(posInput, light.screenSpaceShadowIndex).SHADOW_TYPE_SWIZZLE;
}
else
#endif
{
float3 L = -light.forward;
// Is it worth sampling the shadow map?
if ((light.lightDimmer > 0) && (light.shadowDimmer > 0) && // Note: Volumetric can have different dimmer, thus why we test it here
dot(bsdfData.normalWS, L) > 0.0)
{
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
posInput.positionSS, posInput.positionWS + L * _ShadowBias, bsdfData.normalWS,
light.shadowIndex, L);
}
}
}
}
PreLightData preLightData = GetPreLightData_UTS(V, posInput, bsdfData);
AggregateLighting aggregateLighting;
ZERO_INITIALIZE(AggregateLighting, aggregateLighting);
// Evaluate the punctual lights.
if (featureFlags & LIGHTFEATUREFLAGS_PUNCTUAL)
{
uint lightCount, lightStart;
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
lightCount = _PunctualLightCount;
lightStart = 0;
#endif
bool fastPath = false;
#if SCALARIZE_LIGHT_LOOP
uint lightStartLane0;
fastPath = IsFastPath(lightStart, lightStartLane0);
if (fastPath)
{
lightStart = lightStartLane0;
}
#endif
// Scalarized loop. All lights that are in a tile/cluster touched by any pixel in the wave are loaded (scalar load), only the one relevant to current thread/pixel are processed.
// For clarity, the following code will follow the convention: variables starting with s_ are meant to be wave uniform (meant for scalar register),
// v_ are variables that might have different value for each thread in the wave (meant for vector registers).
// This will perform more loads than it is supposed to, however, the benefits should offset the downside, especially given that light data accessed should be largely coherent.
// Note that the above is valid only if wave intriniscs are supported.
uint v_lightListOffset = 0;
uint v_lightIdx = lightStart;
[loop] // vulkan shader compiler can not unroll.
#if NEED_TO_CHECK_HELPER_LANE
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
// sure it will not happen.
bool isHelperLane = WaveIsHelperLane();
while (!isHelperLane && v_lightListOffset < lightCount)
#else
while (v_lightListOffset < lightCount)
#endif
{
v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
#if SCALARIZE_LIGHT_LOOP
uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
#else
uint s_lightIdx = v_lightIdx;
#endif
if (s_lightIdx == -1)
{
break;
}
LightData s_lightData = FetchLight(s_lightIdx);
// If current scalar and vector light index match, we process the light. The v_lightListOffset for current thread is increased.
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// end up with a unique v_lightIdx value that is smaller than s_lightIdx hence being stuck in a loop. All the active lanes will not have this problem.
if (s_lightIdx >= v_lightIdx)
{
v_lightListOffset++;
if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
{
DirectLighting lighting = UtsEvaluateBSDF_Punctual(context, posInput, builtinData, s_lightData, bsdfData, preLightData, V, fragInputs.texCoord0.xy);
AccumulateDirectLighting(lighting, aggregateLighting);
}
}
}
}
// Evaluate the directional lights.
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
{
uint i = 0; // Declare once to avoid the D3D11 compiler warning.
for (i = 0; i < _DirectionalLightCount; ++i)
{
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
DirectLighting direct = UtsEvaluateBSDF_Directional(context, posInput, builtinData, _DirectionalLightDatas[i], bsdfData, preLightData, V, fragInputs.texCoord0.xy);
AccumulateDirectLighting(direct, aggregateLighting);
}
}
}
// Evaluate the environment lights.
if (featureFlags & (LIGHTFEATUREFLAGS_ENV | LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_SSREFRACTION | LIGHTFEATUREFLAGS_SSREFLECTION))
{
float reflectionHierarchyWeight = 0.0; // Max: 1.0
uint envLightStart, envLightCount;
// Fetch first env light to provide the scene proxy for screen space computation
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
GetCountAndStart(posInput, LIGHTCATEGORY_ENV, envLightStart, envLightCount);
#else
envLightCount = _EnvLightCount;
envLightStart = 0;
#endif
bool fastPath = false;
#if SCALARIZE_LIGHT_LOOP
uint envStartFirstLane;
fastPath = IsFastPath(envLightStart, envStartFirstLane);
#endif
// Reflection hierarchy is
// 1. Screen Space Reflection
// 2. Environment Reflection
// 3. Sky Reflection
// Apply SSR.
#if (defined(_SURFACE_TYPE_TRANSPARENT) && !defined(_DISABLE_SSR_TRANSPARENT)) || (!defined(_SURFACE_TYPE_TRANSPARENT) && !defined(_DISABLE_SSR))
{
IndirectLighting lighting = UtsEvaluateBSDF_ScreenSpaceReflection(posInput, preLightData, reflectionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}
#endif
float3 lightInReflDir = 0.0;
#ifdef _INDIRECT_DIFFUSE_OFF
#elif _INDIRECT_DIFFUSE_IBL
bool replaceBakeDiffuseLighting = false;
#if !defined(_SURFACE_TYPE_TRANSPARENT) // No SSGI/RTGI/Mixed effect on transparent
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
{
replaceBakeDiffuseLighting = true;
}
#endif
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (!builtinData.isLightmap)
{
replaceBakeDiffuseLighting = true;
}
#endif
#if defined(LIGHT_EVALUATION_SKIP_INDIRECT_DIFFUSE)
replaceBakeDiffuseLighting = false;
#endif
if (replaceBakeDiffuseLighting)
{
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
}
#elif _INDIRECT_DIFFUSE_MATCAP
//builtinData.bakeDiffuseLighting = UtsEvaluateColor_MatCap(posInput.positionWS, bsdfData.normalWS, 0.0);
UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData);
#elif _INDIRECT_DIFFUSE_RAMP
UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData);
#endif
if (featureFlags & LIGHTFEATUREFLAGS_ENV)
{
#if _INDIRECT_SPECULAR_OFF
#elif _INDIRECT_SPECULAR_IBL
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
#if SCALARIZE_LIGHT_LOOP
if (fastPath)
{
envLightStart = envStartFirstLane;
}
#endif
// Scalarized loop, same rationale of the punctual light version
uint v_envLightListOffset = 0;
uint v_envLightIdx = envLightStart;
#if NEED_TO_CHECK_HELPER_LANE
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
// sure it will not happen.
bool isHelperLane = WaveIsHelperLane();
while (!isHelperLane && v_envLightListOffset < envLightCount)
#else
while (v_envLightListOffset < envLightCount)
#endif
{
v_envLightIdx = FetchIndex(envLightStart, v_envLightListOffset);
#if SCALARIZE_LIGHT_LOOP
uint s_envLightIdx = ScalarizeElementIndex(v_envLightIdx, fastPath);
#else
uint s_envLightIdx = v_envLightIdx;
#endif
if (s_envLightIdx == -1)
{
break;
}
EnvLightData s_envLightData = FetchEnvLight(s_envLightIdx);
// If current scalar and vector light index match, we process the light. The v_envLightListOffset for current thread is increased.
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// end up with a unique v_envLightIdx value that is smaller than s_envLightIdx hence being stuck in a loop. All the active lanes will not have this problem.
if (s_envLightIdx >= v_envLightIdx)
{
v_envLightListOffset++;
if (reflectionHierarchyWeight < 1.0)
{
if (IsMatchingLightLayer(s_envLightData.lightLayers, builtinData.renderingLayers))
{
IndirectLighting lighting = UtsEvaluateBSDF_Env(context, posInput, preLightData, s_envLightData, bsdfData, s_envLightData.influenceShapeType, GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION, reflectionHierarchyWeight);
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (s_envLightData.normalizeWithAPV > 0 && all(lightInReflDir >= 0))
{
float factor = GetReflectionProbeNormalizationFactor(lightInReflDir, bsdfData.normalWS, s_envLightData.L0L1, s_envLightData.L2_1, s_envLightData.L2_2);
lighting.specularReflected *= factor;
}
#endif
AccumulateIndirectLighting(lighting, aggregateLighting);
}
}
}
}
#elif _INDIRECT_SPECULAR_MATCAP
IndirectLighting lighting = UtsEvaluateBSDF_MatCapSpecular(posInput.positionWS, bsdfData, preLightData);
AccumulateIndirectLighting(lighting, aggregateLighting);
#endif
}
#if _INDIRECT_SPECULAR_IBL
// Only apply the sky IBL if the sky texture is available
if ((featureFlags & LIGHTFEATUREFLAGS_SKY) && _EnvLightSkyEnabled)
{
// The sky is a single cubemap texture separate from the reflection probe texture array (different resolution and compression)
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_SKY;
// The sky data are generated on the fly so the compiler can optimize the code
EnvLightData envLightSky = InitSkyEnvLightData(0);
// Only apply the sky if we haven't yet accumulated enough IBL lighting.
if (reflectionHierarchyWeight < 1.0)
{
IndirectLighting lighting = UtsEvaluateBSDF_Env(context, posInput, preLightData, envLightSky, bsdfData, envLightSky.influenceShapeType, GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION, reflectionHierarchyWeight);
AccumulateIndirectLighting(lighting, aggregateLighting);
}
}
#endif
}
UtsPostEvaluateBSDF(posInput, preLightData, bsdfData, builtinData, aggregateLighting, lightLoopOutput);
}
// UTSLightData GetUTSMainPunctualLightData(BuiltinData builtinData, PositionInputs posInput)
// {
// UTSLightData mainPunctualLight;
// uint lightCount, lightStart;
// #ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
// GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
// #else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
// lightCount = _PunctualLightCount;
// lightStart = 0;
// #endif
// bool fastPath = false;
// #if SCALARIZE_LIGHT_LOOP
// uint lightStartLane0;
// fastPath = IsFastPath(lightStart, lightStartLane0);
// if (fastPath)
// {
// lightStart = lightStartLane0;
// }
// #endif
// uint v_lightListOffset = 0;
// uint v_lightIdx = lightStart;
// float channelAlpha = 0.0f;
// [loop] // vulkan shader compiler can not unroll.
// while (v_lightListOffset < lightCount)
// {
// v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
// #if SCALARIZE_LIGHT_LOOP
// uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
// #else
// uint s_lightIdx = v_lightIdx;
// #endif
// if (s_lightIdx == -1)
// break;
// LightData s_lightData = FetchLight(s_lightIdx);
// // If current scalar and vector light index match, we process the light. The v_lightListOffset for current thread is increased.
// // Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// // end up with a unique v_lightIdx value that is smaller than s_lightIdx hence being stuck in a loop. All the active lanes will not have this problem.
// if (s_lightIdx >= v_lightIdx)
// {
// v_lightListOffset++;
// if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
// {
// float3 lightDirection;
// float4 distances; // {d, d^2, 1/d, d_proj}
// GetPunctualLightVectors(posInput.positionWS, s_lightData, lightDirection, distances);
// float4 lightColor = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirection, distances);
// float3 additionalLightColor = ApplyCurrentExposureMultiplier(lightColor.rgb) * lightColor.a;
// const float notDirectional = 1.0f;
// UTSLightData utsLightData;
// utsLightData.lightColor = additionalLightColor;
// utsLightData.lightDirection = lightDirection;
// utsLightData.diffuseDimmer = s_lightData.diffuseDimmer;
// utsLightData.specularDimmer = s_lightData.specularDimmer;
// utsLightData.shadowTint = s_lightData.shadowTint;
// utsLightData.penumbraTint = s_lightData.penumbraTint;
// if(length(additionalLightColor) >= length(mainPunctualLight.lightColor))
// {
// mainPunctualLight = utsLightData;
// }
// }
// }
// }
// return mainPunctualLight;
// }
// Todo: calculate the acutal main lighboth dorectional and punctual)t based on the light attenuation, rather than using the main directional light
UTSLightData GetCustomMainLightData(BuiltinData builtinData, UTSLightData mainPunctualLight)
{
UTSLightData utsLightData;
int mainLightIndex;
mainLightIndex = GetUtsMainLightIndex(builtinData);
if (mainLightIndex == -1 || length(_DirectionalLightDatas[mainLightIndex].color) < length(mainPunctualLight.lightColor))
{
utsLightData = mainPunctualLight;
}
else
{
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
utsLightData.lightDirection = -_DirectionalLightDatas[mainLightIndex].forward;
utsLightData.diffuseDimmer = _DirectionalLightDatas[mainLightIndex].diffuseDimmer;
utsLightData.specularDimmer = _DirectionalLightDatas[mainLightIndex].specularDimmer;
utsLightData.shadowTint = _DirectionalLightDatas[mainLightIndex].shadowTint;
utsLightData.penumbraTint = _DirectionalLightDatas[mainLightIndex].penumbraTint;
}
return utsLightData;
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9ed2a3a7c9a17104c9792d8ec79bf631
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#ifndef DirectionalShadowType
# if (SHADEROPTIONS_RAYTRACING && (defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_PSSL))
# define DirectionalShadowType float3
# else
# define DirectionalShadowType float
# endif
#endif
float3 UTS_SelfShdowMainLight(LightLoopContext lightLoopContext, FragInputs input, int mainLightIndex)
{
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
/* todo. these should be put int a struct */
float4 Set_UV0 = input.texCoord0;
float3x3 tangentTransform = input.tangentToWorld;
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
float4 n = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, Set_UV0.xy);
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
float3 normalLocal = _NormalMap_var.rgb;
float3 i_normalDir = surfaceData.normalWS;
/* to here todo. these should be put int a struct */
float shadowAttenuation = (float)lightLoopContext.shadowValue;
float3 mainLihgtDirection = -_DirectionalLightDatas[mainLightIndex].forward;
float3 mainLightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
// float3 mainLightColor = tmpColor.xyz;
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
////// Lighting:
float _HalfLambert_var = 0.5 * dot(i_normalDir, lightDirection) + 0.5;
float lambert = dot(i_normalDir, lightDirection);
_HalfLambert_var = lambert;
float baseColorStep = 0.00001;
float Set_FinalShadowMask = saturate(1.0 + (-_HalfLambert_var) / (baseColorStep));
float3 Set_FinalBaseColor = 1 - Set_FinalShadowMask;
return Set_FinalBaseColor;
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d53a3bfa05741064d9b4d15154890a04
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: