summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-03-31 21:20:11 -0700
committeryum <yum.food.vr@gmail.com>2026-03-31 21:20:11 -0700
commit3ee87f52f8979aa166c23fbfc2e310590a416a1e (patch)
tree501ea1d3b9174543557f4d578fe915b12c536522
parente595ed41ef130d9883a9f9a4b9566c285f0abde3 (diff)
Begin work on triplanar projection feature
-rwxr-xr-x3ner.shader40
-rwxr-xr-xScripts/gaussianize36
-rw-r--r--burley.cginc4
-rwxr-xr-xfeatures.cginc14
-rwxr-xr-xglobals.cginc21
-rwxr-xr-xpbr.cginc2
6 files changed, 109 insertions, 8 deletions
diff --git a/3ner.shader b/3ner.shader
index b60eb7d..d5d7815 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -511,6 +511,46 @@ Shader "yum_food/3ner"
//endex
[HideInInspector] m_end_Decals("Decals", Float) = 0
+ [HideInInspector] m_start_Triplanar_Layers("Triplanar Layers", Float) = 0
+ //ifex _Triplanar_Layer0_Enabled==0
+ [HideInInspector] m_start_Triplanar_Layer0("Triplanar Layer 0", Float) = 0
+ [ThryToggle(_TRIPLANAR_LAYER0)] _Triplanar_Layer0_Enabled("Enable", Float) = 0
+ _Triplanar_Layer0_Scale("Scale", Float) = 1
+
+ _Triplanar_Layer0_MainTex("Base color", 2D) = "white" {}
+ [HDR] _Triplanar_Layer0_Color("Tint", Color) = (1, 1, 1, 1)
+
+ //ifex _Triplanar_Layer0_Normal_Enabled==0
+ [HideInInspector] m_start_Triplanar_Layer0_Normal("Normal Map", Float) = 0
+ [ThryToggle(_TRIPLANAR_LAYER0_NORMAL)] _Triplanar_Layer0_Normal_Enabled("Enable", Float) = 0
+ [Normal] _Triplanar_Layer0_Normal("Normal Map", 2D) = "bump" {}
+ _Triplanar_Layer0_Normal_Scale("Scale", Float) = 1
+ [HideInInspector] m_end_Triplanar_Layer0_Normal("Normal Map", Float) = 0
+ //endex
+
+ //ifex _Triplanar_Layer0_Metallic_Gloss_Enabled==0
+ [HideInInspector] m_start_Triplanar_Layer0_Metallic_Gloss("Metallic Gloss", Float) = 0
+ [ThryToggle(_TRIPLANAR_LAYER0_METALLIC_GLOSS)] _Triplanar_Layer0_Metallic_Gloss_Enabled("Enable", Float) = 0
+ _Triplanar_Layer0_Metallic_Gloss("Metallic Gloss", 2D) = "white" {}
+ _Triplanar_Layer0_Metallic("Metallic", Range(0, 1)) = 0
+ _Triplanar_Layer0_Smoothness("Smoothness", Range(0, 1)) = 0.5
+ [HideInInspector] m_end_Triplanar_Layer0_Metallic_Gloss("Metallic Gloss", Float) = 0
+ //endex
+
+ //ifex _Triplanar_Layer0_Burley_Enabled==0
+ [HideInInspector] m_start_Triplanar_Layer0_Burley("Burley/Gaussian Mixing", Float) = 0
+ [ThryToggle(_TRIPLANAR_LAYER0_BURLEY)] _Triplanar_Layer0_Burley_Enabled("Burley/Gaussian Mixing", Float) = 0
+ _Triplanar_Layer0_Burley_Blend_Gamma("Blend Gamma", Range(0, 8)) = 4
+ _Triplanar_Layer0_MainTex_Burley_LUT("Base color LUT", 2D) = "white" {}
+ [Gradient] _Triplanar_Layer0_Normal_Burley_LUT("Normal LUT", 2D) = "white" {}
+ [Gradient] _Triplanar_Layer0_Metallic_Gloss_Burley_LUT("Metallic Gloss LUT", 2D) = "white" {}
+ [HideInInspector] m_end_Triplanar_Layer0_Burley("Burley/Gaussian Mixing", Float) = 0
+ //endex
+
+ [HideInInspector] m_end_Triplanar_Layer0("Triplanar Layer 0", Float) = 0
+ //endex
+ [HideInInspector] m_end_Triplanar_Layers("Triplanar Layers", Float) = 0
+
[HideInInspector] m_start_Matcaps("Matcaps", Float) = 0
//ifex _Matcap0_Enabled==0
[HideInInspector] m_start_Matcap0("Matcap 0", Float) = 0
diff --git a/Scripts/gaussianize b/Scripts/gaussianize
index 620e05d..f997b8a 100755
--- a/Scripts/gaussianize
+++ b/Scripts/gaussianize
@@ -410,20 +410,38 @@ def histogram_preserving_blend(
def verify_histogram(image_path: Path, output_path: Path):
- """Generate a minimal RGB histogram verification figure."""
+ """Generate the original image with an RGB histogram chart beneath it."""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
+ from matplotlib.ticker import MultipleLocator
img = load_image(image_path)
-
- fig = plt.figure(figsize=(4.0, 2.0), facecolor='#bcbcbc')
- plot_ax = fig.add_axes((0.0, 0.0, 1.0, 1.0))
+ h, w, _ = img.shape
+ quantization_step = 0.0 if image_path.suffix.lower() == ".exr" else (1.0 / 255.0)
+
+ # Chart is the full image width, with height proportional to the image
+ chart_height_ratio = 0.25
+ total_height_ratio = 1.0 + chart_height_ratio
+ fig_w = max(w, 2048) / 180.0
+ fig_h = fig_w * total_height_ratio * (h / w)
+
+ fig = plt.figure(figsize=(fig_w, fig_h), facecolor='#bcbcbc')
+
+ # Original image on top
+ img_ax = fig.add_axes((0.0, chart_height_ratio / total_height_ratio, 1.0, 1.0 / total_height_ratio))
+ img_ax.imshow(np.clip(img, 0.0, 1.0))
+ img_ax.set_axis_off()
+
+ # Histogram chart on bottom
+ left_margin = 0.06
+ right_margin = 0.02
+ bottom_margin = 0.04
+ chart_top = chart_height_ratio / total_height_ratio
+ plot_ax = fig.add_axes((left_margin, bottom_margin, 1.0 - left_margin - right_margin, chart_top - bottom_margin))
plot_ax.set_facecolor('#bcbcbc')
for spine in plot_ax.spines.values():
spine.set_visible(False)
- plot_ax.set_xticks([])
- plot_ax.set_yticks([])
kernel = np.array([1.0, 2.0, 3.0, 2.0, 1.0], dtype=np.float64)
kernel /= kernel.sum()
@@ -431,7 +449,8 @@ def verify_histogram(image_path: Path, output_path: Path):
colors = ('#ff1a1a', '#00aa22', '#003cff')
for channel, color in enumerate(colors):
- hist, edges = np.histogram(img[:, :, channel].ravel(), bins=512, range=(0.0, 1.0), density=True)
+ data = dither_channel(img[:, :, channel], quantization_step, channel)
+ hist, edges = np.histogram(data.ravel(), bins=512, range=(0.0, 1.0), density=True)
hist = np.convolve(hist, kernel, mode='same')
centers = 0.5 * (edges[:-1] + edges[1:])
curve_max = max(curve_max, float(hist.max()))
@@ -439,6 +458,9 @@ def verify_histogram(image_path: Path, output_path: Path):
plot_ax.set_xlim(0.0, 1.0)
plot_ax.set_ylim(0.0, curve_max * 1.18 if curve_max > 0.0 else 1.0)
+ plot_ax.xaxis.set_major_locator(MultipleLocator(0.1))
+ plot_ax.tick_params(axis='x', labelsize=5, length=2, pad=1)
+ plot_ax.set_yticks([])
fig.savefig(output_path, dpi=180, facecolor=fig.get_facecolor(), edgecolor='none')
plt.close(fig)
print(f"Saved histogram to {output_path}")
diff --git a/burley.cginc b/burley.cginc
index 1ca870f..539b317 100644
--- a/burley.cginc
+++ b/burley.cginc
@@ -4,7 +4,7 @@
#include "data.cginc"
#include "math.cginc"
-#if defined(_BURLEY_TILING)
+#if defined(_BURLEY_TILING) || defined(TRIPLANAR_BURLEY)
float2 burley_tri_to_cart(float2 tri_coord) {
return float2(
tri_coord.x + tri_coord.y * 0.5f,
@@ -111,7 +111,9 @@ float4 burley_sample_patch(texture2D tex, BurleyPatchTransform patch) {
return tex.SampleGrad(
aniso4_trilinear_repeat_s, patch.uv, patch.dx, patch.dy);
}
+#endif // _BURLEY_TILING || TRIPLANAR_BURLEY
+#if defined(_BURLEY_TILING)
struct BurleyTilingContext {
BurleyPatchTransform patch_0;
BurleyPatchTransform patch_1;
diff --git a/features.cginc b/features.cginc
index 57c2191..99e5593 100755
--- a/features.cginc
+++ b/features.cginc
@@ -251,4 +251,18 @@
#pragma shader_feature_local _BURLEY_TILING_ROTATION_CONSTRAINT
//endex
+//ifex _Triplanar_Layer0_Enabled==0
+#pragma shader_feature_local _TRIPLANAR_LAYER0
+#pragma shader_feature_local _TRIPLANAR_LAYER0_NORMAL
+#pragma shader_feature_local _TRIPLANAR_LAYER0_METALLIC_GLOSS
+#pragma shader_feature_local _TRIPLANAR_LAYER0_BURLEY
+//endex
+
+#if defined(_TRIPLANAR_LAYER0)
+#define TRIPLANAR
+#endif
+#if defined(_TRIPLANAR_LAYER0_BURLEY)
+#define TRIPLANAR_BURLEY
+#endif
+
#endif // __FEATURES_INC
diff --git a/globals.cginc b/globals.cginc
index ded978b..a62d9e5 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -655,4 +655,25 @@ texture2D _Burley_Tiling_Heightmap;
texture2D _Burley_Tiling_Heightmap_LUT;
#endif // _BURLEY_TILING_HEIGHTMAP
+#if defined(_TRIPLANAR_LAYER0)
+texture2D _Triplanar_Layer0_MainTex;
+float _Triplanar_Layer0_Scale;
+
+#if defined(_TRIPLANAR_LAYER0_NORMAL)
+texture2D _Triplanar_Layer0_Normal;
+float _Triplanar_Layer0_Normal_Scale;
+#endif // _TRIPLANAR_LAYER0_NORMAL
+
+#if defined(_TRIPLANAR_LAYER0_METALLIC_GLOSS)
+texture2D _Triplanar_Layer0_Metallic_Gloss;
+#endif // _TRIPLANAR_LAYER0_METALLIC_GLOSS
+
+#if defined(_TRIPLANAR_LAYER0_BURLEY)
+float _Triplanar_Layer0_Burley_Blend_Gamma;
+texture2D _Triplanar_Layer0_MainTex_Burley_LUT;
+texture2D _Triplanar_Layer0_Normal_Burley_LUT;
+texture2D _Triplanar_Layer0_Metallic_Gloss_Burley_LUT;
+#endif // _TRIPLANAR_LAYER0_BURLEY
+#endif // _TRIPLANAR_LAYER0
+
#endif // __GLOBALS_INC
diff --git a/pbr.cginc b/pbr.cginc
index 969e1a3..3e37cea 100755
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -9,6 +9,7 @@
#include "interpolators.cginc"
#include "letter_grid.cginc"
#include "texture_utils.cginc"
+#include "triplanar.cginc"
#if defined(_PARALLAX_HEIGHTMAP_TEXTURE) || defined(_BURLEY_TILING_HEIGHTMAP)
float heightmap_sample(float2 uv) {
@@ -282,6 +283,7 @@ Pbr getPbr(v2f i) {
apply_kintsugi(i.worldPos, pbr.albedo.xyz, pbr.smoothness, pbr.metallic);
apply_letter_grid(i, pbr);
apply_burley_tiling(pbr, normal_tangent);
+ apply_triplanar_layers(i.worldPos, i.normal, pbr, normal_tangent);
applyDecals(i, pbr, normal_tangent);