summaryrefslogtreecommitdiffstats
path: root/Third_Party
diff options
context:
space:
mode:
Diffstat (limited to 'Third_Party')
-rw-r--r--Third_Party/at.pimaker.ltcgi/Shaders/LTCGI.cginc58
-rw-r--r--Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_config.cginc2
-rw-r--r--Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_functions.cginc22
-rw-r--r--Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_shadowmap.cginc15
-rw-r--r--Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_uniform.cginc4
5 files changed, 77 insertions, 24 deletions
diff --git a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI.cginc b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI.cginc
index c6ad0b7..b976972 100644
--- a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI.cginc
+++ b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI.cginc
@@ -41,9 +41,8 @@ void LTCGI_Evaluate(ltcgi_input input, float3 worldNorm, float3 viewDir, float3x
{
if (!input.flags.lmdOnly) {
// very approximate lol
- float3 ctr = (input.Lw[0] + input.Lw[1])/2;
- float dist = length(ctr);
- if (dist > LTCGI_DISTANCE_FADE_APPROX_MULT)
+ float3 ctr = (input.Lw[0] + input.Lw[1]) * 0.5f;
+ if (dot(ctr, ctr) > LTCGI_DISTANCE_FADE_APPROX_MULT * LTCGI_DISTANCE_FADE_APPROX_MULT)
{
return;
}
@@ -53,6 +52,7 @@ void LTCGI_Evaluate(ltcgi_input input, float3 worldNorm, float3 viewDir, float3x
#define RET1_IF_LMDIFF [branch] if (/*const*/ diffuse && input.flags.diffFromLm) { output.intensity = 1.0f; return; }
+ [branch]
if (input.flags.colormode == LTCGI_COLORMODE_SINGLEUV) {
float2 uv = input.uvStart;
if (uv.x < 0) uv.xy = uv.yx;
@@ -69,6 +69,7 @@ void LTCGI_Evaluate(ltcgi_input input, float3 worldNorm, float3 viewDir, float3x
}
#ifdef LTCGI_AUDIOLINK
+ [branch]
if (input.flags.colormode == LTCGI_COLORMODE_AUDIOLINK) {
float al = AudioLinkData(ALPASS_AUDIOLINK + uint2(0, input.flags.alBand)).r;
output.color *= al;
@@ -133,6 +134,7 @@ void LTCGI_Evaluate(ltcgi_input input, float3 worldNorm, float3 viewDir, float3x
LTCGI_ClipQuadToHorizon(L, n);
// early out if everything was clipped below horizon
+ [branch]
if (n == 0)
return;
@@ -140,15 +142,20 @@ void LTCGI_Evaluate(ltcgi_input input, float3 worldNorm, float3 viewDir, float3x
L[1] = normalize(L[1]);
L[2] = normalize(L[2]);
L[3] = normalize(L[3]);
- L[4] = normalize(L[4]);
- // integrate (and pray that constant folding works well)
+ // integrate
float sum = 0;
- [unroll(5)]
- for (uint v = 0; v < max(3, (uint)n); v++) {
- float3 a = L[v];
- float3 b = L[(v + 1) % 5];
- sum += LTCGI_IntegrateEdge(a, b).z;
+ sum += LTCGI_IntegrateEdge(L[0], L[1]).z;
+ sum += LTCGI_IntegrateEdge(L[1], L[2]).z;
+ sum += LTCGI_IntegrateEdge(L[2], L[3]).z;
+ [branch]
+ if (n >= 4)
+ {
+ L[4] = normalize(L[4]);
+ sum += LTCGI_IntegrateEdge(L[3], L[4]).z;
+ [branch]
+ if (n == 5)
+ sum += LTCGI_IntegrateEdge(L[4], L[0]).z;
}
// doublesided is accounted for with optimization at the start, so return abs
@@ -172,6 +179,15 @@ void LTCGI_Contribution(
totalSpecularIntensity = 0;
totalDiffuseIntensity = 0;
#endif
+
+ #ifdef LTCGI_SPECULAR_OFF
+ specular = 0;
+ #endif
+ #ifdef LTCGI_DIFFUSE_OFF
+ diffuse = 0;
+ #endif
+
+ [branch]
if (_Udon_LTCGI_GlobalEnable == 0.0f) {
return;
}
@@ -181,10 +197,6 @@ void LTCGI_Contribution(
float2 uv = float2(roughness, theta/(0.5*UNITY_PI));
uv = uv*LUT_SCALE + LUT_BIAS;
- #ifndef UNITY_UV_STARTS_AT_TOP
- uv.y = 1 - uv.y;
- #endif
-
// calculate LTCGI custom lightmap UV and sample
float3 lms = LTCGI_SampleShadowmap(lmuv);
@@ -210,9 +222,12 @@ void LTCGI_Contribution(
Minv = mul(Minv, identityBrdf);
// specular brightness
+ float spec_amp = 1.0f;
#ifndef LTCGI_SPECULAR_OFF
+ #ifndef LTCGI_DISABLE_LUT2
#ifndef SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER
- float spec_amp = _Udon_LTCGI_lut2.SampleLevel(LTCGI_SAMPLER, uv, 0).x;
+ spec_amp = _Udon_LTCGI_lut2.SampleLevel(LTCGI_SAMPLER, uv, 0).x;
+ #endif
#endif
#endif
@@ -231,8 +246,14 @@ void LTCGI_Contribution(
#endif
// loop through all lights and add them to the output
+#if MAX_SOURCES != 1
uint count = min(_Udon_LTCGI_ScreenCount, MAX_SOURCES);
[loop]
+#else
+ // mobile config
+ const uint count = 1;
+ [unroll(1)]
+#endif
for (uint i = 0; i < count; i++) {
// skip masked and black lights
if (_Udon_LTCGI_Mask[i]) continue;
@@ -298,6 +319,7 @@ void LTCGI_Contribution(
lmd = smoothstep(0.0, LTCGI_SPECULAR_LIGHTMAP_STEP, saturate(lm - LTCGI_LIGHTMAP_CUTOFF));
}
ltcgi_output diff;
+ diff.color = 0;
LTCGI_Evaluate(input, worldNorm, viewDir, identityBrdf, roughness, true, diff);
diff.intensity *= lmd;
@@ -317,6 +339,7 @@ void LTCGI_Contribution(
if (flags.specular)
{
ltcgi_output spec;
+ spec.color = 0;
LTCGI_Evaluate(input, worldNorm, viewDir, Minv, roughness, false, spec);
spec.intensity *= spec_amp * smoothstep(0.0, LTCGI_SPECULAR_LIGHTMAP_STEP, saturate(lm - LTCGI_LIGHTMAP_CUTOFF));
@@ -336,14 +359,16 @@ void LTCGI_Contribution(
#ifndef LTCGI_API_V2
+// missing totalSpecularIntensity, totalDiffuseIntensity, specular
void LTCGI_Contribution(
float3 worldPos, float3 worldNorm, float3 viewDir, float roughness, float2 lmuv, inout half3 diffuse
) {
- half3 _u1;
+ half3 _u1 = (half3)0;
float _u2, _u3;
LTCGI_Contribution(worldPos, worldNorm, viewDir, roughness, lmuv, diffuse, _u1, _u2, _u3);
}
+// missing totalSpecularIntensity, totalDiffuseIntensity
void LTCGI_Contribution(
float3 worldPos, float3 worldNorm, float3 viewDir, float roughness, float2 lmuv, inout half3 diffuse, inout half3 specular
) {
@@ -351,6 +376,7 @@ void LTCGI_Contribution(
LTCGI_Contribution(worldPos, worldNorm, viewDir, roughness, lmuv, diffuse, specular, _u1, _u2);
}
+// missing totalDiffuseIntensity
void LTCGI_Contribution(
float3 worldPos, float3 worldNorm, float3 viewDir, float roughness, float2 lmuv, inout half3 diffuse, inout half3 specular, out float totalSpecularIntensity
) {
diff --git a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_config.cginc b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_config.cginc
index 1ddb38a..e64f5a3 100644
--- a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_config.cginc
+++ b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_config.cginc
@@ -73,7 +73,7 @@ const float LUT_BIAS = 0.5/LUT_SIZE;
#define LTCGI_STATIC_UNIFORMS
// Allow statically textured lights.
-//#define LTCGI_STATIC_TEXTURES
+#define LTCGI_STATIC_TEXTURES
// Enable support for cylindrical screens.
//#define LTCGI_CYLINDER
diff --git a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_functions.cginc b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_functions.cginc
index ff33c87..08df1c7 100644
--- a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_functions.cginc
+++ b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_functions.cginc
@@ -138,16 +138,28 @@ half3 premul_alpha(half4 i)
return i.rgb * i.a;
}
+half max2(half2 v)
+{
+ return max(v.x, v.y);
+}
+
void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
{
+#ifndef LTCGI_STATIC_TEXTURES
+ idx = 0; // optimize away the branches below
+#endif
+
#ifdef LTCGI_FAST_SAMPLING
#ifndef SHADER_TARGET_SURFACE_ANALYSIS
- blend *= 2.5f;
+ float outside = max2(abs(uv - 0.5f) - 0.5f);
+ float outmod = smoothstep(-0.1f, 0.1f, outside) * 2.5f;
+ blend = blend * 2.5f + outmod;
[branch]
if (idx == 0)
{
result = premul_alpha(_Udon_LTCGI_Texture_LOD0.SampleLevel(LTCGI_SAMPLER, uv, blend));
}
+ #ifdef LTCGI_STATIC_TEXTURES
else
{
result = UNITY_SAMPLE_TEX2DARRAY_SAMPLER_LOD(
@@ -157,14 +169,12 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
blend
).rgb;
}
+ #endif
#else
result = 0;
#endif
#else
result = 0;
- #ifndef LTCGI_STATIC_TEXTURES
- idx = 0; // optimize away the branches below
- #endif
[branch]
if (lod == 0)
@@ -191,6 +201,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
return;
#endif
}
+ #ifdef LTCGI_STATIC_TEXTURES
else
{
result = premul_alpha(UNITY_SAMPLE_TEX2DARRAY_SAMPLER_LOD(
@@ -201,6 +212,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
));
return;
}
+ #endif
}
}
@@ -227,6 +239,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
return;
#endif
}
+ #ifdef LTCGI_STATIC_TEXTURES
else
{
[forcecase]
@@ -258,6 +271,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
return;
}
}
+ #endif
#endif
}
diff --git a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_shadowmap.cginc b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_shadowmap.cginc
index 922c567..2c4a598 100644
--- a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_shadowmap.cginc
+++ b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_shadowmap.cginc
@@ -25,7 +25,7 @@ float4 LTCGI_cubic(float v)
// Unity's SampleTexture2DBicubic doesn't exist in 2018, which is our target here.
// So this is a similar function with tweaks to have similar semantics.
-float4 LTCGI_SampleTexture2DBicubicFilter(Texture2D tex, SamplerState smp, float2 coord, float4 texSize)
+float4 LTCGI_SampleTexture2DBicubicFilter(Texture2D tex, SamplerState smp, float2 coord, float4 texSize, bool lightmap = false)
{
coord = coord * texSize.xy - 0.5;
float fx = frac(coord.x);
@@ -45,6 +45,13 @@ float4 LTCGI_SampleTexture2DBicubicFilter(Texture2D tex, SamplerState smp, float
float4 sample2 = tex.Sample(smp, float2(offset.x, offset.w) * texSize.zw);
float4 sample3 = tex.Sample(smp, float2(offset.y, offset.w) * texSize.zw);
+ if (lightmap) {
+ sample0 = float4(DecodeLightmap(sample0), 1.0);
+ sample1 = float4(DecodeLightmap(sample1), 1.0);
+ sample2 = float4(DecodeLightmap(sample2), 1.0);
+ sample3 = float4(DecodeLightmap(sample3), 1.0);
+ }
+
float sx = s.x / (s.x + s.y);
float sy = s.z / (s.z + s.w);
@@ -68,10 +75,12 @@ float4 LTCGI_SampleShadowmap(float2 lmuv)
return LTCGI_SampleTexture2DBicubicFilter(
_Udon_LTCGI_Lightmap, LTCGI_SAMPLER,
- lmuv, _Udon_LTCGI_Lightmap_TexelSize
+ lmuv, _Udon_LTCGI_Lightmap_TexelSize,
+ true
);
#else
- return _Udon_LTCGI_Lightmap.Sample(LTCGI_SAMPLER, lmuv);
+ fixed4 sample = _Udon_LTCGI_Lightmap.Sample(LTCGI_SAMPLER, lmuv);
+ return float4(DecodeLightmap(sample), 1.0);
#endif
#endif
}
diff --git a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_uniform.cginc b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_uniform.cginc
index 116cedd..2bf4673 100644
--- a/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_uniform.cginc
+++ b/Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_uniform.cginc
@@ -10,7 +10,9 @@ SamplerState sampler_LTCGI_trilinear_clamp_sampler;
// LUTs
#ifndef SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER
+#ifndef LTCGI_DISABLE_LUT2
uniform Texture2D<float4> _Udon_LTCGI_lut2;
+#endif
uniform Texture2D<float4> _Udon_LTCGI_lut1;
#endif
@@ -120,12 +122,14 @@ uniform Texture2D<float4> _Udon_LTCGI_Texture_LOD3;
#endif
// static textures
+#ifdef LTCGI_STATIC_TEXTURES
UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(_Udon_LTCGI_Texture_LOD0_arr);
#ifndef LTCGI_FAST_SAMPLING
UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(_Udon_LTCGI_Texture_LOD1_arr);
UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(_Udon_LTCGI_Texture_LOD2_arr);
UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(_Udon_LTCGI_Texture_LOD3_arr);
#endif
+#endif
// lightmap
#ifndef SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER