Added new Shadow SSS Lut;
Fixed the issue that SSGI and SSAO weight not works properly;
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
#pragma kernel CSMain
|
#pragma kernel SkinLut
|
||||||
|
#pragma kernel ShadowLut
|
||||||
|
|
||||||
#pragma multi_compile_local _ _PRODUCTION
|
#pragma multi_compile_local _ _PRODUCTION
|
||||||
|
|
||||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||||
|
|
||||||
|
#define _PROFILE_WIDTH 8.166
|
||||||
|
|
||||||
float _ScatterRadius;
|
float _ScatterRadius;
|
||||||
|
float _PositionShift;
|
||||||
float _Intensity;
|
float _Intensity;
|
||||||
int _SampleCount;
|
int _SampleCount;
|
||||||
int _ApplyTonemap;
|
int _ApplyTonemap;
|
||||||
@@ -51,12 +56,11 @@ float3 RadianceScatter(float r)
|
|||||||
|
|
||||||
float3 IntegrateDiffuseScattering_Ring(float theta, float r)
|
float3 IntegrateDiffuseScattering_Ring(float theta, float r)
|
||||||
{
|
{
|
||||||
float x = -HALF_PI;
|
|
||||||
float increment = PI / _SampleCount;
|
|
||||||
|
|
||||||
float3 totalScatter = 0;
|
float3 totalScatter = 0;
|
||||||
float3 totalWeight = 0;
|
float3 totalWeight = 0;
|
||||||
|
float increment = PI / _SampleCount;
|
||||||
|
|
||||||
|
float x = -HALF_PI;
|
||||||
while (x < HALF_PI)
|
while (x < HALF_PI)
|
||||||
{
|
{
|
||||||
float diffuse = saturate(cos(theta + x));
|
float diffuse = saturate(cos(theta + x));
|
||||||
@@ -72,13 +76,42 @@ float3 IntegrateDiffuseScattering_Ring(float theta, float r)
|
|||||||
return totalScatter / totalWeight;
|
return totalScatter / totalWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float newPenumbra(float pos, float penumbraWidth)
|
||||||
|
{
|
||||||
|
return saturate((pos * penumbraWidth - _PROFILE_WIDTH) / (penumbraWidth - _PROFILE_WIDTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 IntegrateShadowScattering(float penumbraLocation, float penumbraWidth)
|
||||||
|
{
|
||||||
|
float3 totalScatter = 0;
|
||||||
|
float3 totalWeights = 0;
|
||||||
|
float increment = (_PROFILE_WIDTH * 2) / _SampleCount;
|
||||||
|
|
||||||
|
penumbraWidth = max(penumbraWidth, _PROFILE_WIDTH + 1e-5);
|
||||||
|
|
||||||
|
float x = -_PROFILE_WIDTH;
|
||||||
|
while (x <= _PROFILE_WIDTH)
|
||||||
|
{
|
||||||
|
float light = newPenumbra(penumbraLocation + x / penumbraWidth, penumbraWidth);
|
||||||
|
float distance = abs(x);
|
||||||
|
float3 weights = RadianceScatter(distance);
|
||||||
|
|
||||||
|
totalWeights += weights;
|
||||||
|
totalScatter += light * weights;
|
||||||
|
|
||||||
|
x += increment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalScatter / totalWeights;
|
||||||
|
}
|
||||||
|
|
||||||
float3 FilmicTonemap(float3 color)
|
float3 FilmicTonemap(float3 color)
|
||||||
{
|
{
|
||||||
return (color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06);
|
return (color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06);
|
||||||
}
|
}
|
||||||
|
|
||||||
[numthreads(8,8,1)]
|
[numthreads(8,8,1)]
|
||||||
void CSMain (uint3 id : SV_DispatchThreadID)
|
void SkinLut (uint3 id : SV_DispatchThreadID)
|
||||||
{
|
{
|
||||||
if (id.x > _TextureSize || id.y > _TextureSize)
|
if (id.x > _TextureSize || id.y > _TextureSize)
|
||||||
{
|
{
|
||||||
@@ -90,7 +123,7 @@ void CSMain (uint3 id : SV_DispatchThreadID)
|
|||||||
uv.y = 1.0 - uv.y;
|
uv.y = 1.0 - uv.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float theta = acos(uv.x * 2.0 - 1.0);
|
float theta = acos((uv.x * 2.0 - 1.0)) + _PositionShift;
|
||||||
float r = rcp(max(uv.y, 0.001) * _ScatterRadius);
|
float r = rcp(max(uv.y, 0.001) * _ScatterRadius);
|
||||||
|
|
||||||
float3 scatter = IntegrateDiffuseScattering_Ring(theta, r) * _Intensity;
|
float3 scatter = IntegrateDiffuseScattering_Ring(theta, r) * _Intensity;
|
||||||
@@ -99,5 +132,31 @@ void CSMain (uint3 id : SV_DispatchThreadID)
|
|||||||
scatter = FilmicTonemap(scatter);
|
scatter = FilmicTonemap(scatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_SSSLut[id.xy] = float4(scatter, 1.0);
|
||||||
|
//_SSSLut[id.xy] = theta;
|
||||||
|
}
|
||||||
|
|
||||||
|
[numthreads(8, 8, 1)]
|
||||||
|
void ShadowLut(uint3 id : SV_DispatchThreadID)
|
||||||
|
{
|
||||||
|
if (id.x > _TextureSize || id.y > _TextureSize)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float2 uv = id.xy / float2(_TextureSize, _TextureSize);
|
||||||
|
#if UNITY_UV_STARTS_AT_TOP && _PRODUCTION
|
||||||
|
uv.y = 1.0 - uv.y;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float penumbraLocation = uv.x + _PositionShift;
|
||||||
|
float penumbraWidth = rcp(max(uv.y, 0.001) * _ScatterRadius);
|
||||||
|
|
||||||
|
float3 scatter = IntegrateShadowScattering(penumbraLocation, penumbraWidth) * _Intensity;
|
||||||
|
if (_ApplyTonemap == 1)
|
||||||
|
{
|
||||||
|
scatter = FilmicTonemap(scatter);
|
||||||
|
}
|
||||||
|
|
||||||
_SSSLut[id.xy] = float4(scatter, 1.0);
|
_SSSLut[id.xy] = float4(scatter, 1.0);
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,9 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
private RenderTexture _previewTexture;
|
private RenderTexture _previewTexture;
|
||||||
private RenderTextureDescriptor _previewDescriptor;
|
private RenderTextureDescriptor _previewDescriptor;
|
||||||
|
|
||||||
|
public bool isShadowLut;
|
||||||
public float scatterRadius = 1.0f;
|
public float scatterRadius = 1.0f;
|
||||||
|
public float positionShift = 0.0f;
|
||||||
public float intensity = 1.0f;
|
public float intensity = 1.0f;
|
||||||
public Quality sampleCount = Quality.Low;
|
public Quality sampleCount = Quality.Low;
|
||||||
public bool applyTonemap = true;
|
public bool applyTonemap = true;
|
||||||
@@ -78,7 +80,10 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var kernelIndex = isShadowLut ? 1 : 0;
|
||||||
|
|
||||||
_bakerShader.SetFloat("_ScatterRadius", scatterRadius);
|
_bakerShader.SetFloat("_ScatterRadius", scatterRadius);
|
||||||
|
_bakerShader.SetFloat("_PositionShift", positionShift);
|
||||||
_bakerShader.SetFloat("_Intensity", intensity);
|
_bakerShader.SetFloat("_Intensity", intensity);
|
||||||
_bakerShader.SetInt("_SampleCount", (int)sampleCount);
|
_bakerShader.SetInt("_SampleCount", (int)sampleCount);
|
||||||
_bakerShader.SetInt("_ApplyTonemap", applyTonemap ? 1 : 0);
|
_bakerShader.SetInt("_ApplyTonemap", applyTonemap ? 1 : 0);
|
||||||
@@ -86,13 +91,13 @@ namespace Misaki.HdrpToon.Editor
|
|||||||
|
|
||||||
_bakerShader.SetKeyword(new LocalKeyword(_bakerShader, "_PRODUCTION"), production);
|
_bakerShader.SetKeyword(new LocalKeyword(_bakerShader, "_PRODUCTION"), production);
|
||||||
|
|
||||||
_bakerShader.SetTexture(0, "_SSSLut", texture);
|
_bakerShader.SetTexture(kernelIndex, "_SSSLut", texture);
|
||||||
|
|
||||||
const int groupSizeX = 8;
|
const int groupSizeX = 8;
|
||||||
const int groupSizeY = 8;
|
const int groupSizeY = 8;
|
||||||
var threadGroupX = (textureSize + (groupSizeX - 1)) / groupSizeX;
|
var threadGroupX = (textureSize + (groupSizeX - 1)) / groupSizeX;
|
||||||
var threadGroupY = (textureSize + (groupSizeY - 1)) / groupSizeY;
|
var threadGroupY = (textureSize + (groupSizeY - 1)) / groupSizeY;
|
||||||
_bakerShader.Dispatch(0, threadGroupX, threadGroupY, 1);
|
_bakerShader.Dispatch(kernelIndex, threadGroupX, threadGroupY, 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,21 @@
|
|||||||
<engine:VisualElement data-source-type="Misaki.HdrpToon.Editor.SSSLutBakerView, Misaki.HdrpToon.Editor" style="flex-grow: 1; padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px;">
|
<engine:VisualElement data-source-type="Misaki.HdrpToon.Editor.SSSLutBakerView, Misaki.HdrpToon.Editor" style="flex-grow: 1; padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px;">
|
||||||
<engine:Label text="SSS Lut Baker" style="font-size: 18px; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; margin-top: 12px; margin-bottom: 8px; margin-left: 4px; margin-right: 6px; -unity-font-style: bold;" />
|
<engine:Label text="SSS Lut Baker" style="font-size: 18px; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; margin-top: 12px; margin-bottom: 8px; margin-left: 4px; margin-right: 6px; -unity-font-style: bold;" />
|
||||||
<engine:Label text="Parameters:" style="-unity-font-style: bold; margin-top: 12px; margin-bottom: 4px; margin-right: 2px; margin-left: 2px;" />
|
<engine:Label text="Parameters:" style="-unity-font-style: bold; margin-top: 12px; margin-bottom: 4px; margin-right: 2px; margin-left: 2px;" />
|
||||||
|
<engine:DropdownField label="Lut Type" choices="Skin,Shadow" index="0">
|
||||||
|
<Bindings>
|
||||||
|
<engine:DataBinding property="index" data-source-path="isShadowLut" binding-mode="TwoWay" />
|
||||||
|
</Bindings>
|
||||||
|
</engine:DropdownField>
|
||||||
<engine:FloatField label="Scatter Radius" value="1">
|
<engine:FloatField label="Scatter Radius" value="1">
|
||||||
<Bindings>
|
<Bindings>
|
||||||
<engine:DataBinding property="value" data-source-path="scatterRadius" binding-mode="TwoWay" />
|
<engine:DataBinding property="value" data-source-path="scatterRadius" binding-mode="TwoWay" />
|
||||||
</Bindings>
|
</Bindings>
|
||||||
</engine:FloatField>
|
</engine:FloatField>
|
||||||
|
<engine:Slider label="Position Shift" value="0.0" low-value="-1" high-value="1" page-size="0.1" show-input-field="true">
|
||||||
|
<Bindings>
|
||||||
|
<engine:DataBinding property="value" data-source-path="positionShift" binding-mode="TwoWay" />
|
||||||
|
</Bindings>
|
||||||
|
</engine:Slider>
|
||||||
<engine:Slider label="Intensity" value="1" high-value="10" show-input-field="true" page-size="0.1">
|
<engine:Slider label="Intensity" value="1" high-value="10" show-input-field="true" page-size="0.1">
|
||||||
<Bindings>
|
<Bindings>
|
||||||
<engine:DataBinding property="value" data-source-path="intensity" binding-mode="TwoWay" />
|
<engine:DataBinding property="value" data-source-path="intensity" binding-mode="TwoWay" />
|
||||||
|
|||||||
@@ -1000,7 +1000,9 @@ Shader "HDRP/Toon"
|
|||||||
#pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
|
#pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
|
||||||
|
|
||||||
#pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
|
#pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
|
||||||
//Probe volume
|
//#pragma multi_compile_fragment PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
|
||||||
|
//#pragma multi_compile_fragment DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH
|
||||||
|
//#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH
|
||||||
#pragma multi_compile PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
#pragma multi_compile PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
||||||
|
|
||||||
#define SHADERPASS SHADERPASS_FORWARD
|
#define SHADERPASS SHADERPASS_FORWARD
|
||||||
|
|||||||
@@ -124,15 +124,6 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
|
|||||||
lightInReflDir = float3(-1, -1, -1); // This variable is used with APV for reflection probe normalization - see code for LIGHTFEATUREFLAGS_ENV
|
lightInReflDir = float3(-1, -1, -1); // This variable is used with APV for reflection probe normalization - see code for LIGHTFEATUREFLAGS_ENV
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
|
|
||||||
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
|
|
||||||
{
|
|
||||||
float3 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
|
|
||||||
builtinData.bakeDiffuseLighting = lerp(builtinData.bakeDiffuseLighting, ssgiLighting.rgb, _SSGIWeight);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
|
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
|
||||||
float3 normalWS = float3(0.0, 0.0, 1.0);
|
float3 normalWS = float3(0.0, 0.0, 1.0);
|
||||||
#else
|
#else
|
||||||
@@ -140,14 +131,14 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
|
|||||||
#endif
|
#endif
|
||||||
float3 backNormalWS = -normalWS;
|
float3 backNormalWS = -normalWS;
|
||||||
|
|
||||||
|
// Reflect normal to get lighting for reflection probe tinting
|
||||||
|
float3 R = reflect(-V, normalWS);
|
||||||
|
|
||||||
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
|
||||||
if (_EnableProbeVolumes)
|
if (_EnableProbeVolumes)
|
||||||
{
|
{
|
||||||
// Reflect normal to get lighting for reflection probe tinting
|
|
||||||
float3 R = reflect(-V, bsdfData.normalWS);
|
|
||||||
|
|
||||||
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS),
|
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS),
|
||||||
bsdfData.normalWS, -bsdfData.normalWS,
|
normalWS, -backNormalWS,
|
||||||
R, V,
|
R, V,
|
||||||
posInput.positionSS, builtinData.renderingLayers,
|
posInput.positionSS, builtinData.renderingLayers,
|
||||||
builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting, lightInReflDir);
|
builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting, lightInReflDir);
|
||||||
@@ -158,7 +149,14 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
|
|||||||
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
|
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
|
||||||
|
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
|
||||||
|
{
|
||||||
|
float3 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
|
||||||
|
builtinData.bakeDiffuseLighting = lerp(builtinData.bakeDiffuseLighting, ssgiLighting.rgb, _SSGIWeight);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UtsEvaluateBSDF_MatCapDiffuse(float3 positionWS, float3 normalWS, inout BuiltinData builtinData)
|
void UtsEvaluateBSDF_MatCapDiffuse(float3 positionWS, float3 normalWS, inout BuiltinData builtinData)
|
||||||
@@ -262,7 +260,7 @@ void AdjustIndirectLighting(PreLightData preLightData, UtsBSDFData bsdfData, ino
|
|||||||
|
|
||||||
void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput)
|
void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput)
|
||||||
{
|
{
|
||||||
#if !defined(_INDIRECT_DIFFUSE_MODE_OFF) && !defined(_INDIRECT_SPECULAR_MODE_OFF)
|
#if !defined(_INDIRECT_DIFFUSE_MODE_OFF) || !defined(_INDIRECT_SPECULAR_MODE_OFF)
|
||||||
AmbientOcclusionFactor aoFactor;
|
AmbientOcclusionFactor aoFactor;
|
||||||
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
|
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
|
||||||
ApplyAmbientOcclusion(aoFactor, builtinData, lighting);
|
ApplyAmbientOcclusion(aoFactor, builtinData, lighting);
|
||||||
|
|||||||
@@ -276,7 +276,6 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
|||||||
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
|
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
|
||||||
}
|
}
|
||||||
#elif _INDIRECT_DIFFUSE_MODE_MATCAP
|
#elif _INDIRECT_DIFFUSE_MODE_MATCAP
|
||||||
//builtinData.bakeDiffuseLighting = UtsEvaluateColor_MatCap(posInput.positionWS, bsdfData.normalWS, 0.0);
|
|
||||||
UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData);
|
UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData);
|
||||||
#elif _INDIRECT_DIFFUSE_MODE_RAMP
|
#elif _INDIRECT_DIFFUSE_MODE_RAMP
|
||||||
UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData);
|
UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData);
|
||||||
|
|||||||
@@ -5,12 +5,6 @@
|
|||||||
|
|
||||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl"
|
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl"
|
||||||
|
|
||||||
struct UtsShadeMask
|
|
||||||
{
|
|
||||||
float baseShadeMask;
|
|
||||||
float firstShadeMask;
|
|
||||||
};
|
|
||||||
|
|
||||||
float RoughnessToBlinnPhongSpecularExponent(float roughness)
|
float RoughnessToBlinnPhongSpecularExponent(float roughness)
|
||||||
{
|
{
|
||||||
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
|
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
|
||||||
@@ -122,9 +116,9 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
|||||||
|
|
||||||
if (Max3(lightColor.r, lightColor.g, lightColor.b) > 0.0)
|
if (Max3(lightColor.r, lightColor.g, lightColor.b) > 0.0)
|
||||||
{
|
{
|
||||||
shadow = smoothstep(0.4, 0.6, shadow);
|
SHADOW_TYPE sharpShadow = smoothstep(0.4, 0.6, shadow);
|
||||||
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
|
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
|
||||||
shadow *= GetHairShadow(posInput, L);
|
sharpShadow *= GetHairShadow(posInput, L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _SHADING_MODE_SDF
|
#if _SHADING_MODE_SDF
|
||||||
@@ -142,15 +136,16 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
|||||||
float NdotL = dot(bsdfData.normalWS, L);
|
float NdotL = dot(bsdfData.normalWS, L);
|
||||||
float halfLambert = 0.5 * NdotL + 0.5;
|
float halfLambert = 0.5 * NdotL + 0.5;
|
||||||
|
|
||||||
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, 0.0), _ShadingIndex, 0.0).rgb;
|
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, 1.0), _ShadingIndex, 0.0).rgb;
|
||||||
|
//float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(shadow.x, 1.0), _ShadingIndex, 0.0).rgb;
|
||||||
|
|
||||||
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
||||||
specularTerm *= saturate(NdotL) * shadow;
|
specularTerm *= saturate(NdotL) * sharpShadow;
|
||||||
#elif _SHADING_MODE_SDF
|
#elif _SHADING_MODE_SDF
|
||||||
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * shadow.x, 0.0), _ShadingIndex, 0.0).rgb;
|
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, 1.0), _ShadingIndex, 0.0).rgb;
|
||||||
|
|
||||||
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
||||||
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * shadow;
|
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if _SHADING_MODE_STANDARD
|
#if _SHADING_MODE_STANDARD
|
||||||
@@ -159,7 +154,7 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
|||||||
|
|
||||||
float firstColorFeatherForMask = lerp(_1stShadeColorFeather, 0.0, max(_ComposerMaskMode, _FirstShadeOverridden));
|
float firstColorFeatherForMask = lerp(_1stShadeColorFeather, 0.0, max(_ComposerMaskMode, _FirstShadeOverridden));
|
||||||
float baseShadeMask = saturate((halfLambert - (_1stShadeColorStep - firstColorFeatherForMask)) / (_1stShadeColorStep - (_1stShadeColorStep - firstColorFeatherForMask)));
|
float baseShadeMask = saturate((halfLambert - (_1stShadeColorStep - firstColorFeatherForMask)) / (_1stShadeColorStep - (_1stShadeColorStep - firstColorFeatherForMask)));
|
||||||
baseShadeMask *= shadow.x;
|
baseShadeMask *= sharpShadow.x;
|
||||||
|
|
||||||
float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
|
float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||||
float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - secondColorFeatherForMask)) / (_2ndShadeColorStep - (_2ndShadeColorStep - secondColorFeatherForMask)));
|
float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - secondColorFeatherForMask)) / (_2ndShadeColorStep - (_2ndShadeColorStep - secondColorFeatherForMask)));
|
||||||
@@ -167,7 +162,7 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
|||||||
diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, firstShadeMask), bsdfData.diffuseColor, baseShadeMask);
|
diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, firstShadeMask), bsdfData.diffuseColor, baseShadeMask);
|
||||||
specularTerm *= baseShadeMask;
|
specularTerm *= baseShadeMask;
|
||||||
#elif _SHADING_MODE_SDF
|
#elif _SHADING_MODE_SDF
|
||||||
float shadeMask = sdfShadowMask * sdfTexture.b * shadow.x;
|
float shadeMask = sdfShadowMask * sdfTexture.b * sharpShadow.x;
|
||||||
|
|
||||||
diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask);
|
diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask);
|
||||||
specularTerm = (specularTerm + sdfHighlight) * shadeMask;
|
specularTerm = (specularTerm + sdfHighlight) * shadeMask;
|
||||||
|
|||||||
Reference in New Issue
Block a user