Organize folder structure;
Update RimLighting;
This commit is contained in:
785
Runtime/Shaders/Includes/Deprecated/ShaderPassForwardUTS.hlsl
Normal file
785
Runtime/Shaders/Includes/Deprecated/ShaderPassForwardUTS.hlsl
Normal file
@@ -0,0 +1,785 @@
|
||||
//Unity Toon Shader/HDRP
|
||||
//nobuyuki@unity3d.com
|
||||
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
||||
|
||||
#define APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT
|
||||
|
||||
#if SHADERPASS != SHADERPASS_FORWARD
|
||||
#error SHADERPASS_is_not_correctly_define
|
||||
#endif
|
||||
|
||||
#ifndef SCALARIZE_LIGHT_LOOP
|
||||
// We perform scalarization only for forward rendering as for deferred loads will already be scalar since tiles will match waves and therefore all threads will read from the same tile.
|
||||
// More info on scalarization: https://flashypixels.wordpress.com/2018/11/10/intro-to-gpu-scalarization-part-2-scalarize-all-the-lights/ .
|
||||
// Note that it is currently disabled on gamecore platforms for issues with wave intrinsics and the new compiler, it will be soon investigated, but we disable it in the meantime.
|
||||
#define SCALARIZE_LIGHT_LOOP (defined(PLATFORM_SUPPORTS_WAVE_INTRINSICS) && !defined(LIGHTLOOP_DISABLE_TILE_AND_CLUSTER) && !defined(SHADER_API_GAMECORE) && SHADERPASS == SHADERPASS_FORWARD)
|
||||
#endif
|
||||
|
||||
//#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/HDRP/Shaders/Includes/Common/UtsCommon.hlsl"
|
||||
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
return MotionVectorVS(varyingsType, inputMesh, inputPass);
|
||||
}
|
||||
|
||||
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
|
||||
|
||||
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
||||
{
|
||||
VaryingsType varyingsType;
|
||||
varyingsType.vmesh = VertMesh(inputMesh);
|
||||
|
||||
return PackVaryingsType(varyingsType);
|
||||
}
|
||||
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Attenuation Functions /
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Grafted from URP
|
||||
// Matches Unity Vanila attenuation
|
||||
// Attenuation smoothly decreases to light range.
|
||||
float DistanceAttenuation(float distanceSqr, half2 distanceAttenuation)
|
||||
{
|
||||
// We use a shared distance attenuation for additional directional and puctual lights
|
||||
// for directional lights attenuation will be 1
|
||||
float lightAtten = rcp(distanceSqr);
|
||||
|
||||
#if SHADER_HINT_NICE_QUALITY
|
||||
// Use the smoothing factor also used in the Unity lightmapper.
|
||||
half factor = distanceSqr * distanceAttenuation.x;
|
||||
half smoothFactor = saturate(1.0h - factor * factor);
|
||||
smoothFactor = smoothFactor * smoothFactor;
|
||||
#else
|
||||
// We need to smoothly fade attenuation to light range. We start fading linearly at 80% of light range
|
||||
// Therefore:
|
||||
// fadeDistance = (0.8 * 0.8 * lightRangeSq)
|
||||
// smoothFactor = (lightRangeSqr - distanceSqr) / (lightRangeSqr - fadeDistance)
|
||||
// We can rewrite that to fit a MAD by doing
|
||||
// distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
|
||||
// distanceSqr * distanceAttenuation.y + distanceAttenuation.z
|
||||
half smoothFactor = saturate(distanceSqr * distanceAttenuation.x + distanceAttenuation.y);
|
||||
#endif
|
||||
|
||||
return lightAtten * smoothFactor;
|
||||
}
|
||||
|
||||
float ApplyChannelAlpha( float alpha)
|
||||
{
|
||||
return lerp(1.0, alpha, _ComposerMaskMode);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
#define VT_BUFFER_TARGET SV_Target1
|
||||
#define EXTRA_BUFFER_TARGET SV_Target2
|
||||
#else
|
||||
#define EXTRA_BUFFER_TARGET SV_Target1
|
||||
#endif
|
||||
|
||||
uniform sampler2D _RaytracedHardShadow;
|
||||
float4 _RaytracedHardShadow_TexelSize;
|
||||
|
||||
|
||||
|
||||
void Frag(PackedVaryingsToPS packedInput,
|
||||
#ifdef OUTPUT_SPLIT_LIGHTING
|
||||
out float4 outColor : SV_Target0, // outSpecularLighting
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
out float4 outVTFeedback : VT_BUFFER_TARGET,
|
||||
#endif
|
||||
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
|
||||
OUTPUT_SSSBUFFER(outSSSBuffer)
|
||||
#else
|
||||
out float4 outColor : SV_Target0
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
,out float4 outVTFeedback : VT_BUFFER_TARGET
|
||||
#endif
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
|
||||
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
#endif // OUTPUT_SPLIT_LIGHTING
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
, out float outputDepth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
||||
// Init outMotionVector here to solve compiler warning (potentially unitialized variable)
|
||||
// It is init to the value of forceNoMotion (with 2.0)
|
||||
outMotionVec = float4(2.0, 0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
||||
|
||||
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
|
||||
#if defined(PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER) && SHADER_STAGE_FRAGMENT
|
||||
#if (defined(VARYINGS_NEED_PRIMITIVEID) || (SHADERPASS == SHADERPASS_FULL_SCREEN_DEBUG))
|
||||
input.primitiveID = packedInput.primitiveID;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
|
||||
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
||||
#endif
|
||||
|
||||
float4 Set_UV0 = input.texCoord0;
|
||||
UTSData utsData;
|
||||
|
||||
// We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer.
|
||||
input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy;
|
||||
|
||||
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);
|
||||
|
||||
#ifdef _MATERIAL_TYPE_EYE
|
||||
// Must have view Dir to work
|
||||
float2 viewT = TransformObjectToTangent(V, input.tangentToWorld);
|
||||
float2 parallaxOffset = viewT;
|
||||
parallaxOffset.y = -parallaxOffset.y;
|
||||
Set_UV0.xy = clamp(Set_UV0.xy -_EyeParallaxAmount * parallaxOffset, 0, 1);
|
||||
#endif
|
||||
|
||||
#else
|
||||
// Unused
|
||||
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
|
||||
#endif
|
||||
#ifdef _SURFACE_TYPE_TRANSPARENT
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
||||
#else
|
||||
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
||||
#endif
|
||||
SurfaceData surfaceData; // used to get normalWS;
|
||||
BuiltinData builtinData; // used to get lightlayersAndSoOn
|
||||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
|
||||
|
||||
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
float3x3 tangentTransform = input.tangentToWorld;
|
||||
float4 _MainTex_var = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
|
||||
float4 normalLocal = 0;
|
||||
if (_Use_SSSLut)
|
||||
{
|
||||
normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap), _SSSIntensity);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalLocal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
|
||||
}
|
||||
normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale);
|
||||
float3 _NormalMap_var = normalize(mul(normalLocal.rgb, tangentTransform));
|
||||
|
||||
float smoothness = _Smoothness;
|
||||
float coatRoughness = 1;
|
||||
float metallic = _Metallic;
|
||||
float ao = 1.0;
|
||||
float3 specularColor = 0;
|
||||
|
||||
#ifdef _MASKMAP
|
||||
float4 _MaskMap_var = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
|
||||
metallic = _MaskMap_var.x;
|
||||
metallic = lerp(_MetallicRemapMin, _MetallicRemapMax, metallic);
|
||||
ao = _MaskMap_var.y;
|
||||
ao = lerp(_AORemapMin, _AORemapMax, ao);
|
||||
smoothness = _MaskMap_var.w;
|
||||
smoothness = lerp(_SmoothnessRemapMin, _SmoothnessRemapMax, smoothness);
|
||||
#endif
|
||||
|
||||
#ifdef _ANISOTROPYMAP
|
||||
surfaceData.anisotropy = SAMPLE_TEXTURE2D(_AnisotropyMap, sampler_AnisotropyMap, TRANSFORM_TEX(Set_UV0, _AnisotropyMap)).r;
|
||||
#if _PBR_Mode_KK
|
||||
surfaceData.anisotropy += ADD_IDX(_Anisotropy) - 0.5;
|
||||
#else
|
||||
surfaceData.anisotropy *= ADD_IDX(_Anisotropy);
|
||||
#endif
|
||||
#else
|
||||
surfaceData.anisotropy = 1.0;
|
||||
surfaceData.anisotropy *= ADD_IDX(_Anisotropy);
|
||||
#endif
|
||||
|
||||
#ifdef _PBR_Mode_KK
|
||||
metallic = 0.0;
|
||||
coatRoughness = 1 - smoothness;
|
||||
smoothness *=_BSDFContribution;
|
||||
#endif
|
||||
|
||||
#ifdef _PBR_Mode_TOON
|
||||
float3 _SpecTex_var = 1;
|
||||
#ifdef _SPECULARCOLORMAP
|
||||
_SpecTex_var = SAMPLE_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap)).rgb;
|
||||
#endif
|
||||
specularColor = _SpecTex_var * _SpecularColor;
|
||||
#else
|
||||
specularColor = GetSpecularColor(_MainTex_var.rgb * _BaseColor.rgb, metallic);
|
||||
#endif
|
||||
|
||||
surfaceData.baseColor = _MainTex_var.rgb;
|
||||
surfaceData.coatMask = _MainTex_var.a;
|
||||
surfaceData.metallic = metallic;
|
||||
surfaceData.ambientOcclusion = ao;
|
||||
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(dot(_NormalMap_var, V), ao, PerceptualRoughnessToRoughness(1 - smoothness));
|
||||
surfaceData.perceptualSmoothness = smoothness;
|
||||
surfaceData.normalWS = _NormalMap_var;
|
||||
surfaceData.specularColor = specularColor;
|
||||
|
||||
float perceptualRoughness = 1 - surfaceData.perceptualSmoothness;
|
||||
float3 tangentDir = Orthonormalize(tangentTransform[0].rgb, surfaceData.normalWS);
|
||||
float3 bitangentDir = normalize(cross(surfaceData.normalWS, tangentDir));
|
||||
|
||||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); // used to calc shadow
|
||||
bsdfData.coatRoughness = coatRoughness;
|
||||
bsdfData.normalWS = surfaceData.normalWS;
|
||||
bsdfData.ambientOcclusion = surfaceData.ambientOcclusion;
|
||||
bsdfData.specularOcclusion = surfaceData.specularOcclusion;
|
||||
bsdfData.perceptualRoughness = perceptualRoughness;
|
||||
bsdfData.anisotropy = surfaceData.anisotropy;
|
||||
bsdfData.tangentWS = tangentDir;
|
||||
bsdfData.bitangentWS = bitangentDir;
|
||||
|
||||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); // used to calc shadow
|
||||
|
||||
UTSAggregateLighting utsAggregateLighting;
|
||||
ZERO_INITIALIZE(UTSAggregateLighting, utsAggregateLighting);
|
||||
|
||||
UTSLightData customMainLight;
|
||||
customMainLight.shadowValue = 1.0f;
|
||||
//UTSLightData mainPunctualLight;
|
||||
//mainPunctualLight.lightColor = float3(0, 0, 0);
|
||||
|
||||
#define UNITY_PROJ_COORD(a) a
|
||||
#define UNITY_SAMPLE_SCREEN_SHADOW(tex, uv) tex2Dproj( tex, UNITY_PROJ_COORD(uv) ).r
|
||||
float inverseClipping = 0.0;
|
||||
LightLoopContext context;
|
||||
context.shadowContext = InitShadowContext();
|
||||
context.shadowValue = 1;
|
||||
context.sampleReflection = 0.0;
|
||||
#if UNITY_VERSION >= 202120 && UNITY_VERSION < 202320
|
||||
context.splineVisibility = -1;
|
||||
#endif
|
||||
#ifdef APPLY_FOG_ON_SKY_REFLECTIONS
|
||||
context.positionWS = posInput.positionWS;
|
||||
#endif
|
||||
|
||||
// With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
|
||||
// This is required because there is only one list of lights generated on the CPU. Shadows are also generated once and shared between the instanced views.
|
||||
ApplyCameraRelativeXR(posInput.positionWS);
|
||||
|
||||
// Initialize the contactShadow and contactShadowFade fields
|
||||
InitContactShadow(posInput, context);
|
||||
|
||||
float3 i_normalDir = surfaceData.normalWS;
|
||||
|
||||
int mainLightIndex = -1;
|
||||
float channelAlpha = 0.0f;
|
||||
float3 finalColor = float3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
|
||||
{
|
||||
// because of light culling or light layer, we can not adopt this
|
||||
// https://unity.slack.com/archives/C06V7HDDW/p1580959470180800
|
||||
// int mainLightIndex = _DirectionalShadowIndex;
|
||||
mainLightIndex = GetUtsMainLightIndex(builtinData);
|
||||
DirectionalLightData lightData;
|
||||
ZERO_INITIALIZE(DirectionalLightData, lightData);
|
||||
if (mainLightIndex >= 0)
|
||||
{
|
||||
lightData = _DirectionalLightDatas[mainLightIndex];
|
||||
}
|
||||
|
||||
float3 lightColor = ApplyCurrentExposureMultiplier(lightData.color);
|
||||
float3 lightDirection = -lightData.forward;
|
||||
|
||||
#ifndef LIGHT_EVALUATION_NO_COOKIE
|
||||
if (lightData.cookieMode != COOKIEMODE_NONE)
|
||||
{
|
||||
float3 lightToSample = input.positionRWS - lightData.positionRWS;
|
||||
lightColor *= EvaluateCookie_Directional(context, lightData, lightToSample);
|
||||
}
|
||||
#endif
|
||||
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightDirection = lightDirection;
|
||||
utsLightData.lightColor = lightColor;
|
||||
utsLightData.diffuseDimmer = lightData.diffuseDimmer;
|
||||
utsLightData.specularDimmer = lightData.specularDimmer;
|
||||
utsLightData.shadowTint = lightData.shadowTint;
|
||||
utsLightData.penumbraTint = lightData.penumbraTint;
|
||||
|
||||
customMainLight = utsLightData;
|
||||
|
||||
// Evaluate sun shadows.
|
||||
if (_DirectionalShadowIndex >= 0)
|
||||
{
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
#if defined(SCREEN_SPACE_SHADOWS_ON) && !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
if (UtsUseScreenSpaceShadow(light, bsdfData.normalWS))
|
||||
{
|
||||
// HDRP Contact Shadow
|
||||
context.shadowValue = GetScreenSpaceColorShadow(posInput, light.screenSpaceShadowIndex).SHADOW_TYPE_SWIZZLE;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// TODO: this will cause us to load from the normal buffer first. Does this cause a performance problem?
|
||||
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
|
||||
IsNonZeroBSDF(V, L, preLightData, bsdfData) &&
|
||||
!ShouldEvaluateThickObjectTransmission(V, L, preLightData, bsdfData, light.shadowIndex))
|
||||
{
|
||||
|
||||
#if defined(UTS_USE_RAYTRACING_SHADOW)
|
||||
{
|
||||
/*
|
||||
struct PositionInputs
|
||||
{
|
||||
float3 positionWS; // World space position (could be camera-relative)
|
||||
float2 positionNDC; // Normalized screen coordinates within the viewport : [0, 1) (with the half-pixel offset)
|
||||
uint2 positionSS; // Screen space pixel coordinates : [0, NumPixels)
|
||||
uint2 tileCoord; // Screen tile coordinates : [0, NumTiles)
|
||||
float deviceDepth; // Depth from the depth buffer : [0, 1] (typically reversed)
|
||||
float linearDepth; // View space Z coordinate : [Near, Far]
|
||||
};
|
||||
float4 size = _RaytracedHardShadow_TexelSize;
|
||||
*/
|
||||
|
||||
float r = UNITY_SAMPLE_SCREEN_SHADOW(_RaytracedHardShadow, float4(posInput.positionNDC.xy, lightDirection * _ShadowBias, 1));
|
||||
context.shadowValue = r;
|
||||
}
|
||||
#else
|
||||
{
|
||||
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
|
||||
posInput.positionSS, posInput.positionWS + lightDirection * _ShadowBias, GetNormalForShadowBias(bsdfData),
|
||||
light.shadowIndex, L);
|
||||
|
||||
}
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
|
||||
|
||||
}
|
||||
#if defined (UTS_USE_RAYTRACING_SHADOW)
|
||||
else
|
||||
{
|
||||
float r = UNITY_SAMPLE_SCREEN_SHADOW(_RaytracedHardShadow, float4(posInput.positionNDC.xy, lightDirection * _ShadowBias, 1));
|
||||
context.shadowValue = r;
|
||||
}
|
||||
#endif // UTS_USE_RAYTRACING_SHADOW
|
||||
}
|
||||
|
||||
context.shadowValue = lerp(1, context.shadowValue, lightData.shadowDimmer);
|
||||
customMainLight.shadowValue = context.shadowValue;
|
||||
}
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
if (_DirectionalShadowIndex >= 0)
|
||||
finalColor = UTS_SelfShdowMainLight(context, input, _DirectionalShadowIndex);
|
||||
#else
|
||||
UTS_MainLight(context, input, utsLightData, surfaceData, bsdfData, inverseClipping, channelAlpha, utsData, utsAggregateLighting);
|
||||
#endif
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
float notDirectional = 0.0f;
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[i].color);
|
||||
utsLightData.lightDirection = -_DirectionalLightDatas[i].forward;
|
||||
utsLightData.diffuseDimmer = _DirectionalLightDatas[i].diffuseDimmer;
|
||||
utsLightData.specularDimmer = _DirectionalLightDatas[i].specularDimmer;
|
||||
utsLightData.shadowTint = _DirectionalLightDatas[i].shadowTint;
|
||||
utsLightData.penumbraTint = _DirectionalLightDatas[i].penumbraTint;
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, 0, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//#undef EVALUATE_BSDF_ENV
|
||||
//#undef EVALUATE_BSDF_ENV_SKY
|
||||
|
||||
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.
|
||||
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);
|
||||
const float notDirectional = 1.0f;
|
||||
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightColor = additionalLightColor;
|
||||
utsLightData.lightDirection = lightDirection;
|
||||
utsLightData.diffuseDimmer = s_lightData.diffuseDimmer * lightColor.a;
|
||||
utsLightData.specularDimmer = s_lightData.specularDimmer * lightColor.a;
|
||||
utsLightData.shadowTint = s_lightData.shadowTint;
|
||||
utsLightData.penumbraTint = s_lightData.penumbraTint;
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
posInput.positionWS = posInput.positionWS + lightDirection * _ShadowBias;
|
||||
context.shadowValue = EvaluateShadow_Punctual(context, posInput, s_lightData, builtinData, GetNormalForShadowBias(bsdfData), lightDirection, distances);
|
||||
posInput.positionWS = posInput.positionWS - lightDirection * _ShadowBias;
|
||||
|
||||
if (length(utsLightData.lightColor) >= length(customMainLight.lightColor))
|
||||
{
|
||||
float3 lightDirectionToObject;
|
||||
float4 distancesToObject; // {d, d^2, 1/d, d_proj}
|
||||
float3 objectCenter = (TransformObjectToWorld(float3(0, 0, 0)));
|
||||
GetPunctualLightVectors(objectCenter, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float4 lightColorToObject = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirectionToObject, distancesToObject);
|
||||
float3 additionalLightColorToObject = ApplyCurrentExposureMultiplier(lightColorToObject.rgb) * lightColorToObject.a;
|
||||
|
||||
customMainLight = utsLightData;
|
||||
customMainLight.lightColor = additionalLightColorToObject;
|
||||
customMainLight.lightDirection = lightDirectionToObject;
|
||||
customMainLight.shadowValue = context.shadowValue;
|
||||
}
|
||||
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, s_lightData.lightType, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//v.2.0.7
|
||||
|
||||
#if SHADEROPTIONS_AREA_LIGHTS
|
||||
if (featureFlags & LIGHTFEATUREFLAGS_AREA)
|
||||
{
|
||||
uint lightCount, lightStart;
|
||||
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
GetCountAndStart(posInput, LIGHTCATEGORY_AREA, lightStart, lightCount);
|
||||
#else
|
||||
lightCount = _AreaLightCount;
|
||||
lightStart = _PunctualLightCount;
|
||||
#endif
|
||||
|
||||
if (lightCount > 0)
|
||||
{
|
||||
uint i = 0;
|
||||
uint last = lightCount - 1;
|
||||
LightData s_lightData = FetchLight(lightStart, i);
|
||||
|
||||
[loop] // vulkan shader compiler can not unroll.
|
||||
while (i <= last)
|
||||
{
|
||||
if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
float3 lightDirection = -s_lightData.forward;
|
||||
float3 areaLightColor = ApplyCurrentExposureMultiplier(s_lightData.color.rgb);
|
||||
const float notDirectional = 1.0f;
|
||||
|
||||
UTSLightData utsLightData;
|
||||
utsLightData.lightColor = areaLightColor;
|
||||
utsLightData.lightDirection = lightDirection;
|
||||
utsLightData.diffuseDimmer = s_lightData.diffuseDimmer;
|
||||
utsLightData.specularDimmer = s_lightData.specularDimmer;
|
||||
utsLightData.shadowTint = s_lightData.shadowTint;
|
||||
utsLightData.penumbraTint = s_lightData.penumbraTint;
|
||||
|
||||
bool isRectLight = s_lightData.lightType == GPULIGHTTYPE_RECTANGLE;
|
||||
|
||||
float3 unL = s_lightData.positionRWS - posInput.positionWS;
|
||||
utsLightData.lightDirection = normalize(unL);
|
||||
float3 center = mul(preLightData.orthoBasisViewNormal, unL);
|
||||
float3 right = mul(preLightData.orthoBasisViewNormal, s_lightData.right);
|
||||
float3 up = mul(preLightData.orthoBasisViewNormal, s_lightData.up);
|
||||
|
||||
float halfWidth = s_lightData.size.x * 0.5;
|
||||
float halfHeight = s_lightData.size.y * 0.5;
|
||||
|
||||
float intensity = PillowWindowing(unL, s_lightData.right, s_lightData.up, halfWidth, halfHeight, s_lightData.rangeAttenuationScale, s_lightData.rangeAttenuationBias);
|
||||
|
||||
// Make sure the light is front-facing (and has a non-zero effective area).
|
||||
intensity *= (isRectLight && dot(unL, s_lightData.forward) >= 0) ? 0 : 1;
|
||||
|
||||
float4 ltcValue;
|
||||
|
||||
// Diffuse
|
||||
ltcValue = UTS_EvaluateLTC_Area(isRectLight, center, right, up, halfWidth, halfHeight, transpose(preLightData.ltcTransformDiffuse), /*bsdfData.perceptualRoughness*/ 1.0f,
|
||||
true, s_lightData.cookieMode, s_lightData.cookieScaleOffset);
|
||||
utsLightData.diffuseDimmer *= ltcValue.a * intensity;
|
||||
utsLightData.lightColor *= ltcValue.rgb;
|
||||
|
||||
// Specular
|
||||
ltcValue = UTS_EvaluateLTC_Area(isRectLight, center, right, up, halfWidth, halfHeight, transpose(preLightData.ltcTransformSpecular[0]), bsdfData.perceptualRoughness,
|
||||
false, s_lightData.cookieMode, s_lightData.cookieScaleOffset);
|
||||
utsLightData.specularDimmer *= ltcValue.a * intensity;
|
||||
|
||||
if (isRectLight)
|
||||
{
|
||||
//Evaluate the shadow part
|
||||
float shadow;
|
||||
posInput.positionWS = posInput.positionWS + utsLightData.lightDirection * _ShadowBias;
|
||||
context.shadowValue = EvaluateShadow_RectArea(context, posInput, s_lightData, builtinData, GetNormalForShadowBias(bsdfData), normalize(s_lightData.positionRWS), length(s_lightData.positionRWS));
|
||||
posInput.positionWS = posInput.positionWS - lightDirection * _ShadowBias;
|
||||
}
|
||||
|
||||
#if defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#else
|
||||
UTS_OtherLights(context, input, utsLightData, surfaceData, bsdfData, s_lightData.lightType, i_normalDir, notDirectional, channelAlpha, utsAggregateLighting);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
s_lightData = FetchLight(lightStart, min(++i, last));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SHADEROPTIONS_AREA_LIGHTS
|
||||
|
||||
#ifdef _EMISSIVE_SIMPLE
|
||||
float4 _Emissive_Tex_var = tex2D(_Emissive_Tex, TRANSFORM_TEX(Set_UV0, _Emissive_Tex));
|
||||
float emissiveMask = _Emissive_Tex_var.a;
|
||||
emissive = _Emissive_Tex_var.rgb * _Emissive_Color.rgb * emissiveMask;
|
||||
#elif _EMISSIVE_ANIMATION
|
||||
//v.2.0.7 Calculation View Coord UV for Scroll
|
||||
float3 viewNormal_Emissive = (mul(UNITY_MATRIX_V, float4(i_normalDir, 0))).xyz;
|
||||
float3 NormalBlend_Emissive_Detail = viewNormal_Emissive * float3(-1, -1, 1);
|
||||
float3 NormalBlend_Emissive_Base = (mul(UNITY_MATRIX_V, float4(utsData.viewDirection, 0)).xyz * float3(-1, -1, 1)) + float3(0, 0, 1);
|
||||
float3 noSknewViewNormal_Emissive = NormalBlend_Emissive_Base * dot(NormalBlend_Emissive_Base, NormalBlend_Emissive_Detail) / NormalBlend_Emissive_Base.z - NormalBlend_Emissive_Detail;
|
||||
float2 _ViewNormalAsEmissiveUV = noSknewViewNormal_Emissive.xy * 0.5 + 0.5;
|
||||
float2 _ViewCoord_UV = RotateUV(_ViewNormalAsEmissiveUV, -(utsData.cameraDir * utsData.cameraRoll), float2(0.5, 0.5), 1.0);
|
||||
//Invert if it's "inside the mirror".
|
||||
if (utsData.signMirror < 0) {
|
||||
_ViewCoord_UV.x = 1 - _ViewCoord_UV.x;
|
||||
}
|
||||
else {
|
||||
_ViewCoord_UV = _ViewCoord_UV;
|
||||
}
|
||||
float2 emissive_uv = lerp(Set_UV0, _ViewCoord_UV, _Is_ViewCoord_Scroll);
|
||||
//
|
||||
float4 _time_var = _Time;
|
||||
float _base_Speed_var = (_time_var.g * _Base_Speed);
|
||||
float _Is_PingPong_Base_var = lerp(_base_Speed_var, sin(_base_Speed_var), _Is_PingPong_Base);
|
||||
float2 scrolledUV = emissive_uv + float2(_Scroll_EmissiveU, _Scroll_EmissiveV) * _Is_PingPong_Base_var;
|
||||
float rotateVelocity = _Rotate_EmissiveUV * 3.141592654;
|
||||
float2 _rotate_EmissiveUV_var = RotateUV(scrolledUV, rotateVelocity, float2(0.5, 0.5), _Is_PingPong_Base_var);
|
||||
float4 _Emissive_Tex_var = tex2D(_Emissive_Tex, TRANSFORM_TEX(Set_UV0, _Emissive_Tex));
|
||||
float emissiveMask = _Emissive_Tex_var.a;
|
||||
_Emissive_Tex_var = tex2D(_Emissive_Tex, TRANSFORM_TEX(_rotate_EmissiveUV_var, _Emissive_Tex));
|
||||
float _colorShift_Speed_var = 1.0 - cos(_time_var.g * _ColorShift_Speed);
|
||||
float viewShift_var = smoothstep(0.0, 1.0, max(0, dot(utsData.normalDirection, utsData.viewDirection)));
|
||||
float4 colorShift_Color = lerp(_Emissive_Color, lerp(_Emissive_Color, _ColorShift, _colorShift_Speed_var), _Is_ColorShift);
|
||||
float4 viewShift_Color = lerp(_ViewShift, colorShift_Color, viewShift_var);
|
||||
float4 emissive_Color = lerp(colorShift_Color, viewShift_Color, _Is_ViewShift);
|
||||
emissive = emissive_Color.rgb * _Emissive_Tex_var.rgb * emissiveMask;
|
||||
|
||||
//
|
||||
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
|
||||
#endif
|
||||
|
||||
// We directly calculate custome main light during the light loop in upper code to avoid extra calculation
|
||||
//customMainLight = GetCustomMainLightData(builtinData, mainPunctualLight);
|
||||
|
||||
#if _SDFShadow || (_RECEIVE_HAIR_SHADOW && ENABLE_UTS_HAIR_SHAOW)
|
||||
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, customMainLight.lightDirection.xyz, any(customMainLight.lightDirection.xyz)));
|
||||
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
|
||||
float3 originalLightColor = customMainLight.lightColor.rgb;
|
||||
|
||||
originalLightColor = lerp(originalLightColor, clamp(originalLightColor, ConvertFromEV100(_ToonEvAdjustmentValueMin ), ConvertFromEV100(_ToonEvAdjustmentValueMax)), _ToonEvAdjustmentCurve) * _Light_Intensity_Multiplier;
|
||||
float3 lightColor = lerp(max(defaultLightColor, originalLightColor), max(defaultLightColor, saturate(originalLightColor)), max(_Is_Filter_LightColor, _ToonLightHiCutFilter));
|
||||
|
||||
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _MainTex_var, _Use_BaseAs1st);
|
||||
float3 _1st_Shade_var = lerp((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb), ((_1st_ShadeMap_var.rgb * _1st_ShadeColor.rgb) * lightColor), _Is_LightColor_1st_Shade);
|
||||
|
||||
float systemShadowValue = lerp(1.0f, saturate(customMainLight.shadowValue * 2.0f), _Set_SystemShadowsToBase);
|
||||
#endif
|
||||
|
||||
#ifdef _SDFShadow
|
||||
// modified by Suomi @ 20230902 - SDFResult is used to sample SDF texture on the correct side
|
||||
|
||||
float angle;
|
||||
bool rightside;
|
||||
float2 SDF_UV = TRANSFORM_TEX(Set_UV0, _BaseColorMap);
|
||||
float4 sdfRes = SDFResult(rightside, angle, customMainLight.lightDirection, SDF_UV);
|
||||
float sdfShadowValue = 1.0f - SDFMask(angle, sdfRes.r);
|
||||
|
||||
utsAggregateLighting.directDiffuse = lerp(_1st_Shade_var, bsdfData.diffuseColor * _BaseColor.rgb * lightColor, sdfShadowValue * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular = lerp(0, utsAggregateLighting.directSpecular, sdfShadowValue * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular += _SDFNoseHighlightCoef * SDFNoseHighlight(angle, sdfRes.g, rightside, SDF_UV) * lightColor;
|
||||
#endif
|
||||
|
||||
#if _RECEIVE_HAIR_SHADOW && ENABLE_UTS_HAIR_SHAOW
|
||||
// Push the face fragment view space position towards the light for a little bit
|
||||
float hairShadowOpacity = saturate(Remap(length(posInput.positionWS), float2(_HairShadowFadeOutDistance, _HairShadowFadeInDistance), float2(0, 1)));
|
||||
|
||||
float3 viewLightDir = TransformWorldToViewDir(customMainLight.lightDirection); // / posInput.deviceDepth; when linearDepth grows large, the movement amount should be lower since we are getting further from the face.
|
||||
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
float shadowLengthY = _HairShadowDistance * 5.0 * max(0.5, posInput.linearDepth * _HairShadowDistanceScaleFactor) / posInput.linearDepth;
|
||||
float2 shadowLength = float2(shadowLengthY * 2.0f, shadowLengthY);
|
||||
|
||||
float3 camDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
float camDirFactor = 1 - smoothstep(0.1, 0.9, camDirOS.y);
|
||||
shadowLength.y *= camDirFactor;
|
||||
|
||||
float2 samplingPoint = (input.positionSS.xy + shadowLength * viewLightDir.xy * (_ScreenSize.xy / float2 (1920.0f, 1080.0f))) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions.
|
||||
|
||||
// Then sample the hair buffer, to see if the fragment lands in shadow.
|
||||
float2 scaledUVs = samplingPoint * _HairShadowRTHandleScale; // We have to including the scaling factor for our shadow map since we are not going to allocate new texture if the rendering resolution changed.
|
||||
float hairDepth = SAMPLE_TEXTURE2D(_HairShadowTex, s_trilinear_clamp_sampler, scaledUVs).r;
|
||||
float depthCorrect = posInput.deviceDepth <= hairDepth + _HairShadowDepthBias ? 1 : 0; // Hair < Face means Hair are closer to camera
|
||||
// Note that we have LinearEyeDepth in the buffer. A comparison of depth is needed so that we don't project the shadow of hair behind the face.
|
||||
float hairShadow = lerp(0,hairShadowOpacity,depthCorrect);
|
||||
|
||||
utsAggregateLighting.directDiffuse = lerp(utsAggregateLighting.directDiffuse, _1st_Shade_var, hairShadow * systemShadowValue);
|
||||
utsAggregateLighting.directSpecular = lerp(utsAggregateLighting.directSpecular, 0, hairShadow * systemShadowValue);
|
||||
#endif
|
||||
|
||||
// Ambient
|
||||
utsAggregateLighting.indirectDiffuse = EvaluateIndirectDiffuse(posInput, bsdfData, V) * _ID_Intensity;
|
||||
utsAggregateLighting.indirectSpecular = EvaluateIndirectSpecular(context, posInput, preLightData, bsdfData, surfaceData, builtinData, V) * _IR_Intensity;
|
||||
|
||||
float3 finalColorWoEmissive = AccumulateUTSAggregateLighting(utsAggregateLighting);
|
||||
|
||||
finalColorWoEmissive = GetExposureAdjustedColor(finalColorWoEmissive);
|
||||
finalColorWoEmissive = ApplyCompensation(finalColorWoEmissive);
|
||||
|
||||
finalColor = finalColorWoEmissive + emissive;
|
||||
|
||||
#ifdef _IS_TRANSCLIPPING_OFF
|
||||
|
||||
outColor = float4(finalColor, 1 * ApplyChannelAlpha(channelAlpha));
|
||||
|
||||
#elif _IS_TRANSCLIPPING_ON
|
||||
|
||||
float Set_Opacity = saturate((inverseClipping + _Tweak_transparency));
|
||||
|
||||
outColor = EvaluateAtmosphericScattering(posInput, V, float4(finalColor, 1));
|
||||
outColor = float4(outColor.rgb, Set_Opacity * ApplyChannelAlpha(channelAlpha));
|
||||
#endif
|
||||
|
||||
#if _MATERIAL_TYPE_FRONT_HAIR && ENABLE_UTS_HAIR_BLENDING
|
||||
float2 screenUV = posInput.positionNDC * _HairBlendingRTHandleScale.xy;
|
||||
float4 hairBlendingMap = SAMPLE_TEXTURE2D(_HairBlendingTex, s_trilinear_clamp_sampler, screenUV);
|
||||
outColor.rgb = lerp(outColor.rgb, hairBlendingMap.rgb, hairBlendingMap.a * _HairBlendingFactor);
|
||||
#endif
|
||||
|
||||
#if UTS_DEBUG_SHADOWMAP || UTS_DEBUG_SELFSHADOW
|
||||
outColor.rgb = 1;
|
||||
#ifdef UTS_DEBUG_SELFSHADOW
|
||||
outColor.rgb = min(finalColor, outColor.rgb);
|
||||
#endif
|
||||
|
||||
#ifdef UTS_DEBUG_SHADOWMAP
|
||||
#ifdef UTS_DEBUG_SHADOWMAP_BINALIZATION
|
||||
outColor.rgb = min(context.shadowValue < 0.9f ? clamp(context.shadowValue - 0.2, 0.0, 0.9) : 1.0f, outColor.rgb);
|
||||
#else
|
||||
outColor.rgb = min(context.shadowValue, outColor.rgb);
|
||||
#endif
|
||||
#endif // ifdef UTS_DEBUG_SHADOWMAP
|
||||
#endif // defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
|
||||
|
||||
#ifdef _DEPTHOFFSET_ON
|
||||
outputDepth = posInput.deviceDepth;
|
||||
#endif
|
||||
#ifdef UNITY_VIRTUAL_TEXTURING
|
||||
|
||||
outVTFeedback = builtinData.vtPackedFeedback;
|
||||
#endif
|
||||
|
||||
//outColor.rgb = customMainLight.shadowValue;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d797988f43f630944b3b0de4c7cfab37
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
340
Runtime/Shaders/Includes/Deprecated/ShadingMainLight.hlsl
Normal file
340
Runtime/Shaders/Includes/Deprecated/ShadingMainLight.hlsl
Normal 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
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b18b203f15b921a47a7cf30e26007d1a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
258
Runtime/Shaders/Includes/Deprecated/ShadingOtherLight.hlsl
Normal file
258
Runtime/Shaders/Includes/Deprecated/ShadingOtherLight.hlsl
Normal 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
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0d6ddf3fb34bef48b91a2fb9cae8cb1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
220
Runtime/Shaders/Includes/Deprecated/UtsAreaLight.hlsl
Normal file
220
Runtime/Shaders/Includes/Deprecated/UtsAreaLight.hlsl
Normal 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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afada69a218dd594ea0f17e7c639c533
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
231
Runtime/Shaders/Includes/Deprecated/UtsEnvLight.hlsl
Normal file
231
Runtime/Shaders/Includes/Deprecated/UtsEnvLight.hlsl
Normal 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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52ab7245a70fe6a4e80663ca80f9811b
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d53a3bfa05741064d9b4d15154890a04
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user