Skip to content

Commit

Permalink
make fast sampling a serialized setting
Browse files Browse the repository at this point in the history
  • Loading branch information
PiMaker committed May 11, 2024
1 parent f9d6c8e commit 96338db
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
32 changes: 22 additions & 10 deletions Editor/LTCGI_Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public partial class LTCGI_Controller : MonoBehaviour
[Tooltip("Renderers that may change material during runtime. Otherwise only 'sharedMaterial's are updated for performance reasons.")]
public Renderer[] DynamicRenderers;

#if UNITY_STANDALONE
[Tooltip("When enabled, LTCGI will not use a blur chain but rather just the input texture's mip maps. This is faster and saves samplers, but will not look as good.")]
public bool FastSampling = false;
#else
public bool FastSampling => true; // force-enable on Quest, but allow use of toggle in C# code below on Standalone too (to avoid unnecessarily uploading LOD CRT references)
#endif

[Header("Expert Settings")]
[Tooltip("Do not automatically set up the blur chain. Use this if you use AVPro to set _MainTex on the LOD1 material for example.")]
public bool CustomBlurChain = false;
Expand Down Expand Up @@ -544,27 +551,33 @@ public void UpdateMaterials(bool fast, LTCGI_Screen screen = null)
adapter._Screens = screens.Select(x => x != null ? x.gameObject : null).ToArray();
adapter._LTCGI_LODs = new Texture[4];
adapter._LTCGI_LODs[0] = VideoTexture;
#if UNITY_STANDALONE
if (!FastSampling)
{
adapter._LTCGI_LODs[1] = LOD1;
adapter._LTCGI_LODs[2] = LOD2;
adapter._LTCGI_LODs[3] = LOD3;
#else
}
else
{
adapter._LTCGI_LODs[1] = null;
adapter._LTCGI_LODs[2] = null;
adapter._LTCGI_LODs[3] = null;
#endif
}
if (_LTCGI_LOD_arrays != null)
{
adapter._LTCGI_Static_LODs_0 = _LTCGI_LOD_arrays[0];
#if UNITY_STANDALONE
if (!FastSampling)
{
adapter._LTCGI_Static_LODs_1 = _LTCGI_LOD_arrays[1];
adapter._LTCGI_Static_LODs_2 = _LTCGI_LOD_arrays[2];
adapter._LTCGI_Static_LODs_3 = _LTCGI_LOD_arrays[3];
#else
}
else
{
adapter._LTCGI_Static_LODs_1 = null;
adapter._LTCGI_Static_LODs_2 = null;
adapter._LTCGI_Static_LODs_3 = null;
#endif
}
}
else
{
Expand All @@ -590,11 +603,10 @@ public void UpdateMaterials(bool fast, LTCGI_Screen screen = null)
Math.Max(adapter._LTCGI_ScreenCountDynamic,
Array.FindLastIndex(mask, m => m == 0.0f) + 1)).ToArray();
adapter._LTCGI_ScreenCountMaskedAvatars = Array.FindLastIndex(screens, x => x.AffectAvatars) + 1;
#if UNITY_STANDALONE
adapter.BlurCRTInput = LOD1s;
#else
if (FastSampling)
adapter.BlurCRTInput = null;
#endif
else
adapter.BlurCRTInput = LOD1s;

#pragma warning disable 618
adapter.ApplyProxyModifications();
Expand Down
16 changes: 14 additions & 2 deletions Editor/LTCGI_ControllerExternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LTCGI_ControllerEditor : Editor
private static readonly string[] CONFIGURATION_PROPS = new[] {
#if UNITY_STANDALONE
"StaticTextures",
"FastSampling",
#endif
"DynamicRenderers",
"CustomBlurChain",
Expand Down Expand Up @@ -258,12 +259,12 @@ public override void OnInspectorGUI()
bool? forceSet = null;

#if !UNITY_STANDALONE
if (name == "LTCGI_FAST_SAMPLING")
forceSet = true;
if (name == "LTCGI_STATIC_TEXTURES")
forceSet = false;
if (name == "LTCGI_DISABLE_LUT2")
forceSet = true;
if (name == "LTCGI_BLENDED_DIFFUSE_SAMPLING")
forceSet = false;
#endif

if (type == ConfigType.Boolean)
Expand Down Expand Up @@ -444,6 +445,17 @@ public static void RecalculateAutoConfig(LTCGI_Controller controller)
}
}

if (line.EndsWith("#define LTCGI_FAST_SAMPLING"))
{
var enabledInConfig = !line.StartsWith("//");
var available = controller.FastSampling;
if (enabledInConfig != available)
{
config[i] = (available ? "" : "//") + "#define LTCGI_FAST_SAMPLING";
changed = true;
}
}

if (line.EndsWith("#define LTCGI_CYLINDER"))
{
var enabledInConfig = !line.StartsWith("//");
Expand Down
7 changes: 3 additions & 4 deletions Shaders/LTCGI_config.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
/// a bit more with global screen color data. Slight performance cost.
//#define LTCGI_BLENDED_DIFFUSE_SAMPLING

/// Slightly simplified and thus faster sampling for reflections at the cost of quality.
/// Consider using this if your scene looks about the same with this enabled.
//#define LTCGI_FAST_SAMPLING

/// Disable extra specular detail LUT, saves a sampler.
//#define LTCGI_DISABLE_LUT2

Expand Down Expand Up @@ -85,4 +81,7 @@ const float LUT_BIAS = 0.5/LUT_SIZE;
// Activate avatar mode, which overrides certain configs from above.
//#define LTCGI_AVATAR_MODE

// Slightly simplified and thus faster sampling for reflections at the cost of quality.
//#define LTCGI_FAST_SAMPLING

#endif
2 changes: 2 additions & 0 deletions Shaders/LTCGI_functions.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
return;
#endif
}
#ifdef LTCGI_STATIC_TEXTURES
else
{
[forcecase]
Expand Down Expand Up @@ -263,6 +264,7 @@ void LTCGI_sample(float2 uv, uint lod, uint idx, float blend, out float3 result)
return;
}
}
#endif
#endif
}

Expand Down

0 comments on commit 96338db

Please sign in to comment.