Added UtsSingleLightLoop
This commit is contained in:
@@ -277,4 +277,4 @@ void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, Uts
|
||||
ApplyExposureAdjustment(lightLoopOutput.specularLighting);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -38,32 +38,6 @@ int GetNextDirectionalLightIndex(BuiltinData builtinData, int currentIndex, int
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
int GetUtsMainLightIndex(BuiltinData builtinData)
|
||||
{
|
||||
int mainLightIndex = -1;
|
||||
float3 lightColor = float3(0.0f, 0.0f, 0.0f);
|
||||
float lightAttenuation = 0.0f;
|
||||
uint i = 0; // Declare once to avoid the D3D11 compiler warning.
|
||||
for (i = 0; i < _DirectionalLightCount; ++i)
|
||||
{
|
||||
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
float3 currentLightColor = _DirectionalLightDatas[i].color;
|
||||
float currentLightAttenuation = GetColorAttenuation(currentLightColor);
|
||||
|
||||
if (mainLightIndex == -1 || (currentLightAttenuation > lightAttenuation))
|
||||
{
|
||||
mainLightIndex = i;
|
||||
lightAttenuation = currentLightAttenuation;
|
||||
|
||||
lightColor = currentLightColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mainLightIndex;
|
||||
}
|
||||
|
||||
bool UtsUseScreenSpaceShadow(DirectionalLightData light, float3 normalWS)
|
||||
{
|
||||
#if defined(RAY_TRACED_SCREEN_SPACE_SHADOW_FLAG)
|
||||
@@ -464,29 +438,4 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
// return mainPunctualLight;
|
||||
// }
|
||||
|
||||
// Todo: calculate the acutal main lighboth dorectional and punctual)t based on the light attenuation, rather than using the main directional light
|
||||
UTSLightData GetCustomMainLightData(BuiltinData builtinData, UTSLightData mainPunctualLight)
|
||||
{
|
||||
UTSLightData utsLightData;
|
||||
int mainLightIndex;
|
||||
|
||||
mainLightIndex = GetUtsMainLightIndex(builtinData);
|
||||
|
||||
if (mainLightIndex == -1 || length(_DirectionalLightDatas[mainLightIndex].color) < length(mainPunctualLight.lightColor))
|
||||
{
|
||||
utsLightData = mainPunctualLight;
|
||||
}
|
||||
else
|
||||
{
|
||||
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
|
||||
utsLightData.lightDirection = -_DirectionalLightDatas[mainLightIndex].forward;
|
||||
utsLightData.diffuseDimmer = _DirectionalLightDatas[mainLightIndex].diffuseDimmer;
|
||||
utsLightData.specularDimmer = _DirectionalLightDatas[mainLightIndex].specularDimmer;
|
||||
utsLightData.shadowTint = _DirectionalLightDatas[mainLightIndex].shadowTint;
|
||||
utsLightData.penumbraTint = _DirectionalLightDatas[mainLightIndex].penumbraTint;
|
||||
}
|
||||
|
||||
return utsLightData;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -131,18 +131,23 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
|
||||
float3 diffuseTerm = 0.0;
|
||||
float3 specularTerm = ComputeSpecularTerm(bsdfData, preLightData, V, L);
|
||||
|
||||
#if _USE_SHADING_RAMP_MAP_ON
|
||||
float rampMask = _ShadingRampMask;
|
||||
#if _SHADING_RAMP_MASK_MAP
|
||||
rampMask *= SAMPLE_TEXTURE2D(_ShadingRampMaskMap, s_linear_clamp_sampler, uv).r;
|
||||
#endif
|
||||
|
||||
#if _SHADING_MODE_STANDARD
|
||||
float NdotL = dot(bsdfData.normalWS, L);
|
||||
float halfLambert = 0.5 * NdotL + 0.5;
|
||||
|
||||
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;
|
||||
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, rampMask), _ShadingIndex, 0.0).rgb;
|
||||
|
||||
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
||||
specularTerm *= saturate(NdotL) * sharpShadow;
|
||||
#elif _SHADING_MODE_SDF
|
||||
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, 1.0), _ShadingIndex, 0.0).rgb;
|
||||
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, rampMask), _ShadingIndex, 0.0).rgb;
|
||||
|
||||
diffuseTerm = bsdfData.diffuseColor * rampColor;
|
||||
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow;
|
||||
@@ -186,4 +191,4 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
return lighting;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
59
Runtime/Shaders/Includes/Lighting/UtsSingleLightLoop.hlsl
Normal file
59
Runtime/Shaders/Includes/Lighting/UtsSingleLightLoop.hlsl
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef UTS_SINGLE_LIGHT_LOOP
|
||||
#define UTS_SINGLE_LIGHT_LOOP
|
||||
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Models/SurfaceFeature.cs.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsSurfaceFeatureEvaluation.hlsl"
|
||||
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsLightEvaluation.hlsl"
|
||||
|
||||
struct UtsSingleMainLight
|
||||
{
|
||||
GPULightType lightType;
|
||||
uint lightIndex;
|
||||
};
|
||||
|
||||
int GetMainLightIndex(BuiltinData builtinData)
|
||||
{
|
||||
int mainLightIndex = -1;
|
||||
|
||||
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
|
||||
{
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
|
||||
if ((light.lightDimmer > 0) && (light.shadowDimmer > 0) && IsMatchingLightLayer(light.lightLayers, builtinData.renderingLayers))
|
||||
{
|
||||
SHADOW_TYPE shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
|
||||
posInput.positionSS, _ObjectCenterPositionWS + L * _ShadowDistanceBias, UtsGetShadowNormal(bsdfData),
|
||||
light.shadowIndex, L);
|
||||
|
||||
if (length(shadowValue) > 0.0)
|
||||
{
|
||||
mainLightIndex = _DirectionalShadowIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mainLightIndex;
|
||||
}
|
||||
|
||||
// TODO: The process of finding main light index should be move to vertex stage
|
||||
void UtsSingleLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bsdfData, BuiltinData builtinData,
|
||||
float3 V, uint featureFlags, out LightLoopOutput lightLoopOutput)
|
||||
{
|
||||
PreLightData preLightData = GetPreLightData_UTS(V, posInput, bsdfData);
|
||||
|
||||
AggregateLighting aggregateLighting;
|
||||
ZERO_INITIALIZE(AggregateLighting, aggregateLighting);
|
||||
|
||||
#if _USER_LIGHT_SOURCE_LOOP_ON
|
||||
|
||||
#else
|
||||
int mainLightIndex = GetMainLightIndex(builtinData);
|
||||
|
||||
if (mainLightIndex != -1 && featureFlags & LIGHTFEATUREFLAGS_PUNCTUAL)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74f20e448cd01914fa3934de999353bc
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user