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:
@@ -50,6 +50,57 @@ float3 UtsComputeDiffuseColor(float3 baseColor, float metallic)
|
||||
return UtsComputeDiffuseColor(baseColor, metallic, 0.0);
|
||||
}
|
||||
|
||||
float Random(float2 uv)
|
||||
{
|
||||
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
float unity_noise_interpolate (float a, float b, float t)
|
||||
{
|
||||
return (1.0-t)*a + (t*b);
|
||||
}
|
||||
|
||||
float ValueNoise (float2 uv)
|
||||
{
|
||||
float2 i = floor(uv);
|
||||
float2 f = frac(uv);
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
uv = abs(frac(uv) - 0.5);
|
||||
float2 c0 = i + float2(0.0, 0.0);
|
||||
float2 c1 = i + float2(1.0, 0.0);
|
||||
float2 c2 = i + float2(0.0, 1.0);
|
||||
float2 c3 = i + float2(1.0, 1.0);
|
||||
float r0 = Random(c0);
|
||||
float r1 = Random(c1);
|
||||
float r2 = Random(c2);
|
||||
float r3 = Random(c3);
|
||||
|
||||
float bottomOfGrid = unity_noise_interpolate(r0, r1, f.x);
|
||||
float topOfGrid = unity_noise_interpolate(r2, r3, f.x);
|
||||
float t = unity_noise_interpolate(bottomOfGrid, topOfGrid, f.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
float SimpleNoise(float2 UV, float Scale)
|
||||
{
|
||||
float t = 0.0;
|
||||
|
||||
float freq = pow(2.0, float(0));
|
||||
float amp = pow(0.5, float(3-0));
|
||||
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
|
||||
|
||||
freq = pow(2.0, float(1));
|
||||
amp = pow(0.5, float(3-1));
|
||||
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
|
||||
|
||||
freq = pow(2.0, float(2));
|
||||
amp = pow(0.5, float(3-2));
|
||||
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
#define SampleRampSignalLine(texture, u) (SAMPLE_TEXTURE2D_LOD(texture, s_linear_clamp_sampler, float2(u, 0.5), 0))
|
||||
|
||||
// Exposure
|
||||
@@ -243,4 +294,4 @@ float3 GetWorldPosFromDepthBuffer(float2 clipPos01, float cameraDepth)
|
||||
|
||||
return mul(unity_CameraToWorld, float4(localInvertDepthDirHD, 1.0)).xyz;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -295,7 +295,7 @@ void UtsGetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInput
|
||||
#else
|
||||
float alphaCutoff = _AlphaCutoff;
|
||||
#endif
|
||||
|
||||
// clip(-0.1);
|
||||
GENERIC_ALPHA_TEST(alphaValue, alphaCutoff);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
#ifndef UTS_SURFACE_FEATURE_EVALUATION
|
||||
#define UTS_SURFACE_FEATURE_EVALUATION
|
||||
|
||||
void UtsEvaluateLighting_Stocking(FragInputs input, PositionInputs posInput, float3 normalWS, float3 V, inout AggregateLighting aggregateLighting)
|
||||
{
|
||||
float NdotV = saturate(dot(normalize(V), normalWS));
|
||||
|
||||
NdotV = pow(NdotV, 2.0);
|
||||
|
||||
// TODO: Move sparkle to bsdf evaluation?
|
||||
// float sparkle = Random(posInput.positionNDC.xy);
|
||||
// sparkle = step(0.995, sparkle);
|
||||
// float noise = SimpleNoise(posInput.positionNDC.xy, 500.0);
|
||||
// sparkle = noise < sparkle ? 1.0 : 0.0;
|
||||
|
||||
aggregateLighting.direct.diffuse *= NdotV;
|
||||
// aggregateLighting.direct.specular = saturate(aggregateLighting.direct.specular + sparkle * (1.0 - NdotV) * 0.5);
|
||||
}
|
||||
|
||||
DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData
|
||||
#if _LIGHT_BASE_RIM_LIGHT_ON
|
||||
, float3 L, float3 lightColor
|
||||
@@ -9,9 +25,10 @@ DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData
|
||||
{
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
|
||||
float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity;
|
||||
|
||||
rimLightColor = lerp(rimLightColor, rimLightColor * bsdfData.diffuseColor.rgb, _AlbedoAffectRimLight * _RimLightColor.a);
|
||||
|
||||
#if _SCREEN_SPACE_RIM_LIGHT_ON
|
||||
float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS));
|
||||
float2 depthUV = posInput.positionNDC.xy + normalVS.xy * (_RimLightLevel * 0.05 / posInput.linearDepth);
|
||||
@@ -24,17 +41,17 @@ DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData
|
||||
float rimLightMask = pow(1.0 - clampNdotV, exp2(lerp(3.0, 0.0, _RimLightLevel)));
|
||||
rimLightMask = lerp(rimLightMask, step(_RimLightClippingLevel, rimLightMask), _RimLightClipping);
|
||||
#endif
|
||||
|
||||
|
||||
#if _LIGHT_BASE_RIM_LIGHT_ON
|
||||
float halfLambert = 0.5 * dot(bsdfData.normalWS, L) + 0.5;
|
||||
float lightBaseMask = saturate(smoothstep(_LightDirectionRimLightLevel, 1.0, halfLambert));
|
||||
|
||||
|
||||
rimLightMask *= lightBaseMask;
|
||||
rimLightColor *= lightColor;
|
||||
#endif
|
||||
|
||||
|
||||
lighting.diffuse = rimLightMask * rimLightColor;
|
||||
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
@@ -42,7 +59,7 @@ DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS,
|
||||
{
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
|
||||
// Should we scroll the angel ring texture on x?
|
||||
float3 cameraRight = UNITY_MATRIX_V[0].xyz;
|
||||
float3 cameraFront = UNITY_MATRIX_V[2].xyz;
|
||||
@@ -53,18 +70,18 @@ DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS,
|
||||
float cameraRollCos = dot(rightAxis, cameraRight) / (rightAxisMagnitude * cameraRightMagnitude);
|
||||
float3 cameraRoll = acos(clamp(cameraRollCos, -1.0, 1.0));
|
||||
float cameraDir = cameraRight.y < 0 ? -1.0 : 1.0;
|
||||
|
||||
|
||||
float2 arOffsetU = lerp(mul(UNITY_MATRIX_V, float4(normalWS, 0)).xyz, float3(0, 0, 1), _AngelRingOffsetU).xy;
|
||||
arOffsetU = arOffsetU * 0.5 + 0.5;
|
||||
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll).x, 0.5, 1.0);
|
||||
float2 arOffsetUV = float2(arvnRotate.x, lerp(input.texCoord0.y, arvnRotate.y, _AngelRingOffsetV));
|
||||
float4 angelRingColor = SAMPLE_TEXTURE2D(_AngelRingColorMap, sampler_AngelRingColorMap, TRANSFORM_TEX(arOffsetUV, _AngelRingColorMap)) * _AngelRingColor * _AngelRingIntensity;
|
||||
|
||||
|
||||
float weight = saturate(dot(normalize(V), normalWS));
|
||||
|
||||
|
||||
lighting.specular = angelRingColor.r * angelRingColor.a * weight;
|
||||
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user