summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audiolink.cginc3
-rw-r--r--clones.cginc7
-rw-r--r--cnlohr.cginc4
-rw-r--r--eyes.cginc6
-rw-r--r--globals.cginc4
-rw-r--r--halos.cginc6
-rw-r--r--interpolators.cginc8
-rw-r--r--iq_sdf.cginc4
-rw-r--r--math.cginc4
-rw-r--r--pbr.cginc9
-rw-r--r--shader_inliner.cs207
-rw-r--r--tooner.shader2
-rw-r--r--tooner_lighting.cginc8
-rw-r--r--tooner_outline_pass.cginc12
-rw-r--r--tooner_scroll.cginc6
-rw-r--r--trochoid_math.cginc4
16 files changed, 250 insertions, 44 deletions
diff --git a/audiolink.cginc b/audiolink.cginc
index 200c2bc..1147744 100644
--- a/audiolink.cginc
+++ b/audiolink.cginc
@@ -1,5 +1,3 @@
-// Upgrade NOTE: replaced 'defined _AUDIOLINK' with 'defined (_AUDIOLINK)'
-
#ifndef __AUDIOLINK
#define __AUDIOLINK
@@ -8,6 +6,5 @@
#include "Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.cginc"
#endif // _AUDIOLINK
-
#endif // __AUDIOLINK
diff --git a/clones.cginc b/clones.cginc
index fe51f18..00612f3 100644
--- a/clones.cginc
+++ b/clones.cginc
@@ -1,11 +1,11 @@
+#include "interpolators.cginc"
+#include "globals.cginc"
+
#ifndef __CLONES_INC
#define __CLONES_INC
#if defined(_CLONES)
-#include "interpolators.cginc"
-#include "globals.cginc"
-
void add_clones(in v2f clone_verts[3], inout TriangleStream<v2f> tri_out)
{
if (_Clones_dx < 1E-6) {
@@ -34,6 +34,5 @@ void add_clones(in v2f clone_verts[3], inout TriangleStream<v2f> tri_out)
}
#endif // _CLONES
-
#endif // __CLONES_INC
diff --git a/cnlohr.cginc b/cnlohr.cginc
index 4df0ef1..bed117d 100644
--- a/cnlohr.cginc
+++ b/cnlohr.cginc
@@ -1,8 +1,8 @@
+#include "globals.cginc"
+
#ifndef __CNLOHR_INC
#define __CNLOHR_INC
-#include "globals.cginc"
-
/*
* MIT License
*
diff --git a/eyes.cginc b/eyes.cginc
index 3a913b0..f993400 100644
--- a/eyes.cginc
+++ b/eyes.cginc
@@ -1,10 +1,10 @@
-#ifndef __EYES_INC
-#define __EYES_INC
-
#include "globals.cginc"
#include "interpolators.cginc"
#include "iq_sdf.cginc"
+#ifndef __EYES_INC
+#define __EYES_INC
+
#if defined(_GIMMICK_EYES_00)
float eyes00_distance_from_sphere(float3 p, float3 c, float r)
diff --git a/globals.cginc b/globals.cginc
index 4c71a85..64d3410 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -1,8 +1,8 @@
+#include "AutoLight.cginc"
+
#ifndef __GLOBALS_INC
#define __GLOBALS_INC
-#include "AutoLight.cginc"
-
SamplerState linear_repeat_s;
SamplerState linear_clamp_s;
diff --git a/halos.cginc b/halos.cginc
index d2601ab..46c539f 100644
--- a/halos.cginc
+++ b/halos.cginc
@@ -1,10 +1,10 @@
-#ifndef __HALOS_INC
-#define __HALOS_INC
-
#include "globals.cginc"
#include "interpolators.cginc"
#include "math.cginc"
+#ifndef __HALOS_INC
+#define __HALOS_INC
+
#if defined(_GIMMICK_HALO_00)
struct Halo00Params {
float3 period;
diff --git a/interpolators.cginc b/interpolators.cginc
index df645de..3b9bdcd 100644
--- a/interpolators.cginc
+++ b/interpolators.cginc
@@ -1,8 +1,8 @@
+#include "AutoLight.cginc"
+
#ifndef __INTERPOLATORS_INC
#define __INTERPOLATORS_INC
-#include "AutoLight.cginc"
-
#if defined(_OUTLINE_INTERPOLATORS)
struct appdata
@@ -44,7 +44,7 @@ struct v2f
UNITY_VERTEX_OUTPUT_STEREO
};
-#else
+#else // _OUTLINE_INTERPOLATORS
struct appdata
{
@@ -91,7 +91,7 @@ struct v2f
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
-#endif
+#endif // _OUTLINE_INTERPOLATORS
#endif // __INTERPOLATORS_INC
diff --git a/iq_sdf.cginc b/iq_sdf.cginc
index 4d1072e..c728ab5 100644
--- a/iq_sdf.cginc
+++ b/iq_sdf.cginc
@@ -1,8 +1,8 @@
+#include "pema99.cginc"
+
#ifndef __IQ_SDF_INC
#define __IQ_SDF_INC
-#include "pema99.cginc"
-
// The MIT License
// Copyright © 2019-2021 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/math.cginc b/math.cginc
index cf753ac..8938940 100644
--- a/math.cginc
+++ b/math.cginc
@@ -1,8 +1,8 @@
+#include "pema99.cginc"
+
#ifndef __MATH_INC
#define __MATH_INC
-#include "pema99.cginc"
-
float4 qmul(float4 q1, float4 q2)
{
return float4(
diff --git a/pbr.cginc b/pbr.cginc
index b9582a0..3bb6be0 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -1,9 +1,3 @@
-#ifndef __PBR_INC
-#define __PBR_INC
-
-#include "UnityPBSLighting.cginc"
-#include "AutoLight.cginc"
-
#include "globals.cginc"
#include "filament_math.cginc"
#include "globals.cginc"
@@ -11,6 +5,9 @@
#include "MochieStandardBRDF.cginc"
#include "poi.cginc"
+#ifndef __PBR_INC
+#define __PBR_INC
+
#if defined(_LTCGI)
#include "Third_Party/at.pimaker.ltcgi/Shaders/LTCGI_structs.cginc"
diff --git a/shader_inliner.cs b/shader_inliner.cs
new file mode 100644
index 0000000..6bfb5a3
--- /dev/null
+++ b/shader_inliner.cs
@@ -0,0 +1,207 @@
+// !! AI ARTIFACT !!
+// This code was originally generated by Claude 3.5 Sonnet.
+// I wanted to write this tooling like I want a fucking hole in the head so I
+// kindly asked Claude to write it for me. It's shitty and poorly designed, but
+// it works well enough for my purposes.
+// It has been slightly tweaked by me, and validated on *this* codebase. It is
+// provided with no warranty.
+using UnityEngine;
+using UnityEditor;
+using System.IO;
+using System.Text.RegularExpressions;
+using System.Collections.Generic;
+using System.Linq;
+
+public class ShaderInliner : EditorWindow
+{
+ private string inputShaderPath;
+ private string outputShaderPath;
+
+ [MenuItem("Tools/yum_food/Shader Inliner")]
+ public static void ShowWindow()
+ {
+ GetWindow<ShaderInliner>("Shader Inliner");
+ }
+
+ private void OnGUI()
+ {
+ GUILayout.Label("Shader Inliner", EditorStyles.boldLabel);
+
+ inputShaderPath = EditorGUILayout.TextField("Input Shader Path", inputShaderPath);
+ if (GUILayout.Button("Select Input Shader"))
+ {
+ inputShaderPath = EditorUtility.OpenFilePanel("Select Shader", "", "shader");
+ }
+
+ if (GUILayout.Button("Inline Shader"))
+ {
+ if (string.IsNullOrEmpty(inputShaderPath))
+ {
+ EditorUtility.DisplayDialog("Error", "Please select an input shader.", "OK");
+ return;
+ }
+
+ InlineShader();
+ }
+ }
+
+ private void InlineShader()
+ {
+ string shaderContent = File.ReadAllText(inputShaderPath);
+ string inlinedShader = ProcessShader(shaderContent, Path.GetDirectoryName(inputShaderPath));
+
+ string fileName = Path.GetFileNameWithoutExtension(inputShaderPath);
+ outputShaderPath = Path.Combine(Path.GetDirectoryName(inputShaderPath), $"{fileName}_inlined.shader");
+ File.WriteAllText(outputShaderPath, inlinedShader);
+
+ AssetDatabase.Refresh();
+ EditorUtility.DisplayDialog("Success", $"Inlined shader saved to:\n{outputShaderPath}", "OK");
+ }
+
+ private string ProcessShader(string content, string basePath)
+ {
+ // Update shader name
+ content = Regex.Replace(content, @"Shader\s+""(.+?)""", match =>
+ {
+ string shaderName = match.Groups[1].Value;
+ return $"Shader \"{shaderName}_inlined\"";
+ });
+
+ // Process each Pass independently
+ content = Regex.Replace(content, @"(CGPROGRAM.*?ENDCG)", match =>
+ {
+ return ProcessPass(match.Value, basePath);
+ }, RegexOptions.Singleline);
+
+ // Check for mismatched preprocessor macros in the entire shader
+ CheckMismatchedMacros(content);
+
+ return content;
+ }
+
+ private string ProcessPass(string passContent, string basePath)
+ {
+ HashSet<string> includedFiles = new HashSet<string>();
+
+ string pattern = @"#include\s+""(.+?)""";
+ return Regex.Replace(passContent, pattern, match =>
+ {
+ string includePath = match.Groups[1].Value;
+ string fullPath = Path.Combine(basePath, includePath);
+
+ if (File.Exists(fullPath))
+ {
+ if (!includedFiles.Contains(fullPath))
+ {
+ includedFiles.Add(fullPath);
+ string includeContent = File.ReadAllText(fullPath);
+ return ProcessInclude(includeContent, Path.GetDirectoryName(fullPath), includedFiles);
+ }
+ else
+ {
+ return "// Already included in this pass: " + includePath;
+ }
+ }
+ else
+ {
+ Debug.LogWarning($"Include file not found: {fullPath}");
+ return match.Value;
+ }
+ });
+ }
+
+ private string ProcessInclude(string content, string basePath, HashSet<string> includedFiles)
+ {
+ string pattern = @"#include\s+""(.+?)""";
+ return Regex.Replace(content, pattern, match =>
+ {
+ string includePath = match.Groups[1].Value;
+ string fullPath = Path.Combine(basePath, includePath);
+
+ if (File.Exists(fullPath))
+ {
+ if (!includedFiles.Contains(fullPath))
+ {
+ includedFiles.Add(fullPath);
+ string includeContent = File.ReadAllText(fullPath);
+ return ProcessInclude(includeContent, Path.GetDirectoryName(fullPath), includedFiles);
+ }
+ else
+ {
+ return "// Already included in this pass: " + includePath;
+ }
+ }
+ else
+ {
+ Debug.LogWarning($"Include file not found: {fullPath}");
+ return match.Value;
+ }
+ });
+ }
+
+ private void CheckMismatchedMacros(string content)
+ {
+ var stack = new Stack<string>();
+ var lines = content.Split('\n');
+ var macroPattern = @"^\s*#(if|ifdef|ifndef|elif|else|endif|if\s+defined)";
+
+ for (int i = 0; i < lines.Length; i++)
+ {
+ var line = lines[i].Trim();
+ var match = Regex.Match(line, macroPattern);
+
+ if (match.Success)
+ {
+ var directive = match.Groups[1].Value;
+
+ switch (directive)
+ {
+ case "if":
+ case "ifdef":
+ case "ifndef":
+ case "if defined":
+ stack.Push(directive);
+ break;
+ case "elif":
+ if (stack.Count == 0 || (stack.Peek() != "if" && stack.Peek() != "elif"))
+ {
+ Debug.LogError($"Mismatched #elif at line {i + 1}");
+ }
+ else
+ {
+ stack.Pop();
+ stack.Push("elif");
+ }
+ break;
+ case "else":
+ if (stack.Count == 0 || (stack.Peek() != "if" && stack.Peek() != "elif"))
+ {
+ Debug.LogError($"Mismatched #else at line {i + 1}");
+ }
+ else
+ {
+ stack.Pop();
+ stack.Push("else");
+ }
+ break;
+ case "endif":
+ if (stack.Count == 0)
+ {
+ Debug.LogError($"Mismatched #endif at line {i + 1}");
+ }
+ else
+ {
+ stack.Pop();
+ }
+ break;
+ }
+ }
+ }
+
+ if (stack.Count > 0)
+ {
+ Debug.LogError($"Unclosed preprocessor directives: {string.Join(", ", stack)}");
+ }
+ }
+}
+
diff --git a/tooner.shader b/tooner.shader
index 57759a7..47043ca 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -3,7 +3,7 @@ Shader "yum_food/tooner"
// Unity fucking sucks ass and sometimes incorrectly uses an old cached
// version of the shader. Bump the nonce below to encourage it to use the
// current version.
- // Build nonce: 29
+ // Build nonce: 31
Properties
{
_Color("Base color", Color) = (0.8, 0.8, 0.8, 1)
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 80e8400..970a965 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -1,7 +1,6 @@
-#ifndef TOONER_LIGHTING
-#define TOONER_LIGHTING
-
#include "UnityCG.cginc"
+#include "AutoLight.cginc"
+#include "UnityPBSLighting.cginc"
#include "audiolink.cginc"
#include "clones.cginc"
@@ -20,6 +19,9 @@
#include "trochoid_math.cginc"
#include "oklab.cginc"
+#ifndef TOONER_LIGHTING
+#define TOONER_LIGHTING
+
// Hacky parameterizable whiteout blending. Probably some big mistakes but it
// passes the eyeball test.
// At w=0.5, this looks kinda like whiteout blending.
diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc
index 1c20c4a..52931d8 100644
--- a/tooner_outline_pass.cginc
+++ b/tooner_outline_pass.cginc
@@ -1,7 +1,6 @@
-#ifndef __TOONER_OUTLINE_PASS
-#define __TOONER_OUTLINE_PASS
-
-#define _OUTLINE_INTERPOLATORS
+#include "UnityCG.cginc"
+#include "AutoLight.cginc"
+#include "UnityPBSLighting.cginc"
#include "audiolink.cginc"
#include "clones.cginc"
@@ -14,6 +13,11 @@
#include "tooner_scroll.cginc"
#include "UnityCG.cginc"
+#ifndef __TOONER_OUTLINE_PASS
+#define __TOONER_OUTLINE_PASS
+
+#define _OUTLINE_INTERPOLATORS
+
v2f vert(appdata v)
{
#if defined(_DISCARD)
diff --git a/tooner_scroll.cginc b/tooner_scroll.cginc
index 1fd29cb..4c58512 100644
--- a/tooner_scroll.cginc
+++ b/tooner_scroll.cginc
@@ -1,10 +1,10 @@
-#ifndef __TOONER_SCROLL
-#define __TOONER_SCROLL
-
#include "globals.cginc"
#include "math.cginc"
#include "pema99.cginc"
+#ifndef __TOONER_SCROLL
+#define __TOONER_SCROLL
+
#if 0
float _Scroll_Toggle;
float _Scroll_Top;
diff --git a/trochoid_math.cginc b/trochoid_math.cginc
index f116db0..334b14e 100644
--- a/trochoid_math.cginc
+++ b/trochoid_math.cginc
@@ -1,10 +1,10 @@
+#include "globals.cginc"
+
#ifndef __TROCHOID_MATH
#define __TROCHOID_MATH
#if defined(_TROCHOID)
-#include "globals.cginc"
-
#define PI 3.14159265
#define TAU PI * 2.0