Added new fabirc pbr mode;

Added new stocking surface feature;

Fixed the issue that diffuse bsdf is not energy conserving.
Fixed the bug that shader can not render alpha clip properly;
This commit is contained in:
2025-05-15 16:07:54 +09:00
parent d19322b768
commit 35dc7b15a6
21 changed files with 234 additions and 103 deletions

View File

@@ -1,6 +1,4 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsLitData.hlsl"
#define APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT
@@ -80,7 +78,7 @@ void Frag(PackedVaryingsToPS packedInput,
#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))
@@ -91,24 +89,23 @@ void Frag(PackedVaryingsToPS packedInput,
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
#endif
// 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();
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;
input.texCoord0.xy = clamp(input.texCoord0.xy -_EyeParallaxAmount * parallaxOffset, 0, 1);
// Must have view Dir to work
float2 viewT = TransformObjectToTangent(V, input.tangentToWorld);
float2 parallaxOffset = viewT;
parallaxOffset.y = -parallaxOffset.y;
input.texCoord0.xy = clamp(input.texCoord0.xy -_EyeParallaxAmount * parallaxOffset, 0, 1);
#endif
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
@@ -118,10 +115,10 @@ void Frag(PackedVaryingsToPS packedInput,
#else
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
#endif
SurfaceData tempSurfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData);
UtsGetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData);
UTSSurfaceData surfaceData = GetUTSSurfaceData(input, V);
UtsBSDFData bsdfData = ConvertUTSSurfaceDataToUTSBSDFData(surfaceData);
@@ -132,11 +129,9 @@ void Frag(PackedVaryingsToPS packedInput,
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;
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).
@@ -145,24 +140,13 @@ void Frag(PackedVaryingsToPS packedInput,
// Initialize the contactShadow and contactShadowFade fields
InitContactShadow(posInput, context);
LightLoopOutput lightLoopOutput;
ZERO_INITIALIZE(LightLoopOutput, lightLoopOutput);
UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput);
float3 finalColor = lightLoopOutput.diffuseLighting + lightLoopOutput.specularLighting;
// #if _SURFACE_TYPE_TRANSPARENT
// float alpha = channelAlpha;
// outColor = EvaluateAtmosphericScattering(posInput, V, float4(finalColor, 1));
// #else
// float alpha = lerp(1.0, channelAlpha, _AlphaCutoffEnable);
// #endif
//
// alpha = lerp(alpha, step(_AlphaCutoff, alpha), _AlphaCutoffEnable);
outColor = float4(finalColor, 1.0);
UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput);
outColor = ApplyBlendMode(lightLoopOutput.diffuseLighting, lightLoopOutput.specularLighting, builtinData.opacity);
#if _MATERIAL_TYPE_FRONTHAIR && ENABLE_UTS_HAIR_BLENDING
float2 screenUV = posInput.positionSS; // * _HairBlendingRTHandleScale.xy; // Why we don't need to scale? Does unity handle it internally?