diff options
| -rw-r--r-- | 2ner.cginc | 17 | ||||
| -rw-r--r-- | SharedFilteringLib.hlsl | 2 | ||||
| -rw-r--r-- | UnityStandardCoreMinimal.cginc | 72 | ||||
| -rw-r--r-- | features.cginc | 4 | ||||
| -rw-r--r-- | yum_brdf.cginc | 6 | ||||
| -rw-r--r-- | yum_lighting.cginc | 8 |
6 files changed, 101 insertions, 8 deletions
@@ -1,6 +1,9 @@ #ifndef __2NER_INC
#define __2NER_INC
+#define HANDLE_SHADOWS_BLENDING_IN_GI
+
+#include "UnityStandardCoreMinimal.cginc"
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
#include "AutoLight.cginc"
@@ -186,15 +189,13 @@ v2f vert(appdata v) { o.tangent = v.tangent.xyz;
o.binormal = cross(o.normal, o.tangent) * v.tangent.w;
- UNITY_TRANSFER_LIGHTING(o, v.uv0);
+ UNITY_TRANSFER_LIGHTING(o, v.uv1);
UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos);
#if defined(SHADOW_CASTER_PASS)
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
#endif
-#if defined(SHADOWS_SCREEN)
TRANSFER_SHADOW(o);
-#endif
// Vertex color
o.color = v.color;
@@ -460,7 +461,15 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace UNITY_APPLY_FOG(_unity_fogCoord, lit.rgb);
return lit;
-#elif defined(SHADOW_CASTER_PASS) || defined(MASKED_STENCIL1_PASS) || defined(MASKED_STENCIL2_PASS) || defined(MASKED_STENCIL3_PASS) || defined(MASKED_STENCIL4_PASS) || defined(DEPTH_PREPASS)
+#elif defined(SHADOW_CASTER_PASS)
+ // Apply dithering for LOD if needed
+ #ifdef LOD_FADE_CROSSFADE
+ UnityApplyDitherCrossFade(i.pos.xy);
+ #endif
+
+ // Output proper shadow data
+ SHADOW_CASTER_FRAGMENT(i)
+defined(MASKED_STENCIL1_PASS) || defined(MASKED_STENCIL2_PASS) || defined(MASKED_STENCIL3_PASS) || defined(MASKED_STENCIL4_PASS) || defined(DEPTH_PREPASS)
return 0;
#endif
}
diff --git a/SharedFilteringLib.hlsl b/SharedFilteringLib.hlsl index 582adff..56dc8c3 100644 --- a/SharedFilteringLib.hlsl +++ b/SharedFilteringLib.hlsl @@ -1,6 +1,8 @@ #ifndef SERVICE_FILTERING_INCLUDED #define SERVICE_FILTERING_INCLUDED +#include "SharedSamplingLib.hlsl" + float4 cubic(float v) { float4 n = float4(1.0, 2.0, 3.0, 4.0) - v; diff --git a/UnityStandardCoreMinimal.cginc b/UnityStandardCoreMinimal.cginc new file mode 100644 index 0000000..e88781e --- /dev/null +++ b/UnityStandardCoreMinimal.cginc @@ -0,0 +1,72 @@ +#ifndef __UNITY_STANDARD_CORE_MINIMAL_INC +#define __UNITY_STANDARD_CORE_MINIMAL_INC + +#include "SharedFilteringLib.hlsl" +#include "UnityShadowLibrary.cginc" + +// Now add the SampleShadowMaskBicubic function +fixed4 SampleShadowMaskBicubic(float2 uv) +{ + #if defined(UNITY_SHADOWMASK) && defined(SHADER_API_D3D11) + float width, height; + unity_ShadowMask.GetDimensions(width, height); + float4 unity_ShadowMask_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(unity_ShadowMask, sampler_unity_ShadowMask, + uv, unity_ShadowMask_TexelSize); + #else + // Fallback to regular sampling + return UNITY_SAMPLE_TEX2D(unity_ShadowMask, uv); + #endif +} + +fixed UnitySampleBakedOcclusionBicubic(float2 lightmapUV, float3 worldPos) +{ + #if defined (SHADOWS_SHADOWMASK) + #if defined(LIGHTMAP_ON) + fixed4 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #else + fixed4 rawOcclusionMask = fixed4(1.0, 1.0, 1.0, 1.0); + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); + else + rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #else + rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #endif + #endif + return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); + + #else + + //In forward dynamic objects can only get baked occlusion from LPPV, light probe occlusion is done on the CPU by attenuating the light color. + fixed atten = 1.0f; + #if defined(UNITY_INSTANCING_ENABLED) && defined(UNITY_USE_SHCOEFFS_ARRAYS) + // ...unless we are doing instancing, and the attenuation is packed into SHC array's .w component. + atten = unity_SHC.w; + #endif + + #if UNITY_LIGHT_PROBE_PROXY_VOLUME && !defined(LIGHTMAP_ON) && !UNITY_STANDARD_SIMPLE + fixed4 rawOcclusionMask = atten.xxxx; + if (unity_ProbeVolumeParams.x == 1.0) + rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); + return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); + #endif + + return atten; + #endif +} + +void GetBakedAttenuation(inout float atten, float2 lightmapUV, float3 worldPos) +{ + // Base pass with Lightmap support is responsible for handling ShadowMask / blending here for performance reason + #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) + half bakedAtten = UnitySampleBakedOcclusionBicubic(lightmapUV.xy, worldPos); + float zDist = dot(_WorldSpaceCameraPos - worldPos, UNITY_MATRIX_V[2].xyz); + float fadeDist = UnityComputeShadowFadeDistance(worldPos, zDist); + atten = UnityMixRealtimeAndBakedShadows(atten, bakedAtten, UnityComputeShadowFade(fadeDist)); + #endif +} + +#endif // __UNITY_STANDARD_CORE_MINIMAL_INC diff --git a/features.cginc b/features.cginc index b46c97e..734472c 100644 --- a/features.cginc +++ b/features.cginc @@ -6,6 +6,10 @@ #pragma shader_feature_local _MATERIAL_TYPE_CLOTH_SUBSURFACE //endex +//ifex _Receive_Shadows_Enabled==0 +#pragma shader_feature_local _RECEIVE_SHADOWS +//endex + //ifex _Alpha_Multiplier_Enabled==0 #pragma shader_feature_local _ALPHA_MULTIPLIER //endex diff --git a/yum_brdf.cginc b/yum_brdf.cginc index 6a4b5e5..cd97865 100644 --- a/yum_brdf.cginc +++ b/yum_brdf.cginc @@ -91,7 +91,7 @@ float4 YumBRDF(v2f i, const YumLighting light, YumPbr pbr) { #endif // Cloth specular BRDF - float3 Fr = specularLobe(pbr, 0.04, h, LoH, NoH, NoV, NoL_wrapped_s); + float3 Fr = specularLobe(pbr, 0.04, h, LoH, NoH, NoV, NoL_wrapped_s) * light.attenuation; #if defined(_MATERIAL_TYPE_CLOTH_SUBSURFACE) // No need to multiply by NoL when using subsurface scattering @@ -117,7 +117,7 @@ float4 YumBRDF(v2f i, const YumLighting light, YumPbr pbr) { float3 Fd = pbr.albedo / PI; Fd *= (1.0 - pbr.metallic) * light.attenuation * pbr.ao; - float3 Fr = specularLobe(pbr, f0, h, LoH, NoH, NoV, NoL_wrapped_s) * pbr.ao * PI; + float3 Fr = specularLobe(pbr, f0, h, LoH, NoH, NoV, NoL_wrapped_s) * pbr.ao * PI * light.attenuation; float3 color = Fd * NoL_wrapped_d + Fr * energy_compensation * NoL_wrapped_s; direct_standard = color * light.direct; @@ -154,7 +154,7 @@ float4 YumBRDF(v2f i, const YumLighting light, YumPbr pbr) { float specularAO = computeSpecularAO(NoV, diffuseAO * light.occlusion, pbr.roughness); float3 specularSingleBounceAO = singleBounceAO(specularAO) * energy_compensation; - float3 Fd = pbr.albedo * light.diffuse * (1.0 - E) * (1.0 - pbr.metallic) * pbr.ao * light.attenuation; + float3 Fd = pbr.albedo * light.diffuse * (1.0 - E) * (1.0 - pbr.metallic) * pbr.ao; float3 Fr = E * light.specular * specularSingleBounceAO; indirect_standard = Fr + Fd; diff --git a/yum_lighting.cginc b/yum_lighting.cginc index a77114f..af082b0 100644 --- a/yum_lighting.cginc +++ b/yum_lighting.cginc @@ -5,6 +5,7 @@ #include "AutoLight.cginc" #include "UnityPBSLighting.cginc" #include "UnityLightingCommon.cginc" +#include "UnityStandardCoreMinimal.cginc" #include "features.cginc" #include "LightVolumes.cginc" @@ -95,7 +96,12 @@ float getShadowAttenuation(v2f i) float shadow = 1; attenuation = 1; #endif - attenuation *= lerp(1, shadow, _Shadow_Strength); + + attenuation *= shadow; + + GetBakedAttenuation(attenuation, i.uv01.zw, i.worldPos); + + attenuation = lerp(1, attenuation, _Shadow_Strength); return attenuation; } |
