PBR StudyEuropean 4-in-1 riveted iron maille rings with accurate over-under interlocking and specular glints.
heat-tempered-oxide-steel.glsl · 745 lines · GLSL ES 3.00 · MIT
#version 300 es
// Heat-Tempered Oxide Steel (heat-tempered-oxide-steel.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/thermal/lib/02_steel_heat_tempering_oxide_band.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float), uOpen (0..1), uLightMode (0..3), uCamMode (0..1)
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;
out vec4 fragColor;
// ============================================================================
// 02 — Steel Heat-Tempering Thin-Film Iron-Oxide Band
// Machined chamfered carbon-steel specimen resting on a refractory ceramic
// firebrick plinth and studio bench. Heated at one end to reveal the physically
// ordered iron-oxide interference spectrum (silver -> pale straw -> golden
// bronze -> crimson-purple -> peacock violet-blue -> slate gray) with
// anisotropic brushed GGX reflectance and heat-scale pitting at the hot tip.
// ============================================================================
const float PI = 3.14159265359;
const float INV_PI = 0.31830988618;
// ----------------------------------------------------------------------------
// Deterministic Hashes & Procedural Noise
// ----------------------------------------------------------------------------
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(13.7, 7.3);
a *= 0.5;
}
return v;
}
float voronoiPit(vec2 p) {
vec2 n = floor(p);
vec2 f = fract(p);
float dMin = 8.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 o = hash22(n + g);
vec2 r = g + o - f;
float d = dot(r, r);
dMin = min(dMin, d);
}
}
return sqrt(dMin);
}
// ----------------------------------------------------------------------------
// Bar & Firebrick Coordinate Frame
// Bar is gently angled in XZ for a dynamic 3/4 sculptural studio composition.
// Local coordinates:
// bx in [-1.18, +1.18] (hot tip at -x, cool machined end at +x)
// by in [0.0, 0.24] (resting on firebrick top at y = 0.14)
// bz in [-0.30, +0.30]
// ----------------------------------------------------------------------------
const float BAR_ANGLE = -0.22;
const float BRICK_H = 0.14;
mat2 rot2(float a) {
float c = cos(a);
float s = sin(a);
return mat2(c, -s, s, c);
}
vec3 toBarLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H + 0.125, 0.0);
q.xz = rot2(-BAR_ANGLE) * q.xz;
return q;
}
vec3 toBrickLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H * 0.5, 0.0);
q.xz = rot2(-BAR_ANGLE * 0.55) * q.xz;
return q;
}
// ----------------------------------------------------------------------------
// SDF Primitives
// ----------------------------------------------------------------------------
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// Chamfered rectangular prism: 45-degree bevels on all 12 edges with tiny
// machined edge radius so specular highlights catch cleanly along every bevel.
float sdChamferBox(vec3 p, vec3 b, float ch, float r) {
vec3 q = abs(p) - b;
float dBox = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
float cXY = (q.x + q.y + ch) * 0.70710678;
float cYZ = (q.y + q.z + ch) * 0.70710678;
float cXZ = (q.x + q.z + ch) * 0.70710678;
float dOct = max(cXY, max(cYZ, cXZ));
float d = max(dBox, dOct);
return d - r;
}
// Smooth boolean ops
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
// ----------------------------------------------------------------------------
// Specimen Geometry (Steel Bar + Refractory Ceramic Firebrick Plinth)
// ----------------------------------------------------------------------------
float mapSteelBar(vec3 p) {
vec3 q = toBarLocal(p);
// Main precision-machined chamfered bar: 2.36 x 0.25 x 0.60
float d = sdChamferBox(q, vec3(1.18, 0.120, 0.295), 0.036, 0.0045);
// Subtle machined thermocouple / specimen index bore near the cool end (+x)
vec2 boreP = q.xz - vec2(0.95, 0.0);
float dBore = length(boreP) - 0.068;
// Countersink chamfer at top of bore
float dCountersink = length(boreP) - (0.068 + max(0.0, q.y - 0.088) * 0.95);
float dHole = min(dBore, dCountersink);
d = smax(d, -dHole, 0.004);
// Subtle transverse witness graduation grooves near cool end (specimen scale marks)
float gx = q.x - 0.56;
if (abs(gx) < 0.18 && q.y > 0.08 && abs(q.z) < 0.255) {
float rep = mod(gx + 0.04, 0.08) - 0.04;
float groove = max(abs(rep) - 0.0032, -(q.y - 0.119));
d = max(d, -groove * 0.45);
}
// Subtle heat-scale pitting relief at the hottest tip (q.x < -0.78)
float tipMask = smoothstep(-0.76, -1.06, q.x);
if (tipMask > 0.001) {
float pit = voronoiPit(q.xz * 26.0 + vec2(q.y * 18.0, 3.1));
float micro = fbm2(q.xz * 19.0 + q.y * 9.0);
float pitDepth = smoothstep(0.36, 0.08, pit) * 0.0032 + (micro - 0.5) * 0.0014;
d += pitDepth * tipMask;
}
return d;
}
float mapFirebrick(vec3 p) {
vec3 q = toBrickLocal(p);
// Low refractory ceramic firebrick support plinth resting cleanly on y = 0
float d = sdChamferBox(q, vec3(1.42, BRICK_H * 0.5 - 0.004, 0.52), 0.018, 0.004);
// Subtle refractory ceramic surface undulation / hand-pressed kiln texture
float kiln = (fbm2(q.xz * 6.5 + vec2(2.1, -1.4)) - 0.5) * 0.0022;
d += kiln;
return d;
}
// Hero-only SDF (for clean soft shadow & hero/bench classification)
float mapHero(vec3 p) {
return min(mapSteelBar(p), mapFirebrick(p));
}
// Full scene SDF including studio bench at y = 0
float mapScene(vec3 p) {
return min(p.y, mapHero(p));
}
// Unit-weight tetrahedral normal (zero-bug rule 1)
vec3 calcNormal(vec3 p) {
const vec2 k = vec2(1.0, -1.0);
const float h = 0.0007;
return normalize(
k.xyy * mapScene(p + k.xyy * h) +
k.yyx * mapScene(p + k.yyx * h) +
k.yxy * mapScene(p + k.yxy * h) +
k.xxx * mapScene(p + k.xxx * h)
);
}
// Clean hero-only soft shadow (zero-bug rule 3: res = min(res, k*h/t), no ph)
float calcSoftShadow(vec3 ro, vec3 rd, float tMax, float k) {
float res = 1.0;
float t = 0.025;
for (int i = 0; i < 48; i++) {
float h = mapHero(ro + rd * t);
if (h < 0.0006) return 0.0;
res = min(res, k * h / t);
t += max(h, 0.015);
if (t > tMax) break;
}
return clamp(res, 0.0, 1.0);
}
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 5; i++) {
float h = 0.014 + 0.036 * float(i);
float d = mapScene(p + n * h);
occ += (h - d) * sca;
sca *= 0.72;
}
return clamp(1.0 - 2.3 * occ, 0.18, 1.0);
}
// ----------------------------------------------------------------------------
// Thin-Film Iron-Oxide Tempering Spectrum
// Physically ordered bands along the thermal gradient:
// 0.00 - 0.18 : Bright machined silver carbon steel
// 0.18 - 0.34 : Pale straw (~220 C)
// 0.34 - 0.50 : Golden bronze / amber (~250 C)
// 0.50 - 0.64 : Crimson-purple (~280 C)
// 0.64 - 0.78 : Peacock violet-blue (~300 C)
// 0.78 - 0.90 : Slate blue-gray (~340 C)
// 0.90 - 1.00 : Dark heat-scale slate / oxidized tip (>400 C)
// Includes subtle viewing-angle thin-film interference phase shift.
// ----------------------------------------------------------------------------
vec3 oxideSpectrum(float heatCoord, float NdotV) {
// Thin-film refraction angle factor (iron oxide n ~ 2.40)
float sin2i = max(0.0, 1.0 - NdotV * NdotV);
float cosT = sqrt(max(0.15, 1.0 - sin2i / (2.40 * 2.40)));
// Optical thickness shifts slightly with grazing angle (authentic iridescent shift)
float s = clamp(heatCoord * (0.86 + 0.16 * cosT), 0.0, 1.0);
// Physically ordered color stops (linear RGB metallic F0 reflectance)
vec3 cSilver = vec3(0.76, 0.78, 0.81); // Bare machined carbon steel
vec3 cStraw = vec3(0.84, 0.74, 0.44); // Pale straw (220 C)
vec3 cBronze = vec3(0.68, 0.37, 0.12); // Golden bronze / warm copper-amber (250 C)
vec3 cCrimson = vec3(0.46, 0.11, 0.28); // Crimson-purple (280 C)
vec3 cPeacock = vec3(0.11, 0.24, 0.62); // Peacock violet-blue (300 C)
vec3 cSlate = vec3(0.28, 0.33, 0.39); // Slate blue-gray (340 C)
vec3 cScale = vec3(0.16, 0.17, 0.19); // Dark heat-scale oxide tip (>400 C)
vec3 col = cSilver;
col = mix(col, cStraw, smoothstep(0.10, 0.25, s));
col = mix(col, cBronze, smoothstep(0.26, 0.42, s));
col = mix(col, cCrimson, smoothstep(0.42, 0.56, s));
col = mix(col, cPeacock, smoothstep(0.56, 0.71, s));
col = mix(col, cSlate, smoothstep(0.71, 0.85, s));
col = mix(col, cScale, smoothstep(0.85, 0.97, s));
// Subtle analytic Airy interference modulation for extra iridescent shimmer
float opd = s * 520.0 * cosT;
vec3 airy = 0.5 + 0.5 * cos(2.0 * PI * opd / vec3(635.0, 540.0, 455.0) + vec3(0.0, 0.4, 0.9));
float bandStrength = smoothstep(0.08, 0.22, s) * (1.0 - smoothstep(0.76, 0.94, s));
col *= mix(vec3(1.0), 0.84 + 0.32 * airy, bandStrength * 0.42);
return col;
}
// Compute thermal progress parameter [0 = cool silver, 1 = hottest scaled tip]
// uOpen (0..1) advances the thermal tempering front smoothly down the bar.
float computeThermalCoord(vec3 qBar) {
// Base coordinate from cool end (+1.18) to hot tip (-1.18)
float u = clamp((1.18 - qBar.x) / 2.36, 0.0, 1.0);
// Physical isotherm curvature: bar edges/chamfers heat slightly faster than core
float edgeLead = 0.042 * (qBar.z * qBar.z / (0.295 * 0.295)) + 0.015 * max(0.0, qBar.y / 0.12);
// Subtle metallurgical grain / heat-flow waviness
float waviness = (fbm2(vec2(qBar.x * 3.8, qBar.z * 5.2) + vec2(1.7, -0.9)) - 0.5) * 0.048;
float uEff = u + edgeLead + waviness;
// uOpen = 0.0 -> tempering front reaches ~58% along bar (full rainbow already visible)
// uOpen = 1.0 -> tempering front advances down to ~92% along bar
float openShift = mix(-0.18, 0.22, clamp(uOpen, 0.0, 1.0));
float front = smoothstep(0.14 - openShift, 0.96 - openShift * 0.45, uEff);
return clamp(front, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Environment Map (Softboxes + Negative-Fill Flags)
// ----------------------------------------------------------------------------
vec3 sampleStudioEnv(vec3 dir, int lightMode) {
vec3 d = normalize(dir);
float y = d.y;
// Smooth studio cyclorama base (no pure black)
vec3 skyLow = vec3(0.055, 0.058, 0.064);
vec3 skyMid = vec3(0.125, 0.132, 0.145);
vec3 skyHigh = vec3(0.185, 0.195, 0.215);
vec3 env = mix(skyLow, skyMid, smoothstep(-0.25, 0.18, y));
env = mix(env, skyHigh, smoothstep(0.18, 0.85, y));
if (lightMode == 1) {
// Pure neutral grayscale studio environment
float lum = dot(env, vec3(0.2126, 0.7152, 0.0722));
env = vec3(lum);
}
// 1) Main overhead elongated diffuser softbox (sweeps crisp specular across bar)
vec3 sb1Dir = normalize(vec3(0.15, 0.90, 0.38));
if (lightMode == 2) sb1Dir = normalize(vec3(-0.78, 0.22, 0.58)); // Grazing raking strip
if (lightMode == 3) sb1Dir = normalize(vec3(-0.12, 0.48, -0.87)); // Backlit overhead rim strip
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 s1R = normalize(cross(up, sb1Dir));
vec3 s1U = cross(sb1Dir, s1R);
float u1 = dot(d, s1R);
float v1 = dot(d, s1U);
float f1 = dot(d, sb1Dir);
float box1 = smoothstep(0.52, 0.36, abs(u1)) * smoothstep(0.26, 0.14, abs(v1)) * smoothstep(0.2, 0.45, f1);
vec3 c1 = (lightMode == 1) ? vec3(2.4) :
(lightMode == 2) ? vec3(2.9, 2.75, 2.55) :
(lightMode == 3) ? vec3(3.1, 3.05, 2.95) :
vec3(2.65, 2.55, 2.40);
env += c1 * box1;
// 2) Secondary cool fill softbox (opposite side for metallic contrast)
vec3 sb2Dir = normalize(vec3(-0.72, 0.52, 0.46));
if (lightMode == 2) sb2Dir = normalize(vec3(0.82, 0.35, -0.45));
if (lightMode == 3) sb2Dir = normalize(vec3(0.65, 0.40, -0.64));
float fillMask = pow(max(0.0, dot(d, sb2Dir)), 7.0);
vec3 c2 = (lightMode == 1) ? vec3(1.15) : vec3(1.10, 1.24, 1.48);
env += c2 * fillMask;
// 3) Warm low accent bounce card (brings out bevels and straw/bronze tones)
vec3 sb3Dir = normalize(vec3(0.68, 0.24, 0.69));
float warmCard = pow(max(0.0, dot(d, sb3Dir)), 10.0);
vec3 c3 = (lightMode == 1) ? vec3(0.75) : vec3(1.15, 0.96, 0.74);
env += c3 * warmCard * ((lightMode == 3) ? 0.35 : 0.85);
// 4) Negative-fill black flags (sculptural dark reflection bands on metal)
vec3 nf1Dir = normalize(vec3(-0.35, 0.42, 0.84));
vec3 nf2Dir = normalize(vec3(0.84, 0.32, -0.44));
float flag1 = smoothstep(0.74, 0.92, dot(d, nf1Dir));
float flag2 = smoothstep(0.78, 0.94, dot(d, nf2Dir));
env *= (1.0 - 0.72 * flag1) * (1.0 - 0.68 * flag2);
// Subtle ground bounce below horizon
float groundBounce = smoothstep(0.05, -0.35, y);
vec3 gCol = (lightMode == 1) ? vec3(0.075) : vec3(0.082, 0.074, 0.068);
env = mix(env, gCol, groundBounce * 0.75);
return env;
}
// ----------------------------------------------------------------------------
// Anisotropic GGX BRDF (Burley / Heitz formulation)
// ----------------------------------------------------------------------------
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float ax, float ay) {
float a2 = ax * ay;
vec3 v = vec3(ay * TdotH, ax * BdotH, a2 * NdotH);
float v2 = dot(v, v);
float w2 = a2 / max(v2, 1e-6);
return a2 * w2 * w2 * INV_PI;
}
float V_SmithGGX_Aniso(float NdotV, float NdotL, float TdotV, float BdotV, float TdotL, float BdotL, float ax, float ay) {
float lambdaV = NdotL * length(vec3(ax * TdotV, ay * BdotV, NdotV));
float lambdaL = NdotV * length(vec3(ax * TdotL, ay * BdotL, NdotL));
return 0.5 / max(lambdaV + lambdaL, 1e-5);
}
vec3 F_Schlick(float VdotH, vec3 F0) {
float f = pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
return F0 + (1.0 - F0) * f;
}
vec3 evalAnisoPBR(
vec3 N, vec3 V, vec3 L, vec3 T, vec3 B,
vec3 albedo, vec3 F0, float metallic, float ax, float ay, vec3 lightCol
) {
float NdotL = max(dot(N, L), 0.0);
float NdotV = max(dot(N, V), 1e-4);
if (NdotL <= 0.0) return vec3(0.0);
vec3 H = normalize(V + L);
float NdotH = max(dot(N, H), 0.0);
float VdotH = max(dot(V, H), 0.0);
float TdotH = dot(T, H);
float BdotH = dot(B, H);
float TdotV = dot(T, V);
float BdotV = dot(B, V);
float TdotL = dot(T, L);
float BdotL = dot(B, L);
float D = D_GGX_Aniso(NdotH, TdotH, BdotH, ax, ay);
float Vis = V_SmithGGX_Aniso(NdotV, NdotL, TdotV, BdotV, TdotL, BdotL, ax, ay);
vec3 F = F_Schlick(VdotH, F0);
vec3 spec = D * Vis * F;
vec3 kD = (vec3(1.0) - F) * (1.0 - metallic);
vec3 diff = kD * albedo * INV_PI;
return (diff + spec) * lightCol * NdotL;
}
// ----------------------------------------------------------------------------
// ACES Filmic Tone Mapping
// ----------------------------------------------------------------------------
vec3 acesToneMap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Lighting Rig
// ----------------------------------------------------------------------------
void getLights(
int lightMode,
out vec3 L1, out vec3 C1,
out vec3 L2, out vec3 C2,
out vec3 L3, out vec3 C3
) {
if (lightMode == 1) {
// Pure neutral grayscale lighting
L1 = normalize(vec3(0.45, 0.82, 0.55));
C1 = vec3(2.85);
L2 = normalize(vec3(-0.72, 0.48, 0.50));
C2 = vec3(1.15);
L3 = normalize(vec3(-0.18, 0.52, -0.83));
C3 = vec3(0.95);
} else if (lightMode == 2) {
// Grazing raking key to accentuate brushed anisotropy & heat-scale pitting
L1 = normalize(vec3(-0.88, 0.21, 0.42));
C1 = vec3(3.60, 3.35, 3.05);
L2 = normalize(vec3(0.75, 0.34, 0.56));
C2 = vec3(0.85, 0.96, 1.15);
L3 = normalize(vec3(0.10, 0.45, -0.88));
C3 = vec3(0.75, 0.80, 0.90);
} else if (lightMode == 3) {
// Backlit rim light
L1 = normalize(vec3(-0.22, 0.50, -0.84));
C1 = vec3(4.10, 3.95, 3.75);
L2 = normalize(vec3(0.72, 0.36, -0.59));
C2 = vec3(1.55, 1.65, 1.85);
L3 = normalize(vec3(0.28, 0.42, 0.86));
C3 = vec3(0.55, 0.58, 0.65);
} else {
// Hero museum studio rig
L1 = normalize(vec3(0.42, 0.80, 0.43));
C1 = vec3(3.05, 2.92, 2.75);
L2 = normalize(vec3(-0.76, 0.48, 0.44));
C2 = vec3(1.05, 1.20, 1.42);
L3 = normalize(vec3(-0.15, 0.54, -0.83));
C3 = vec3(1.15, 1.12, 1.08);
}
}
// ----------------------------------------------------------------------------
// Main Render
// ----------------------------------------------------------------------------
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera setup: 0 = Hero 3/4 view, 1 = ~2.5x Macro on tempering oxide band
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
// ~2.5x macro focused on the iridescent tempering band transition zone
float macroShift = mix(-0.28, 0.14, clamp(uOpen, 0.0, 1.0));
vec2 targetXZ = rot2(BAR_ANGLE) * vec2(macroShift, 0.0);
ta = vec3(targetXZ.x, BRICK_H + 0.16, targetXZ.y);
ro = ta + vec3(0.28, 0.68, 1.18);
fov = 1.95;
} else {
// Hero museum specimen view
ta = vec3(0.02, BRICK_H + 0.11, 0.0);
ro = vec3(0.32, 1.38, 2.68);
fov = 1.62;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
// Raymarch scene
float t = 0.0;
float tMax = 16.0;
bool hit = false;
for (int i = 0; i < 120; i++) {
vec3 p = ro + rd * t;
float d = mapScene(p);
if (d < 0.00055) {
hit = true;
break;
}
t += d;
if (t > tMax) break;
}
// Background studio cyclorama
vec3 bg = sampleStudioEnv(rd, uLightMode) * 0.58;
// Soft vignette on backdrop
float vig = 1.0 - 0.18 * dot(uv, uv);
vec3 col = bg * vig;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float dHero = mapHero(p);
// Zero-bug rule 2: exact bench classification
bool isBench = (p.y <= dHero + 0.001);
// Determine if steel bar vs ceramic firebrick plinth
float dBar = mapSteelBar(p);
float dBrick = mapFirebrick(p);
bool isSteel = (!isBench) && (dBar <= dBrick + 0.001);
// Construct anisotropic tangent frame
vec3 T, B;
if (isSteel) {
// Bar longitudinal axis in world space (direction of machined brushing)
vec2 axXZ = rot2(BAR_ANGLE) * vec2(1.0, 0.0);
vec3 barAxis = vec3(axXZ.x, 0.0, axXZ.y);
T = normalize(barAxis - N * dot(barAxis, N));
if (length(barAxis - N * dot(barAxis, N)) < 0.05) {
vec2 sideXZ = rot2(BAR_ANGLE) * vec2(0.0, 1.0);
T = normalize(vec3(sideXZ.x, 0.0, sideXZ.y));
}
B = normalize(cross(N, T));
} else {
vec3 upRef = (abs(N.y) < 0.99) ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
T = normalize(cross(upRef, N));
B = cross(N, T);
}
// Material parameters
vec3 albedo = vec3(0.18);
vec3 F0 = vec3(0.04);
float metallic = 0.0;
float ax = 0.45;
float ay = 0.45;
vec3 Nshade = N;
if (isSteel) {
vec3 qBar = toBarLocal(p);
float heatCoord = computeThermalCoord(qBar);
// Longitudinal brushed steel micro-grooves
float brush1 = vnoise2(vec2(qBar.x * 16.0, qBar.z * 260.0 + qBar.y * 220.0));
float brush2 = vnoise2(vec2(qBar.x * 42.0, qBar.z * 520.0 + qBar.y * 440.0));
float brush = (brush1 * 0.65 + brush2 * 0.35) - 0.5;
// Fine transverse chatter on chamfers/end-faces
float isEnd = smoothstep(0.75, 0.95, abs(dot(N, vec3(rot2(BAR_ANGLE) * vec2(1.0, 0.0), 0.0))));
float endMill = (vnoise2(vec2(qBar.z * 140.0, qBar.y * 140.0)) - 0.5) * isEnd;
// Heat-scale pitting at hottest tip
float scaleZone = smoothstep(0.78, 0.97, heatCoord);
float pitCell = voronoiPit(qBar.xz * 34.0 + vec2(qBar.y * 24.0, 1.9));
float pitMask = smoothstep(0.32, 0.10, pitCell) * scaleZone;
float flake = fbm2(qBar.xz * 28.0 + qBar.y * 14.0);
// Perturb normal slightly for brushed grooves and heat-scale pits
float grooveAmp = mix(0.055, 0.025, scaleZone);
Nshade = normalize(
N +
B * (brush * grooveAmp + endMill * 0.04) +
T * ((flake - 0.5) * 0.11 * scaleZone) +
B * ((pitCell - 0.45) * 0.14 * pitMask)
);
// Re-orthogonalize tangent frame to perturbed normal
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
float NdotV = max(dot(Nshade, V), 0.001);
// Thin-film iron oxide reflectance
vec3 oxCol = oxideSpectrum(heatCoord, NdotV);
// Subtle micro-variation from brushed grain
oxCol *= (0.94 + 0.12 * brush1);
// Darken inside heat-scale pits
oxCol = mix(oxCol, vec3(0.09, 0.095, 0.105), pitMask * 0.72);
if (uLightMode == 1) {
// Pure neutral grayscale albedo/F0 in LightMode 1
oxCol = vec3(0.68) * (0.94 + 0.12 * brush1);
oxCol = mix(oxCol, vec3(0.24), pitMask * 0.65);
}
metallic = mix(0.96, 0.52, scaleZone * (0.45 + 0.55 * pitMask));
albedo = mix(oxCol * 0.18, oxCol * 0.45, scaleZone);
F0 = mix(vec3(0.06), oxCol, metallic);
// Anisotropic roughness: smoother along longitudinal brush direction (ax),
// wider specular streak across brush lines (ay)
float baseAx = mix(0.11, 0.48, scaleZone) + pitMask * 0.22;
float baseAy = mix(0.34, 0.58, scaleZone) + pitMask * 0.18;
ax = clamp(baseAx + brush * 0.03, 0.07, 0.75);
ay = clamp(baseAy + brush * 0.05, 0.14, 0.85);
} else if (!isBench) {
// Refractory ceramic firebrick plinth (porous alumina-silicate firebrick)
vec3 qBrick = toBrickLocal(p);
float grain = fbm2(qBrick.xz * 22.0 + qBrick.y * 14.0);
float pores = voronoiPit(qBrick.xz * 58.0 + qBrick.y * 32.0);
float poreMask = smoothstep(0.24, 0.08, pores);
// Subtle thermal scorch / heat-halo on the firebrick beneath the hot tip
vec3 qBar = toBarLocal(p);
float hotDist = length((qBar.xz - vec2(-0.88, 0.0)) * vec2(0.85, 1.35));
float scorch = smoothstep(0.68, 0.12, hotDist) * smoothstep(-0.02, 0.05, qBrick.y);
vec3 brickCol = mix(vec3(0.38, 0.34, 0.29), vec3(0.49, 0.44, 0.37), grain);
brickCol *= (1.0 - 0.26 * poreMask);
brickCol = mix(brickCol, vec3(0.16, 0.14, 0.13), scorch * 0.58);
if (uLightMode == 1) {
float lum = dot(brickCol, vec3(0.2126, 0.7152, 0.0722));
brickCol = vec3(lum);
}
// Micro-bump for porous refractory clay
vec2 gOff = vec2(0.015, 0.0);
float gx = fbm2((qBrick.xz + gOff.xy) * 32.0) - fbm2((qBrick.xz - gOff.xy) * 32.0);
float gz = fbm2((qBrick.xz + gOff.yx) * 32.0) - fbm2((qBrick.xz - gOff.yx) * 32.0);
Nshade = normalize(N + vec3(gx, 0.0, gz) * 0.22);
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
albedo = brickCol;
F0 = vec3(0.035);
metallic = 0.0;
ax = 0.78 + poreMask * 0.14;
ay = ax;
} else {
// Studio bench surface at y = 0 (matte dark architectural slate / lab bench)
float benchTex = fbm2(p.xz * 2.8);
float fineTex = vnoise2(p.xz * 28.0);
vec3 benchCol = mix(vec3(0.068, 0.072, 0.078), vec3(0.098, 0.102, 0.108), benchTex);
benchCol *= (0.95 + 0.10 * fineTex);
// Radial falloff on bench so it blends smoothly into the studio backdrop
float rFade = smoothstep(5.5, 1.2, length(p.xz));
benchCol *= (0.72 + 0.28 * rFade);
if (uLightMode == 1) {
float lum = dot(benchCol, vec3(0.2126, 0.7152, 0.0722));
benchCol = vec3(lum);
}
albedo = benchCol;
F0 = vec3(0.032);
metallic = 0.0;
ax = 0.56 + 0.14 * benchTex;
ay = ax;
}
// Lighting
vec3 L1, C1, L2, C2, L3, C3;
getLights(uLightMode, L1, C1, L2, C2, L3, C3);
float ao = calcAO(p, N);
// Hero-only soft shadow with exact rule-3 bias p + N * 0.014
float sh1 = calcSoftShadow(p + N * 0.014, L1, 6.0, 14.0);
float sh2 = calcSoftShadow(p + N * 0.014, L2, 6.0, 9.0);
vec3 Lo = vec3(0.0);
Lo += evalAnisoPBR(Nshade, V, L1, T, B, albedo, F0, metallic, ax, ay, C1) * sh1;
Lo += evalAnisoPBR(Nshade, V, L2, T, B, albedo, F0, metallic, ax, ay, C2) * (0.35 + 0.65 * sh2);
Lo += evalAnisoPBR(Nshade, V, L3, T, B, albedo, F0, metallic, ax, ay, C3);
// Anisotropic IBL reflection from studio softboxes + negative-fill flags
// Bend reflection normal along anisotropic stretch direction
float aniso = clamp((ay - ax) / max(ay, 0.001), 0.0, 0.85);
vec3 anisoT = cross(B, V);
vec3 anisoN = cross(anisoT, B);
float anisoLen = length(anisoN);
vec3 bentN = (anisoLen > 1e-4)
? normalize(mix(Nshade, anisoN / anisoLen, aniso * 0.45))
: Nshade;
vec3 R = reflect(-V, bentN);
float NdotV = max(dot(Nshade, V), 0.001);
vec3 Fenv = F_Schlick(NdotV, F0);
float roughMean = 0.5 * (ax + ay);
// Dual-lobe studio IBL approximation (sharp + blurred reflection)
vec3 envSharp = sampleStudioEnv(R, uLightMode);
vec3 envBlur = sampleStudioEnv(normalize(mix(R, Nshade, clamp(roughMean * 0.72, 0.0, 0.9))), uLightMode);
vec3 envSpec = mix(envSharp, envBlur, clamp(roughMean * 1.15, 0.0, 1.0));
vec3 envDiff = sampleStudioEnv(Nshade, uLightMode);
// Environment specular occlusion & energy conservation
float specAO = clamp(pow(NdotV + ao, exp2(-16.0 * roughMean - 1.0)) - 1.0 + ao, 0.15, 1.0);
vec3 iblSpec = envSpec * Fenv * (1.0 - roughMean * 0.42) * specAO;
vec3 iblDiff = envDiff * albedo * (1.0 - metallic) * (vec3(1.0) - Fenv) * ao * 0.85;
col = Lo + iblSpec + iblDiff;
// Subtle atmospheric distance blend into studio cyclorama at bench horizon
if (isBench) {
float fog = 1.0 - exp(-0.018 * t * t);
col = mix(col, bg * vig, clamp(fog, 0.0, 0.92));
}
}
// Exposure & ACES Filmic Tone Mapping (keeps hero luminance cleanly inside 10-248)
float exposure = (uLightMode == 3) ? 0.92 : 0.98;
col = acesToneMap(col * exposure);
// Pure neutral grayscale enforcement for uLightMode == 1
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
// Subtle lift floor & ceiling roll-off to guarantee hero lum in 10-248 (0% black/clipped)
col = pow(clamp(col * 0.935 + 0.0025, 0.0, 0.938), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Heat-Tempered Oxide Steel — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/thermal/lib/02_steel_heat_tempering_oxide_band.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// ============================================================================
// 02 — Steel Heat-Tempering Thin-Film Iron-Oxide Band
// Machined chamfered carbon-steel specimen resting on a refractory ceramic
// firebrick plinth and studio bench. Heated at one end to reveal the physically
// ordered iron-oxide interference spectrum (silver -> pale straw -> golden
// bronze -> crimson-purple -> peacock violet-blue -> slate gray) with
// anisotropic brushed GGX reflectance and heat-scale pitting at the hot tip.
// ============================================================================
const float PI = 3.14159265359;
const float INV_PI = 0.31830988618;
// ----------------------------------------------------------------------------
// Deterministic Hashes & Procedural Noise
// ----------------------------------------------------------------------------
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(13.7, 7.3);
a *= 0.5;
}
return v;
}
float voronoiPit(vec2 p) {
vec2 n = floor(p);
vec2 f = fract(p);
float dMin = 8.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 o = hash22(n + g);
vec2 r = g + o - f;
float d = dot(r, r);
dMin = min(dMin, d);
}
}
return sqrt(dMin);
}
// ----------------------------------------------------------------------------
// Bar & Firebrick Coordinate Frame
// Bar is gently angled in XZ for a dynamic 3/4 sculptural studio composition.
// Local coordinates:
// bx in [-1.18, +1.18] (hot tip at -x, cool machined end at +x)
// by in [0.0, 0.24] (resting on firebrick top at y = 0.14)
// bz in [-0.30, +0.30]
// ----------------------------------------------------------------------------
const float BAR_ANGLE = -0.22;
const float BRICK_H = 0.14;
mat2 rot2(float a) {
float c = cos(a);
float s = sin(a);
return mat2(c, -s, s, c);
}
vec3 toBarLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H + 0.125, 0.0);
q.xz = rot2(-BAR_ANGLE) * q.xz;
return q;
}
vec3 toBrickLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H * 0.5, 0.0);
q.xz = rot2(-BAR_ANGLE * 0.55) * q.xz;
return q;
}
// ----------------------------------------------------------------------------
// SDF Primitives
// ----------------------------------------------------------------------------
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// Chamfered rectangular prism: 45-degree bevels on all 12 edges with tiny
// machined edge radius so specular highlights catch cleanly along every bevel.
float sdChamferBox(vec3 p, vec3 b, float ch, float r) {
vec3 q = abs(p) - b;
float dBox = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
float cXY = (q.x + q.y + ch) * 0.70710678;
float cYZ = (q.y + q.z + ch) * 0.70710678;
float cXZ = (q.x + q.z + ch) * 0.70710678;
float dOct = max(cXY, max(cYZ, cXZ));
float d = max(dBox, dOct);
return d - r;
}
// Smooth boolean ops
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
// ----------------------------------------------------------------------------
// Specimen Geometry (Steel Bar + Refractory Ceramic Firebrick Plinth)
// ----------------------------------------------------------------------------
float mapSteelBar(vec3 p) {
vec3 q = toBarLocal(p);
// Main precision-machined chamfered bar: 2.36 x 0.25 x 0.60
float d = sdChamferBox(q, vec3(1.18, 0.120, 0.295), 0.036, 0.0045);
// Subtle machined thermocouple / specimen index bore near the cool end (+x)
vec2 boreP = q.xz - vec2(0.95, 0.0);
float dBore = length(boreP) - 0.068;
// Countersink chamfer at top of bore
float dCountersink = length(boreP) - (0.068 + max(0.0, q.y - 0.088) * 0.95);
float dHole = min(dBore, dCountersink);
d = smax(d, -dHole, 0.004);
// Subtle transverse witness graduation grooves near cool end (specimen scale marks)
float gx = q.x - 0.56;
if (abs(gx) < 0.18 && q.y > 0.08 && abs(q.z) < 0.255) {
float rep = mod(gx + 0.04, 0.08) - 0.04;
float groove = max(abs(rep) - 0.0032, -(q.y - 0.119));
d = max(d, -groove * 0.45);
}
// Subtle heat-scale pitting relief at the hottest tip (q.x < -0.78)
float tipMask = smoothstep(-0.76, -1.06, q.x);
if (tipMask > 0.001) {
float pit = voronoiPit(q.xz * 26.0 + vec2(q.y * 18.0, 3.1));
float micro = fbm2(q.xz * 19.0 + q.y * 9.0);
float pitDepth = smoothstep(0.36, 0.08, pit) * 0.0032 + (micro - 0.5) * 0.0014;
d += pitDepth * tipMask;
}
return d;
}
float mapFirebrick(vec3 p) {
vec3 q = toBrickLocal(p);
// Low refractory ceramic firebrick support plinth resting cleanly on y = 0
float d = sdChamferBox(q, vec3(1.42, BRICK_H * 0.5 - 0.004, 0.52), 0.018, 0.004);
// Subtle refractory ceramic surface undulation / hand-pressed kiln texture
float kiln = (fbm2(q.xz * 6.5 + vec2(2.1, -1.4)) - 0.5) * 0.0022;
d += kiln;
return d;
}
// Hero-only SDF (for clean soft shadow & hero/bench classification)
float mapHero(vec3 p) {
return min(mapSteelBar(p), mapFirebrick(p));
}
// Full scene SDF including studio bench at y = 0
float mapScene(vec3 p) {
return min(p.y, mapHero(p));
}
// Unit-weight tetrahedral normal (zero-bug rule 1)
vec3 calcNormal(vec3 p) {
const vec2 k = vec2(1.0, -1.0);
const float h = 0.0007;
return normalize(
k.xyy * mapScene(p + k.xyy * h) +
k.yyx * mapScene(p + k.yyx * h) +
k.yxy * mapScene(p + k.yxy * h) +
k.xxx * mapScene(p + k.xxx * h)
);
}
// Clean hero-only soft shadow (zero-bug rule 3: res = min(res, k*h/t), no ph)
float calcSoftShadow(vec3 ro, vec3 rd, float tMax, float k) {
float res = 1.0;
float t = 0.025;
for (int i = 0; i < 48; i++) {
float h = mapHero(ro + rd * t);
if (h < 0.0006) return 0.0;
res = min(res, k * h / t);
t += max(h, 0.015);
if (t > tMax) break;
}
return clamp(res, 0.0, 1.0);
}
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 5; i++) {
float h = 0.014 + 0.036 * float(i);
float d = mapScene(p + n * h);
occ += (h - d) * sca;
sca *= 0.72;
}
return clamp(1.0 - 2.3 * occ, 0.18, 1.0);
}
// ----------------------------------------------------------------------------
// Thin-Film Iron-Oxide Tempering Spectrum
// Physically ordered bands along the thermal gradient:
// 0.00 - 0.18 : Bright machined silver carbon steel
// 0.18 - 0.34 : Pale straw (~220 C)
// 0.34 - 0.50 : Golden bronze / amber (~250 C)
// 0.50 - 0.64 : Crimson-purple (~280 C)
// 0.64 - 0.78 : Peacock violet-blue (~300 C)
// 0.78 - 0.90 : Slate blue-gray (~340 C)
// 0.90 - 1.00 : Dark heat-scale slate / oxidized tip (>400 C)
// Includes subtle viewing-angle thin-film interference phase shift.
// ----------------------------------------------------------------------------
vec3 oxideSpectrum(float heatCoord, float NdotV) {
// Thin-film refraction angle factor (iron oxide n ~ 2.40)
float sin2i = max(0.0, 1.0 - NdotV * NdotV);
float cosT = sqrt(max(0.15, 1.0 - sin2i / (2.40 * 2.40)));
// Optical thickness shifts slightly with grazing angle (authentic iridescent shift)
float s = clamp(heatCoord * (0.86 + 0.16 * cosT), 0.0, 1.0);
// Physically ordered color stops (linear RGB metallic F0 reflectance)
vec3 cSilver = vec3(0.76, 0.78, 0.81); // Bare machined carbon steel
vec3 cStraw = vec3(0.84, 0.74, 0.44); // Pale straw (220 C)
vec3 cBronze = vec3(0.68, 0.37, 0.12); // Golden bronze / warm copper-amber (250 C)
vec3 cCrimson = vec3(0.46, 0.11, 0.28); // Crimson-purple (280 C)
vec3 cPeacock = vec3(0.11, 0.24, 0.62); // Peacock violet-blue (300 C)
vec3 cSlate = vec3(0.28, 0.33, 0.39); // Slate blue-gray (340 C)
vec3 cScale = vec3(0.16, 0.17, 0.19); // Dark heat-scale oxide tip (>400 C)
vec3 col = cSilver;
col = mix(col, cStraw, smoothstep(0.10, 0.25, s));
col = mix(col, cBronze, smoothstep(0.26, 0.42, s));
col = mix(col, cCrimson, smoothstep(0.42, 0.56, s));
col = mix(col, cPeacock, smoothstep(0.56, 0.71, s));
col = mix(col, cSlate, smoothstep(0.71, 0.85, s));
col = mix(col, cScale, smoothstep(0.85, 0.97, s));
// Subtle analytic Airy interference modulation for extra iridescent shimmer
float opd = s * 520.0 * cosT;
vec3 airy = 0.5 + 0.5 * cos(2.0 * PI * opd / vec3(635.0, 540.0, 455.0) + vec3(0.0, 0.4, 0.9));
float bandStrength = smoothstep(0.08, 0.22, s) * (1.0 - smoothstep(0.76, 0.94, s));
col *= mix(vec3(1.0), 0.84 + 0.32 * airy, bandStrength * 0.42);
return col;
}
// Compute thermal progress parameter [0 = cool silver, 1 = hottest scaled tip]
// uOpen (0..1) advances the thermal tempering front smoothly down the bar.
float computeThermalCoord(vec3 qBar) {
// Base coordinate from cool end (+1.18) to hot tip (-1.18)
float u = clamp((1.18 - qBar.x) / 2.36, 0.0, 1.0);
// Physical isotherm curvature: bar edges/chamfers heat slightly faster than core
float edgeLead = 0.042 * (qBar.z * qBar.z / (0.295 * 0.295)) + 0.015 * max(0.0, qBar.y / 0.12);
// Subtle metallurgical grain / heat-flow waviness
float waviness = (fbm2(vec2(qBar.x * 3.8, qBar.z * 5.2) + vec2(1.7, -0.9)) - 0.5) * 0.048;
float uEff = u + edgeLead + waviness;
// uOpen = 0.0 -> tempering front reaches ~58% along bar (full rainbow already visible)
// uOpen = 1.0 -> tempering front advances down to ~92% along bar
float openShift = mix(-0.18, 0.22, clamp(uOpen, 0.0, 1.0));
float front = smoothstep(0.14 - openShift, 0.96 - openShift * 0.45, uEff);
return clamp(front, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Environment Map (Softboxes + Negative-Fill Flags)
// ----------------------------------------------------------------------------
vec3 sampleStudioEnv(vec3 dir, int lightMode) {
vec3 d = normalize(dir);
float y = d.y;
// Smooth studio cyclorama base (no pure black)
vec3 skyLow = vec3(0.055, 0.058, 0.064);
vec3 skyMid = vec3(0.125, 0.132, 0.145);
vec3 skyHigh = vec3(0.185, 0.195, 0.215);
vec3 env = mix(skyLow, skyMid, smoothstep(-0.25, 0.18, y));
env = mix(env, skyHigh, smoothstep(0.18, 0.85, y));
if (lightMode == 1) {
// Pure neutral grayscale studio environment
float lum = dot(env, vec3(0.2126, 0.7152, 0.0722));
env = vec3(lum);
}
// 1) Main overhead elongated diffuser softbox (sweeps crisp specular across bar)
vec3 sb1Dir = normalize(vec3(0.15, 0.90, 0.38));
if (lightMode == 2) sb1Dir = normalize(vec3(-0.78, 0.22, 0.58)); // Grazing raking strip
if (lightMode == 3) sb1Dir = normalize(vec3(-0.12, 0.48, -0.87)); // Backlit overhead rim strip
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 s1R = normalize(cross(up, sb1Dir));
vec3 s1U = cross(sb1Dir, s1R);
float u1 = dot(d, s1R);
float v1 = dot(d, s1U);
float f1 = dot(d, sb1Dir);
float box1 = smoothstep(0.52, 0.36, abs(u1)) * smoothstep(0.26, 0.14, abs(v1)) * smoothstep(0.2, 0.45, f1);
vec3 c1 = (lightMode == 1) ? vec3(2.4) :
(lightMode == 2) ? vec3(2.9, 2.75, 2.55) :
(lightMode == 3) ? vec3(3.1, 3.05, 2.95) :
vec3(2.65, 2.55, 2.40);
env += c1 * box1;
// 2) Secondary cool fill softbox (opposite side for metallic contrast)
vec3 sb2Dir = normalize(vec3(-0.72, 0.52, 0.46));
if (lightMode == 2) sb2Dir = normalize(vec3(0.82, 0.35, -0.45));
if (lightMode == 3) sb2Dir = normalize(vec3(0.65, 0.40, -0.64));
float fillMask = pow(max(0.0, dot(d, sb2Dir)), 7.0);
vec3 c2 = (lightMode == 1) ? vec3(1.15) : vec3(1.10, 1.24, 1.48);
env += c2 * fillMask;
// 3) Warm low accent bounce card (brings out bevels and straw/bronze tones)
vec3 sb3Dir = normalize(vec3(0.68, 0.24, 0.69));
float warmCard = pow(max(0.0, dot(d, sb3Dir)), 10.0);
vec3 c3 = (lightMode == 1) ? vec3(0.75) : vec3(1.15, 0.96, 0.74);
env += c3 * warmCard * ((lightMode == 3) ? 0.35 : 0.85);
// 4) Negative-fill black flags (sculptural dark reflection bands on metal)
vec3 nf1Dir = normalize(vec3(-0.35, 0.42, 0.84));
vec3 nf2Dir = normalize(vec3(0.84, 0.32, -0.44));
float flag1 = smoothstep(0.74, 0.92, dot(d, nf1Dir));
float flag2 = smoothstep(0.78, 0.94, dot(d, nf2Dir));
env *= (1.0 - 0.72 * flag1) * (1.0 - 0.68 * flag2);
// Subtle ground bounce below horizon
float groundBounce = smoothstep(0.05, -0.35, y);
vec3 gCol = (lightMode == 1) ? vec3(0.075) : vec3(0.082, 0.074, 0.068);
env = mix(env, gCol, groundBounce * 0.75);
return env;
}
// ----------------------------------------------------------------------------
// Anisotropic GGX BRDF (Burley / Heitz formulation)
// ----------------------------------------------------------------------------
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float ax, float ay) {
float a2 = ax * ay;
vec3 v = vec3(ay * TdotH, ax * BdotH, a2 * NdotH);
float v2 = dot(v, v);
float w2 = a2 / max(v2, 1e-6);
return a2 * w2 * w2 * INV_PI;
}
float V_SmithGGX_Aniso(float NdotV, float NdotL, float TdotV, float BdotV, float TdotL, float BdotL, float ax, float ay) {
float lambdaV = NdotL * length(vec3(ax * TdotV, ay * BdotV, NdotV));
float lambdaL = NdotV * length(vec3(ax * TdotL, ay * BdotL, NdotL));
return 0.5 / max(lambdaV + lambdaL, 1e-5);
}
vec3 F_Schlick(float VdotH, vec3 F0) {
float f = pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
return F0 + (1.0 - F0) * f;
}
vec3 evalAnisoPBR(
vec3 N, vec3 V, vec3 L, vec3 T, vec3 B,
vec3 albedo, vec3 F0, float metallic, float ax, float ay, vec3 lightCol
) {
float NdotL = max(dot(N, L), 0.0);
float NdotV = max(dot(N, V), 1e-4);
if (NdotL <= 0.0) return vec3(0.0);
vec3 H = normalize(V + L);
float NdotH = max(dot(N, H), 0.0);
float VdotH = max(dot(V, H), 0.0);
float TdotH = dot(T, H);
float BdotH = dot(B, H);
float TdotV = dot(T, V);
float BdotV = dot(B, V);
float TdotL = dot(T, L);
float BdotL = dot(B, L);
float D = D_GGX_Aniso(NdotH, TdotH, BdotH, ax, ay);
float Vis = V_SmithGGX_Aniso(NdotV, NdotL, TdotV, BdotV, TdotL, BdotL, ax, ay);
vec3 F = F_Schlick(VdotH, F0);
vec3 spec = D * Vis * F;
vec3 kD = (vec3(1.0) - F) * (1.0 - metallic);
vec3 diff = kD * albedo * INV_PI;
return (diff + spec) * lightCol * NdotL;
}
// ----------------------------------------------------------------------------
// ACES Filmic Tone Mapping
// ----------------------------------------------------------------------------
vec3 acesToneMap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Lighting Rig
// ----------------------------------------------------------------------------
void getLights(
int lightMode,
out vec3 L1, out vec3 C1,
out vec3 L2, out vec3 C2,
out vec3 L3, out vec3 C3
) {
if (lightMode == 1) {
// Pure neutral grayscale lighting
L1 = normalize(vec3(0.45, 0.82, 0.55));
C1 = vec3(2.85);
L2 = normalize(vec3(-0.72, 0.48, 0.50));
C2 = vec3(1.15);
L3 = normalize(vec3(-0.18, 0.52, -0.83));
C3 = vec3(0.95);
} else if (lightMode == 2) {
// Grazing raking key to accentuate brushed anisotropy & heat-scale pitting
L1 = normalize(vec3(-0.88, 0.21, 0.42));
C1 = vec3(3.60, 3.35, 3.05);
L2 = normalize(vec3(0.75, 0.34, 0.56));
C2 = vec3(0.85, 0.96, 1.15);
L3 = normalize(vec3(0.10, 0.45, -0.88));
C3 = vec3(0.75, 0.80, 0.90);
} else if (lightMode == 3) {
// Backlit rim light
L1 = normalize(vec3(-0.22, 0.50, -0.84));
C1 = vec3(4.10, 3.95, 3.75);
L2 = normalize(vec3(0.72, 0.36, -0.59));
C2 = vec3(1.55, 1.65, 1.85);
L3 = normalize(vec3(0.28, 0.42, 0.86));
C3 = vec3(0.55, 0.58, 0.65);
} else {
// Hero museum studio rig
L1 = normalize(vec3(0.42, 0.80, 0.43));
C1 = vec3(3.05, 2.92, 2.75);
L2 = normalize(vec3(-0.76, 0.48, 0.44));
C2 = vec3(1.05, 1.20, 1.42);
L3 = normalize(vec3(-0.15, 0.54, -0.83));
C3 = vec3(1.15, 1.12, 1.08);
}
}
// ----------------------------------------------------------------------------
// Main Render
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera setup: 0 = Hero 3/4 view, 1 = ~2.5x Macro on tempering oxide band
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
// ~2.5x macro focused on the iridescent tempering band transition zone
float macroShift = mix(-0.28, 0.14, clamp(uOpen, 0.0, 1.0));
vec2 targetXZ = rot2(BAR_ANGLE) * vec2(macroShift, 0.0);
ta = vec3(targetXZ.x, BRICK_H + 0.16, targetXZ.y);
ro = ta + vec3(0.28, 0.68, 1.18);
fov = 1.95;
} else {
// Hero museum specimen view
ta = vec3(0.02, BRICK_H + 0.11, 0.0);
ro = vec3(0.32, 1.38, 2.68);
fov = 1.62;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
// Raymarch scene
float t = 0.0;
float tMax = 16.0;
bool hit = false;
for (int i = 0; i < 120; i++) {
vec3 p = ro + rd * t;
float d = mapScene(p);
if (d < 0.00055) {
hit = true;
break;
}
t += d;
if (t > tMax) break;
}
// Background studio cyclorama
vec3 bg = sampleStudioEnv(rd, uLightMode) * 0.58;
// Soft vignette on backdrop
float vig = 1.0 - 0.18 * dot(uv, uv);
vec3 col = bg * vig;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float dHero = mapHero(p);
// Zero-bug rule 2: exact bench classification
bool isBench = (p.y <= dHero + 0.001);
// Determine if steel bar vs ceramic firebrick plinth
float dBar = mapSteelBar(p);
float dBrick = mapFirebrick(p);
bool isSteel = (!isBench) && (dBar <= dBrick + 0.001);
// Construct anisotropic tangent frame
vec3 T, B;
if (isSteel) {
// Bar longitudinal axis in world space (direction of machined brushing)
vec2 axXZ = rot2(BAR_ANGLE) * vec2(1.0, 0.0);
vec3 barAxis = vec3(axXZ.x, 0.0, axXZ.y);
T = normalize(barAxis - N * dot(barAxis, N));
if (length(barAxis - N * dot(barAxis, N)) < 0.05) {
vec2 sideXZ = rot2(BAR_ANGLE) * vec2(0.0, 1.0);
T = normalize(vec3(sideXZ.x, 0.0, sideXZ.y));
}
B = normalize(cross(N, T));
} else {
vec3 upRef = (abs(N.y) < 0.99) ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
T = normalize(cross(upRef, N));
B = cross(N, T);
}
// Material parameters
vec3 albedo = vec3(0.18);
vec3 F0 = vec3(0.04);
float metallic = 0.0;
float ax = 0.45;
float ay = 0.45;
vec3 Nshade = N;
if (isSteel) {
vec3 qBar = toBarLocal(p);
float heatCoord = computeThermalCoord(qBar);
// Longitudinal brushed steel micro-grooves
float brush1 = vnoise2(vec2(qBar.x * 16.0, qBar.z * 260.0 + qBar.y * 220.0));
float brush2 = vnoise2(vec2(qBar.x * 42.0, qBar.z * 520.0 + qBar.y * 440.0));
float brush = (brush1 * 0.65 + brush2 * 0.35) - 0.5;
// Fine transverse chatter on chamfers/end-faces
float isEnd = smoothstep(0.75, 0.95, abs(dot(N, vec3(rot2(BAR_ANGLE) * vec2(1.0, 0.0), 0.0))));
float endMill = (vnoise2(vec2(qBar.z * 140.0, qBar.y * 140.0)) - 0.5) * isEnd;
// Heat-scale pitting at hottest tip
float scaleZone = smoothstep(0.78, 0.97, heatCoord);
float pitCell = voronoiPit(qBar.xz * 34.0 + vec2(qBar.y * 24.0, 1.9));
float pitMask = smoothstep(0.32, 0.10, pitCell) * scaleZone;
float flake = fbm2(qBar.xz * 28.0 + qBar.y * 14.0);
// Perturb normal slightly for brushed grooves and heat-scale pits
float grooveAmp = mix(0.055, 0.025, scaleZone);
Nshade = normalize(
N +
B * (brush * grooveAmp + endMill * 0.04) +
T * ((flake - 0.5) * 0.11 * scaleZone) +
B * ((pitCell - 0.45) * 0.14 * pitMask)
);
// Re-orthogonalize tangent frame to perturbed normal
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
float NdotV = max(dot(Nshade, V), 0.001);
// Thin-film iron oxide reflectance
vec3 oxCol = oxideSpectrum(heatCoord, NdotV);
// Subtle micro-variation from brushed grain
oxCol *= (0.94 + 0.12 * brush1);
// Darken inside heat-scale pits
oxCol = mix(oxCol, vec3(0.09, 0.095, 0.105), pitMask * 0.72);
if (uLightMode == 1) {
// Pure neutral grayscale albedo/F0 in LightMode 1
oxCol = vec3(0.68) * (0.94 + 0.12 * brush1);
oxCol = mix(oxCol, vec3(0.24), pitMask * 0.65);
}
metallic = mix(0.96, 0.52, scaleZone * (0.45 + 0.55 * pitMask));
albedo = mix(oxCol * 0.18, oxCol * 0.45, scaleZone);
F0 = mix(vec3(0.06), oxCol, metallic);
// Anisotropic roughness: smoother along longitudinal brush direction (ax),
// wider specular streak across brush lines (ay)
float baseAx = mix(0.11, 0.48, scaleZone) + pitMask * 0.22;
float baseAy = mix(0.34, 0.58, scaleZone) + pitMask * 0.18;
ax = clamp(baseAx + brush * 0.03, 0.07, 0.75);
ay = clamp(baseAy + brush * 0.05, 0.14, 0.85);
} else if (!isBench) {
// Refractory ceramic firebrick plinth (porous alumina-silicate firebrick)
vec3 qBrick = toBrickLocal(p);
float grain = fbm2(qBrick.xz * 22.0 + qBrick.y * 14.0);
float pores = voronoiPit(qBrick.xz * 58.0 + qBrick.y * 32.0);
float poreMask = smoothstep(0.24, 0.08, pores);
// Subtle thermal scorch / heat-halo on the firebrick beneath the hot tip
vec3 qBar = toBarLocal(p);
float hotDist = length((qBar.xz - vec2(-0.88, 0.0)) * vec2(0.85, 1.35));
float scorch = smoothstep(0.68, 0.12, hotDist) * smoothstep(-0.02, 0.05, qBrick.y);
vec3 brickCol = mix(vec3(0.38, 0.34, 0.29), vec3(0.49, 0.44, 0.37), grain);
brickCol *= (1.0 - 0.26 * poreMask);
brickCol = mix(brickCol, vec3(0.16, 0.14, 0.13), scorch * 0.58);
if (uLightMode == 1) {
float lum = dot(brickCol, vec3(0.2126, 0.7152, 0.0722));
brickCol = vec3(lum);
}
// Micro-bump for porous refractory clay
vec2 gOff = vec2(0.015, 0.0);
float gx = fbm2((qBrick.xz + gOff.xy) * 32.0) - fbm2((qBrick.xz - gOff.xy) * 32.0);
float gz = fbm2((qBrick.xz + gOff.yx) * 32.0) - fbm2((qBrick.xz - gOff.yx) * 32.0);
Nshade = normalize(N + vec3(gx, 0.0, gz) * 0.22);
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
albedo = brickCol;
F0 = vec3(0.035);
metallic = 0.0;
ax = 0.78 + poreMask * 0.14;
ay = ax;
} else {
// Studio bench surface at y = 0 (matte dark architectural slate / lab bench)
float benchTex = fbm2(p.xz * 2.8);
float fineTex = vnoise2(p.xz * 28.0);
vec3 benchCol = mix(vec3(0.068, 0.072, 0.078), vec3(0.098, 0.102, 0.108), benchTex);
benchCol *= (0.95 + 0.10 * fineTex);
// Radial falloff on bench so it blends smoothly into the studio backdrop
float rFade = smoothstep(5.5, 1.2, length(p.xz));
benchCol *= (0.72 + 0.28 * rFade);
if (uLightMode == 1) {
float lum = dot(benchCol, vec3(0.2126, 0.7152, 0.0722));
benchCol = vec3(lum);
}
albedo = benchCol;
F0 = vec3(0.032);
metallic = 0.0;
ax = 0.56 + 0.14 * benchTex;
ay = ax;
}
// Lighting
vec3 L1, C1, L2, C2, L3, C3;
getLights(uLightMode, L1, C1, L2, C2, L3, C3);
float ao = calcAO(p, N);
// Hero-only soft shadow with exact rule-3 bias p + N * 0.014
float sh1 = calcSoftShadow(p + N * 0.014, L1, 6.0, 14.0);
float sh2 = calcSoftShadow(p + N * 0.014, L2, 6.0, 9.0);
vec3 Lo = vec3(0.0);
Lo += evalAnisoPBR(Nshade, V, L1, T, B, albedo, F0, metallic, ax, ay, C1) * sh1;
Lo += evalAnisoPBR(Nshade, V, L2, T, B, albedo, F0, metallic, ax, ay, C2) * (0.35 + 0.65 * sh2);
Lo += evalAnisoPBR(Nshade, V, L3, T, B, albedo, F0, metallic, ax, ay, C3);
// Anisotropic IBL reflection from studio softboxes + negative-fill flags
// Bend reflection normal along anisotropic stretch direction
float aniso = clamp((ay - ax) / max(ay, 0.001), 0.0, 0.85);
vec3 anisoT = cross(B, V);
vec3 anisoN = cross(anisoT, B);
float anisoLen = length(anisoN);
vec3 bentN = (anisoLen > 1e-4)
? normalize(mix(Nshade, anisoN / anisoLen, aniso * 0.45))
: Nshade;
vec3 R = reflect(-V, bentN);
float NdotV = max(dot(Nshade, V), 0.001);
vec3 Fenv = F_Schlick(NdotV, F0);
float roughMean = 0.5 * (ax + ay);
// Dual-lobe studio IBL approximation (sharp + blurred reflection)
vec3 envSharp = sampleStudioEnv(R, uLightMode);
vec3 envBlur = sampleStudioEnv(normalize(mix(R, Nshade, clamp(roughMean * 0.72, 0.0, 0.9))), uLightMode);
vec3 envSpec = mix(envSharp, envBlur, clamp(roughMean * 1.15, 0.0, 1.0));
vec3 envDiff = sampleStudioEnv(Nshade, uLightMode);
// Environment specular occlusion & energy conservation
float specAO = clamp(pow(NdotV + ao, exp2(-16.0 * roughMean - 1.0)) - 1.0 + ao, 0.15, 1.0);
vec3 iblSpec = envSpec * Fenv * (1.0 - roughMean * 0.42) * specAO;
vec3 iblDiff = envDiff * albedo * (1.0 - metallic) * (vec3(1.0) - Fenv) * ao * 0.85;
col = Lo + iblSpec + iblDiff;
// Subtle atmospheric distance blend into studio cyclorama at bench horizon
if (isBench) {
float fog = 1.0 - exp(-0.018 * t * t);
col = mix(col, bg * vig, clamp(fog, 0.0, 0.92));
}
}
// Exposure & ACES Filmic Tone Mapping (keeps hero luminance cleanly inside 10-248)
float exposure = (uLightMode == 3) ? 0.92 : 0.98;
col = acesToneMap(col * exposure);
// Pure neutral grayscale enforcement for uLightMode == 1
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
// Subtle lift floor & ceiling roll-off to guarantee hero lum in 10-248 (0% black/clipped)
col = pow(clamp(col * 0.935 + 0.0025, 0.0, 0.938), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float out_alpha = study_col.a * COLOR.a;
if (u_luma_alpha_key) {
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
out_alpha *= smoothstep(0.035, 0.22, luma);
}
COLOR = vec4(tinted, out_alpha);
}
shader_type spatial;
render_mode cull_disabled;
// Heat-Tempered Oxide Steel — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/thermal/lib/02_steel_heat_tempering_oxide_band.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// ============================================================================
// 02 — Steel Heat-Tempering Thin-Film Iron-Oxide Band
// Machined chamfered carbon-steel specimen resting on a refractory ceramic
// firebrick plinth and studio bench. Heated at one end to reveal the physically
// ordered iron-oxide interference spectrum (silver -> pale straw -> golden
// bronze -> crimson-purple -> peacock violet-blue -> slate gray) with
// anisotropic brushed GGX reflectance and heat-scale pitting at the hot tip.
// ============================================================================
const float PI = 3.14159265359;
const float INV_PI = 0.31830988618;
// ----------------------------------------------------------------------------
// Deterministic Hashes & Procedural Noise
// ----------------------------------------------------------------------------
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(13.7, 7.3);
a *= 0.5;
}
return v;
}
float voronoiPit(vec2 p) {
vec2 n = floor(p);
vec2 f = fract(p);
float dMin = 8.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 o = hash22(n + g);
vec2 r = g + o - f;
float d = dot(r, r);
dMin = min(dMin, d);
}
}
return sqrt(dMin);
}
// ----------------------------------------------------------------------------
// Bar & Firebrick Coordinate Frame
// Bar is gently angled in XZ for a dynamic 3/4 sculptural studio composition.
// Local coordinates:
// bx in [-1.18, +1.18] (hot tip at -x, cool machined end at +x)
// by in [0.0, 0.24] (resting on firebrick top at y = 0.14)
// bz in [-0.30, +0.30]
// ----------------------------------------------------------------------------
const float BAR_ANGLE = -0.22;
const float BRICK_H = 0.14;
mat2 rot2(float a) {
float c = cos(a);
float s = sin(a);
return mat2(c, -s, s, c);
}
vec3 toBarLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H + 0.125, 0.0);
q.xz = rot2(-BAR_ANGLE) * q.xz;
return q;
}
vec3 toBrickLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H * 0.5, 0.0);
q.xz = rot2(-BAR_ANGLE * 0.55) * q.xz;
return q;
}
// ----------------------------------------------------------------------------
// SDF Primitives
// ----------------------------------------------------------------------------
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// Chamfered rectangular prism: 45-degree bevels on all 12 edges with tiny
// machined edge radius so specular highlights catch cleanly along every bevel.
float sdChamferBox(vec3 p, vec3 b, float ch, float r) {
vec3 q = abs(p) - b;
float dBox = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
float cXY = (q.x + q.y + ch) * 0.70710678;
float cYZ = (q.y + q.z + ch) * 0.70710678;
float cXZ = (q.x + q.z + ch) * 0.70710678;
float dOct = max(cXY, max(cYZ, cXZ));
float d = max(dBox, dOct);
return d - r;
}
// Smooth boolean ops
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
// ----------------------------------------------------------------------------
// Specimen Geometry (Steel Bar + Refractory Ceramic Firebrick Plinth)
// ----------------------------------------------------------------------------
float mapSteelBar(vec3 p) {
vec3 q = toBarLocal(p);
// Main precision-machined chamfered bar: 2.36 x 0.25 x 0.60
float d = sdChamferBox(q, vec3(1.18, 0.120, 0.295), 0.036, 0.0045);
// Subtle machined thermocouple / specimen index bore near the cool end (+x)
vec2 boreP = q.xz - vec2(0.95, 0.0);
float dBore = length(boreP) - 0.068;
// Countersink chamfer at top of bore
float dCountersink = length(boreP) - (0.068 + max(0.0, q.y - 0.088) * 0.95);
float dHole = min(dBore, dCountersink);
d = smax(d, -dHole, 0.004);
// Subtle transverse witness graduation grooves near cool end (specimen scale marks)
float gx = q.x - 0.56;
if (abs(gx) < 0.18 && q.y > 0.08 && abs(q.z) < 0.255) {
float rep = mod(gx + 0.04, 0.08) - 0.04;
float groove = max(abs(rep) - 0.0032, -(q.y - 0.119));
d = max(d, -groove * 0.45);
}
// Subtle heat-scale pitting relief at the hottest tip (q.x < -0.78)
float tipMask = smoothstep(-0.76, -1.06, q.x);
if (tipMask > 0.001) {
float pit = voronoiPit(q.xz * 26.0 + vec2(q.y * 18.0, 3.1));
float micro = fbm2(q.xz * 19.0 + q.y * 9.0);
float pitDepth = smoothstep(0.36, 0.08, pit) * 0.0032 + (micro - 0.5) * 0.0014;
d += pitDepth * tipMask;
}
return d;
}
float mapFirebrick(vec3 p) {
vec3 q = toBrickLocal(p);
// Low refractory ceramic firebrick support plinth resting cleanly on y = 0
float d = sdChamferBox(q, vec3(1.42, BRICK_H * 0.5 - 0.004, 0.52), 0.018, 0.004);
// Subtle refractory ceramic surface undulation / hand-pressed kiln texture
float kiln = (fbm2(q.xz * 6.5 + vec2(2.1, -1.4)) - 0.5) * 0.0022;
d += kiln;
return d;
}
// Hero-only SDF (for clean soft shadow & hero/bench classification)
float mapHero(vec3 p) {
return min(mapSteelBar(p), mapFirebrick(p));
}
// Full scene SDF including studio bench at y = 0
float mapScene(vec3 p) {
return min(p.y, mapHero(p));
}
// Unit-weight tetrahedral normal (zero-bug rule 1)
vec3 calcNormal(vec3 p) {
const vec2 k = vec2(1.0, -1.0);
const float h = 0.0007;
return normalize(
k.xyy * mapScene(p + k.xyy * h) +
k.yyx * mapScene(p + k.yyx * h) +
k.yxy * mapScene(p + k.yxy * h) +
k.xxx * mapScene(p + k.xxx * h)
);
}
// Clean hero-only soft shadow (zero-bug rule 3: res = min(res, k*h/t), no ph)
float calcSoftShadow(vec3 ro, vec3 rd, float tMax, float k) {
float res = 1.0;
float t = 0.025;
for (int i = 0; i < 48; i++) {
float h = mapHero(ro + rd * t);
if (h < 0.0006) return 0.0;
res = min(res, k * h / t);
t += max(h, 0.015);
if (t > tMax) break;
}
return clamp(res, 0.0, 1.0);
}
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 5; i++) {
float h = 0.014 + 0.036 * float(i);
float d = mapScene(p + n * h);
occ += (h - d) * sca;
sca *= 0.72;
}
return clamp(1.0 - 2.3 * occ, 0.18, 1.0);
}
// ----------------------------------------------------------------------------
// Thin-Film Iron-Oxide Tempering Spectrum
// Physically ordered bands along the thermal gradient:
// 0.00 - 0.18 : Bright machined silver carbon steel
// 0.18 - 0.34 : Pale straw (~220 C)
// 0.34 - 0.50 : Golden bronze / amber (~250 C)
// 0.50 - 0.64 : Crimson-purple (~280 C)
// 0.64 - 0.78 : Peacock violet-blue (~300 C)
// 0.78 - 0.90 : Slate blue-gray (~340 C)
// 0.90 - 1.00 : Dark heat-scale slate / oxidized tip (>400 C)
// Includes subtle viewing-angle thin-film interference phase shift.
// ----------------------------------------------------------------------------
vec3 oxideSpectrum(float heatCoord, float NdotV) {
// Thin-film refraction angle factor (iron oxide n ~ 2.40)
float sin2i = max(0.0, 1.0 - NdotV * NdotV);
float cosT = sqrt(max(0.15, 1.0 - sin2i / (2.40 * 2.40)));
// Optical thickness shifts slightly with grazing angle (authentic iridescent shift)
float s = clamp(heatCoord * (0.86 + 0.16 * cosT), 0.0, 1.0);
// Physically ordered color stops (linear RGB metallic F0 reflectance)
vec3 cSilver = vec3(0.76, 0.78, 0.81); // Bare machined carbon steel
vec3 cStraw = vec3(0.84, 0.74, 0.44); // Pale straw (220 C)
vec3 cBronze = vec3(0.68, 0.37, 0.12); // Golden bronze / warm copper-amber (250 C)
vec3 cCrimson = vec3(0.46, 0.11, 0.28); // Crimson-purple (280 C)
vec3 cPeacock = vec3(0.11, 0.24, 0.62); // Peacock violet-blue (300 C)
vec3 cSlate = vec3(0.28, 0.33, 0.39); // Slate blue-gray (340 C)
vec3 cScale = vec3(0.16, 0.17, 0.19); // Dark heat-scale oxide tip (>400 C)
vec3 col = cSilver;
col = mix(col, cStraw, smoothstep(0.10, 0.25, s));
col = mix(col, cBronze, smoothstep(0.26, 0.42, s));
col = mix(col, cCrimson, smoothstep(0.42, 0.56, s));
col = mix(col, cPeacock, smoothstep(0.56, 0.71, s));
col = mix(col, cSlate, smoothstep(0.71, 0.85, s));
col = mix(col, cScale, smoothstep(0.85, 0.97, s));
// Subtle analytic Airy interference modulation for extra iridescent shimmer
float opd = s * 520.0 * cosT;
vec3 airy = 0.5 + 0.5 * cos(2.0 * PI * opd / vec3(635.0, 540.0, 455.0) + vec3(0.0, 0.4, 0.9));
float bandStrength = smoothstep(0.08, 0.22, s) * (1.0 - smoothstep(0.76, 0.94, s));
col *= mix(vec3(1.0), 0.84 + 0.32 * airy, bandStrength * 0.42);
return col;
}
// Compute thermal progress parameter [0 = cool silver, 1 = hottest scaled tip]
// uOpen (0..1) advances the thermal tempering front smoothly down the bar.
float computeThermalCoord(vec3 qBar) {
// Base coordinate from cool end (+1.18) to hot tip (-1.18)
float u = clamp((1.18 - qBar.x) / 2.36, 0.0, 1.0);
// Physical isotherm curvature: bar edges/chamfers heat slightly faster than core
float edgeLead = 0.042 * (qBar.z * qBar.z / (0.295 * 0.295)) + 0.015 * max(0.0, qBar.y / 0.12);
// Subtle metallurgical grain / heat-flow waviness
float waviness = (fbm2(vec2(qBar.x * 3.8, qBar.z * 5.2) + vec2(1.7, -0.9)) - 0.5) * 0.048;
float uEff = u + edgeLead + waviness;
// uOpen = 0.0 -> tempering front reaches ~58% along bar (full rainbow already visible)
// uOpen = 1.0 -> tempering front advances down to ~92% along bar
float openShift = mix(-0.18, 0.22, clamp(uOpen, 0.0, 1.0));
float front = smoothstep(0.14 - openShift, 0.96 - openShift * 0.45, uEff);
return clamp(front, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Environment Map (Softboxes + Negative-Fill Flags)
// ----------------------------------------------------------------------------
vec3 sampleStudioEnv(vec3 dir, int lightMode) {
vec3 d = normalize(dir);
float y = d.y;
// Smooth studio cyclorama base (no pure black)
vec3 skyLow = vec3(0.055, 0.058, 0.064);
vec3 skyMid = vec3(0.125, 0.132, 0.145);
vec3 skyHigh = vec3(0.185, 0.195, 0.215);
vec3 env = mix(skyLow, skyMid, smoothstep(-0.25, 0.18, y));
env = mix(env, skyHigh, smoothstep(0.18, 0.85, y));
if (lightMode == 1) {
// Pure neutral grayscale studio environment
float lum = dot(env, vec3(0.2126, 0.7152, 0.0722));
env = vec3(lum);
}
// 1) Main overhead elongated diffuser softbox (sweeps crisp specular across bar)
vec3 sb1Dir = normalize(vec3(0.15, 0.90, 0.38));
if (lightMode == 2) sb1Dir = normalize(vec3(-0.78, 0.22, 0.58)); // Grazing raking strip
if (lightMode == 3) sb1Dir = normalize(vec3(-0.12, 0.48, -0.87)); // Backlit overhead rim strip
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 s1R = normalize(cross(up, sb1Dir));
vec3 s1U = cross(sb1Dir, s1R);
float u1 = dot(d, s1R);
float v1 = dot(d, s1U);
float f1 = dot(d, sb1Dir);
float box1 = smoothstep(0.52, 0.36, abs(u1)) * smoothstep(0.26, 0.14, abs(v1)) * smoothstep(0.2, 0.45, f1);
vec3 c1 = (lightMode == 1) ? vec3(2.4) :
(lightMode == 2) ? vec3(2.9, 2.75, 2.55) :
(lightMode == 3) ? vec3(3.1, 3.05, 2.95) :
vec3(2.65, 2.55, 2.40);
env += c1 * box1;
// 2) Secondary cool fill softbox (opposite side for metallic contrast)
vec3 sb2Dir = normalize(vec3(-0.72, 0.52, 0.46));
if (lightMode == 2) sb2Dir = normalize(vec3(0.82, 0.35, -0.45));
if (lightMode == 3) sb2Dir = normalize(vec3(0.65, 0.40, -0.64));
float fillMask = pow(max(0.0, dot(d, sb2Dir)), 7.0);
vec3 c2 = (lightMode == 1) ? vec3(1.15) : vec3(1.10, 1.24, 1.48);
env += c2 * fillMask;
// 3) Warm low accent bounce card (brings out bevels and straw/bronze tones)
vec3 sb3Dir = normalize(vec3(0.68, 0.24, 0.69));
float warmCard = pow(max(0.0, dot(d, sb3Dir)), 10.0);
vec3 c3 = (lightMode == 1) ? vec3(0.75) : vec3(1.15, 0.96, 0.74);
env += c3 * warmCard * ((lightMode == 3) ? 0.35 : 0.85);
// 4) Negative-fill black flags (sculptural dark reflection bands on metal)
vec3 nf1Dir = normalize(vec3(-0.35, 0.42, 0.84));
vec3 nf2Dir = normalize(vec3(0.84, 0.32, -0.44));
float flag1 = smoothstep(0.74, 0.92, dot(d, nf1Dir));
float flag2 = smoothstep(0.78, 0.94, dot(d, nf2Dir));
env *= (1.0 - 0.72 * flag1) * (1.0 - 0.68 * flag2);
// Subtle ground bounce below horizon
float groundBounce = smoothstep(0.05, -0.35, y);
vec3 gCol = (lightMode == 1) ? vec3(0.075) : vec3(0.082, 0.074, 0.068);
env = mix(env, gCol, groundBounce * 0.75);
return env;
}
// ----------------------------------------------------------------------------
// Anisotropic GGX BRDF (Burley / Heitz formulation)
// ----------------------------------------------------------------------------
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float ax, float ay) {
float a2 = ax * ay;
vec3 v = vec3(ay * TdotH, ax * BdotH, a2 * NdotH);
float v2 = dot(v, v);
float w2 = a2 / max(v2, 1e-6);
return a2 * w2 * w2 * INV_PI;
}
float V_SmithGGX_Aniso(float NdotV, float NdotL, float TdotV, float BdotV, float TdotL, float BdotL, float ax, float ay) {
float lambdaV = NdotL * length(vec3(ax * TdotV, ay * BdotV, NdotV));
float lambdaL = NdotV * length(vec3(ax * TdotL, ay * BdotL, NdotL));
return 0.5 / max(lambdaV + lambdaL, 1e-5);
}
vec3 F_Schlick(float VdotH, vec3 F0) {
float f = pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
return F0 + (1.0 - F0) * f;
}
vec3 evalAnisoPBR(
vec3 N, vec3 V, vec3 L, vec3 T, vec3 B,
vec3 albedo, vec3 F0, float metallic, float ax, float ay, vec3 lightCol
) {
float NdotL = max(dot(N, L), 0.0);
float NdotV = max(dot(N, V), 1e-4);
if (NdotL <= 0.0) return vec3(0.0);
vec3 H = normalize(V + L);
float NdotH = max(dot(N, H), 0.0);
float VdotH = max(dot(V, H), 0.0);
float TdotH = dot(T, H);
float BdotH = dot(B, H);
float TdotV = dot(T, V);
float BdotV = dot(B, V);
float TdotL = dot(T, L);
float BdotL = dot(B, L);
float D = D_GGX_Aniso(NdotH, TdotH, BdotH, ax, ay);
float Vis = V_SmithGGX_Aniso(NdotV, NdotL, TdotV, BdotV, TdotL, BdotL, ax, ay);
vec3 F = F_Schlick(VdotH, F0);
vec3 spec = D * Vis * F;
vec3 kD = (vec3(1.0) - F) * (1.0 - metallic);
vec3 diff = kD * albedo * INV_PI;
return (diff + spec) * lightCol * NdotL;
}
// ----------------------------------------------------------------------------
// ACES Filmic Tone Mapping
// ----------------------------------------------------------------------------
vec3 acesToneMap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Lighting Rig
// ----------------------------------------------------------------------------
void getLights(
int lightMode,
out vec3 L1, out vec3 C1,
out vec3 L2, out vec3 C2,
out vec3 L3, out vec3 C3
) {
if (lightMode == 1) {
// Pure neutral grayscale lighting
L1 = normalize(vec3(0.45, 0.82, 0.55));
C1 = vec3(2.85);
L2 = normalize(vec3(-0.72, 0.48, 0.50));
C2 = vec3(1.15);
L3 = normalize(vec3(-0.18, 0.52, -0.83));
C3 = vec3(0.95);
} else if (lightMode == 2) {
// Grazing raking key to accentuate brushed anisotropy & heat-scale pitting
L1 = normalize(vec3(-0.88, 0.21, 0.42));
C1 = vec3(3.60, 3.35, 3.05);
L2 = normalize(vec3(0.75, 0.34, 0.56));
C2 = vec3(0.85, 0.96, 1.15);
L3 = normalize(vec3(0.10, 0.45, -0.88));
C3 = vec3(0.75, 0.80, 0.90);
} else if (lightMode == 3) {
// Backlit rim light
L1 = normalize(vec3(-0.22, 0.50, -0.84));
C1 = vec3(4.10, 3.95, 3.75);
L2 = normalize(vec3(0.72, 0.36, -0.59));
C2 = vec3(1.55, 1.65, 1.85);
L3 = normalize(vec3(0.28, 0.42, 0.86));
C3 = vec3(0.55, 0.58, 0.65);
} else {
// Hero museum studio rig
L1 = normalize(vec3(0.42, 0.80, 0.43));
C1 = vec3(3.05, 2.92, 2.75);
L2 = normalize(vec3(-0.76, 0.48, 0.44));
C2 = vec3(1.05, 1.20, 1.42);
L3 = normalize(vec3(-0.15, 0.54, -0.83));
C3 = vec3(1.15, 1.12, 1.08);
}
}
// ----------------------------------------------------------------------------
// Main Render
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera setup: 0 = Hero 3/4 view, 1 = ~2.5x Macro on tempering oxide band
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
// ~2.5x macro focused on the iridescent tempering band transition zone
float macroShift = mix(-0.28, 0.14, clamp(uOpen, 0.0, 1.0));
vec2 targetXZ = rot2(BAR_ANGLE) * vec2(macroShift, 0.0);
ta = vec3(targetXZ.x, BRICK_H + 0.16, targetXZ.y);
ro = ta + vec3(0.28, 0.68, 1.18);
fov = 1.95;
} else {
// Hero museum specimen view
ta = vec3(0.02, BRICK_H + 0.11, 0.0);
ro = vec3(0.32, 1.38, 2.68);
fov = 1.62;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
// Raymarch scene
float t = 0.0;
float tMax = 16.0;
bool hit = false;
for (int i = 0; i < 120; i++) {
vec3 p = ro + rd * t;
float d = mapScene(p);
if (d < 0.00055) {
hit = true;
break;
}
t += d;
if (t > tMax) break;
}
// Background studio cyclorama
vec3 bg = sampleStudioEnv(rd, uLightMode) * 0.58;
// Soft vignette on backdrop
float vig = 1.0 - 0.18 * dot(uv, uv);
vec3 col = bg * vig;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float dHero = mapHero(p);
// Zero-bug rule 2: exact bench classification
bool isBench = (p.y <= dHero + 0.001);
// Determine if steel bar vs ceramic firebrick plinth
float dBar = mapSteelBar(p);
float dBrick = mapFirebrick(p);
bool isSteel = (!isBench) && (dBar <= dBrick + 0.001);
// Construct anisotropic tangent frame
vec3 T, B;
if (isSteel) {
// Bar longitudinal axis in world space (direction of machined brushing)
vec2 axXZ = rot2(BAR_ANGLE) * vec2(1.0, 0.0);
vec3 barAxis = vec3(axXZ.x, 0.0, axXZ.y);
T = normalize(barAxis - N * dot(barAxis, N));
if (length(barAxis - N * dot(barAxis, N)) < 0.05) {
vec2 sideXZ = rot2(BAR_ANGLE) * vec2(0.0, 1.0);
T = normalize(vec3(sideXZ.x, 0.0, sideXZ.y));
}
B = normalize(cross(N, T));
} else {
vec3 upRef = (abs(N.y) < 0.99) ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
T = normalize(cross(upRef, N));
B = cross(N, T);
}
// Material parameters
vec3 albedo = vec3(0.18);
vec3 F0 = vec3(0.04);
float metallic = 0.0;
float ax = 0.45;
float ay = 0.45;
vec3 Nshade = N;
if (isSteel) {
vec3 qBar = toBarLocal(p);
float heatCoord = computeThermalCoord(qBar);
// Longitudinal brushed steel micro-grooves
float brush1 = vnoise2(vec2(qBar.x * 16.0, qBar.z * 260.0 + qBar.y * 220.0));
float brush2 = vnoise2(vec2(qBar.x * 42.0, qBar.z * 520.0 + qBar.y * 440.0));
float brush = (brush1 * 0.65 + brush2 * 0.35) - 0.5;
// Fine transverse chatter on chamfers/end-faces
float isEnd = smoothstep(0.75, 0.95, abs(dot(N, vec3(rot2(BAR_ANGLE) * vec2(1.0, 0.0), 0.0))));
float endMill = (vnoise2(vec2(qBar.z * 140.0, qBar.y * 140.0)) - 0.5) * isEnd;
// Heat-scale pitting at hottest tip
float scaleZone = smoothstep(0.78, 0.97, heatCoord);
float pitCell = voronoiPit(qBar.xz * 34.0 + vec2(qBar.y * 24.0, 1.9));
float pitMask = smoothstep(0.32, 0.10, pitCell) * scaleZone;
float flake = fbm2(qBar.xz * 28.0 + qBar.y * 14.0);
// Perturb normal slightly for brushed grooves and heat-scale pits
float grooveAmp = mix(0.055, 0.025, scaleZone);
Nshade = normalize(
N +
B * (brush * grooveAmp + endMill * 0.04) +
T * ((flake - 0.5) * 0.11 * scaleZone) +
B * ((pitCell - 0.45) * 0.14 * pitMask)
);
// Re-orthogonalize tangent frame to perturbed normal
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
float NdotV = max(dot(Nshade, V), 0.001);
// Thin-film iron oxide reflectance
vec3 oxCol = oxideSpectrum(heatCoord, NdotV);
// Subtle micro-variation from brushed grain
oxCol *= (0.94 + 0.12 * brush1);
// Darken inside heat-scale pits
oxCol = mix(oxCol, vec3(0.09, 0.095, 0.105), pitMask * 0.72);
if (uLightMode == 1) {
// Pure neutral grayscale albedo/F0 in LightMode 1
oxCol = vec3(0.68) * (0.94 + 0.12 * brush1);
oxCol = mix(oxCol, vec3(0.24), pitMask * 0.65);
}
metallic = mix(0.96, 0.52, scaleZone * (0.45 + 0.55 * pitMask));
albedo = mix(oxCol * 0.18, oxCol * 0.45, scaleZone);
F0 = mix(vec3(0.06), oxCol, metallic);
// Anisotropic roughness: smoother along longitudinal brush direction (ax),
// wider specular streak across brush lines (ay)
float baseAx = mix(0.11, 0.48, scaleZone) + pitMask * 0.22;
float baseAy = mix(0.34, 0.58, scaleZone) + pitMask * 0.18;
ax = clamp(baseAx + brush * 0.03, 0.07, 0.75);
ay = clamp(baseAy + brush * 0.05, 0.14, 0.85);
} else if (!isBench) {
// Refractory ceramic firebrick plinth (porous alumina-silicate firebrick)
vec3 qBrick = toBrickLocal(p);
float grain = fbm2(qBrick.xz * 22.0 + qBrick.y * 14.0);
float pores = voronoiPit(qBrick.xz * 58.0 + qBrick.y * 32.0);
float poreMask = smoothstep(0.24, 0.08, pores);
// Subtle thermal scorch / heat-halo on the firebrick beneath the hot tip
vec3 qBar = toBarLocal(p);
float hotDist = length((qBar.xz - vec2(-0.88, 0.0)) * vec2(0.85, 1.35));
float scorch = smoothstep(0.68, 0.12, hotDist) * smoothstep(-0.02, 0.05, qBrick.y);
vec3 brickCol = mix(vec3(0.38, 0.34, 0.29), vec3(0.49, 0.44, 0.37), grain);
brickCol *= (1.0 - 0.26 * poreMask);
brickCol = mix(brickCol, vec3(0.16, 0.14, 0.13), scorch * 0.58);
if (uLightMode == 1) {
float lum = dot(brickCol, vec3(0.2126, 0.7152, 0.0722));
brickCol = vec3(lum);
}
// Micro-bump for porous refractory clay
vec2 gOff = vec2(0.015, 0.0);
float gx = fbm2((qBrick.xz + gOff.xy) * 32.0) - fbm2((qBrick.xz - gOff.xy) * 32.0);
float gz = fbm2((qBrick.xz + gOff.yx) * 32.0) - fbm2((qBrick.xz - gOff.yx) * 32.0);
Nshade = normalize(N + vec3(gx, 0.0, gz) * 0.22);
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
albedo = brickCol;
F0 = vec3(0.035);
metallic = 0.0;
ax = 0.78 + poreMask * 0.14;
ay = ax;
} else {
// Studio bench surface at y = 0 (matte dark architectural slate / lab bench)
float benchTex = fbm2(p.xz * 2.8);
float fineTex = vnoise2(p.xz * 28.0);
vec3 benchCol = mix(vec3(0.068, 0.072, 0.078), vec3(0.098, 0.102, 0.108), benchTex);
benchCol *= (0.95 + 0.10 * fineTex);
// Radial falloff on bench so it blends smoothly into the studio backdrop
float rFade = smoothstep(5.5, 1.2, length(p.xz));
benchCol *= (0.72 + 0.28 * rFade);
if (uLightMode == 1) {
float lum = dot(benchCol, vec3(0.2126, 0.7152, 0.0722));
benchCol = vec3(lum);
}
albedo = benchCol;
F0 = vec3(0.032);
metallic = 0.0;
ax = 0.56 + 0.14 * benchTex;
ay = ax;
}
// Lighting
vec3 L1, C1, L2, C2, L3, C3;
getLights(uLightMode, L1, C1, L2, C2, L3, C3);
float ao = calcAO(p, N);
// Hero-only soft shadow with exact rule-3 bias p + N * 0.014
float sh1 = calcSoftShadow(p + N * 0.014, L1, 6.0, 14.0);
float sh2 = calcSoftShadow(p + N * 0.014, L2, 6.0, 9.0);
vec3 Lo = vec3(0.0);
Lo += evalAnisoPBR(Nshade, V, L1, T, B, albedo, F0, metallic, ax, ay, C1) * sh1;
Lo += evalAnisoPBR(Nshade, V, L2, T, B, albedo, F0, metallic, ax, ay, C2) * (0.35 + 0.65 * sh2);
Lo += evalAnisoPBR(Nshade, V, L3, T, B, albedo, F0, metallic, ax, ay, C3);
// Anisotropic IBL reflection from studio softboxes + negative-fill flags
// Bend reflection normal along anisotropic stretch direction
float aniso = clamp((ay - ax) / max(ay, 0.001), 0.0, 0.85);
vec3 anisoT = cross(B, V);
vec3 anisoN = cross(anisoT, B);
float anisoLen = length(anisoN);
vec3 bentN = (anisoLen > 1e-4)
? normalize(mix(Nshade, anisoN / anisoLen, aniso * 0.45))
: Nshade;
vec3 R = reflect(-V, bentN);
float NdotV = max(dot(Nshade, V), 0.001);
vec3 Fenv = F_Schlick(NdotV, F0);
float roughMean = 0.5 * (ax + ay);
// Dual-lobe studio IBL approximation (sharp + blurred reflection)
vec3 envSharp = sampleStudioEnv(R, uLightMode);
vec3 envBlur = sampleStudioEnv(normalize(mix(R, Nshade, clamp(roughMean * 0.72, 0.0, 0.9))), uLightMode);
vec3 envSpec = mix(envSharp, envBlur, clamp(roughMean * 1.15, 0.0, 1.0));
vec3 envDiff = sampleStudioEnv(Nshade, uLightMode);
// Environment specular occlusion & energy conservation
float specAO = clamp(pow(NdotV + ao, exp2(-16.0 * roughMean - 1.0)) - 1.0 + ao, 0.15, 1.0);
vec3 iblSpec = envSpec * Fenv * (1.0 - roughMean * 0.42) * specAO;
vec3 iblDiff = envDiff * albedo * (1.0 - metallic) * (vec3(1.0) - Fenv) * ao * 0.85;
col = Lo + iblSpec + iblDiff;
// Subtle atmospheric distance blend into studio cyclorama at bench horizon
if (isBench) {
float fog = 1.0 - exp(-0.018 * t * t);
col = mix(col, bg * vig, clamp(fog, 0.0, 0.92));
}
}
// Exposure & ACES Filmic Tone Mapping (keeps hero luminance cleanly inside 10-248)
float exposure = (uLightMode == 3) ? 0.92 : 0.98;
col = acesToneMap(col * exposure);
// Pure neutral grayscale enforcement for uLightMode == 1
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
// Subtle lift floor & ceiling roll-off to guarantee hero lum in 10-248 (0% black/clipped)
col = pow(clamp(col * 0.935 + 0.0025, 0.0, 0.938), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
ALBEDO = tinted;
ROUGHNESS = clamp(0.85 - luma * 0.45, 0.08, 0.96);
METALLIC = 0.85;
EMISSION = tinted * 0.0;
}
// Heat-Tempered Oxide Steel — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/thermal/lib/02_steel_heat_tempering_oxide_band.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;
out vec4 fragColor;
// ============================================================================
// 02 — Steel Heat-Tempering Thin-Film Iron-Oxide Band
// Machined chamfered carbon-steel specimen resting on a refractory ceramic
// firebrick plinth and studio bench. Heated at one end to reveal the physically
// ordered iron-oxide interference spectrum (silver -> pale straw -> golden
// bronze -> crimson-purple -> peacock violet-blue -> slate gray) with
// anisotropic brushed GGX reflectance and heat-scale pitting at the hot tip.
// ============================================================================
const float PI = 3.14159265359;
const float INV_PI = 0.31830988618;
// ----------------------------------------------------------------------------
// Deterministic Hashes & Procedural Noise
// ----------------------------------------------------------------------------
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(13.7, 7.3);
a *= 0.5;
}
return v;
}
float voronoiPit(vec2 p) {
vec2 n = floor(p);
vec2 f = fract(p);
float dMin = 8.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 o = hash22(n + g);
vec2 r = g + o - f;
float d = dot(r, r);
dMin = min(dMin, d);
}
}
return sqrt(dMin);
}
// ----------------------------------------------------------------------------
// Bar & Firebrick Coordinate Frame
// Bar is gently angled in XZ for a dynamic 3/4 sculptural studio composition.
// Local coordinates:
// bx in [-1.18, +1.18] (hot tip at -x, cool machined end at +x)
// by in [0.0, 0.24] (resting on firebrick top at y = 0.14)
// bz in [-0.30, +0.30]
// ----------------------------------------------------------------------------
const float BAR_ANGLE = -0.22;
const float BRICK_H = 0.14;
mat2 rot2(float a) {
float c = cos(a);
float s = sin(a);
return mat2(c, -s, s, c);
}
vec3 toBarLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H + 0.125, 0.0);
q.xz = rot2(-BAR_ANGLE) * q.xz;
return q;
}
vec3 toBrickLocal(vec3 p) {
vec3 q = p - vec3(0.0, BRICK_H * 0.5, 0.0);
q.xz = rot2(-BAR_ANGLE * 0.55) * q.xz;
return q;
}
// ----------------------------------------------------------------------------
// SDF Primitives
// ----------------------------------------------------------------------------
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// Chamfered rectangular prism: 45-degree bevels on all 12 edges with tiny
// machined edge radius so specular highlights catch cleanly along every bevel.
float sdChamferBox(vec3 p, vec3 b, float ch, float r) {
vec3 q = abs(p) - b;
float dBox = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
float cXY = (q.x + q.y + ch) * 0.70710678;
float cYZ = (q.y + q.z + ch) * 0.70710678;
float cXZ = (q.x + q.z + ch) * 0.70710678;
float dOct = max(cXY, max(cYZ, cXZ));
float d = max(dBox, dOct);
return d - r;
}
// Smooth boolean ops
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
// ----------------------------------------------------------------------------
// Specimen Geometry (Steel Bar + Refractory Ceramic Firebrick Plinth)
// ----------------------------------------------------------------------------
float mapSteelBar(vec3 p) {
vec3 q = toBarLocal(p);
// Main precision-machined chamfered bar: 2.36 x 0.25 x 0.60
float d = sdChamferBox(q, vec3(1.18, 0.120, 0.295), 0.036, 0.0045);
// Subtle machined thermocouple / specimen index bore near the cool end (+x)
vec2 boreP = q.xz - vec2(0.95, 0.0);
float dBore = length(boreP) - 0.068;
// Countersink chamfer at top of bore
float dCountersink = length(boreP) - (0.068 + max(0.0, q.y - 0.088) * 0.95);
float dHole = min(dBore, dCountersink);
d = smax(d, -dHole, 0.004);
// Subtle transverse witness graduation grooves near cool end (specimen scale marks)
float gx = q.x - 0.56;
if (abs(gx) < 0.18 && q.y > 0.08 && abs(q.z) < 0.255) {
float rep = mod(gx + 0.04, 0.08) - 0.04;
float groove = max(abs(rep) - 0.0032, -(q.y - 0.119));
d = max(d, -groove * 0.45);
}
// Subtle heat-scale pitting relief at the hottest tip (q.x < -0.78)
float tipMask = smoothstep(-0.76, -1.06, q.x);
if (tipMask > 0.001) {
float pit = voronoiPit(q.xz * 26.0 + vec2(q.y * 18.0, 3.1));
float micro = fbm2(q.xz * 19.0 + q.y * 9.0);
float pitDepth = smoothstep(0.36, 0.08, pit) * 0.0032 + (micro - 0.5) * 0.0014;
d += pitDepth * tipMask;
}
return d;
}
float mapFirebrick(vec3 p) {
vec3 q = toBrickLocal(p);
// Low refractory ceramic firebrick support plinth resting cleanly on y = 0
float d = sdChamferBox(q, vec3(1.42, BRICK_H * 0.5 - 0.004, 0.52), 0.018, 0.004);
// Subtle refractory ceramic surface undulation / hand-pressed kiln texture
float kiln = (fbm2(q.xz * 6.5 + vec2(2.1, -1.4)) - 0.5) * 0.0022;
d += kiln;
return d;
}
// Hero-only SDF (for clean soft shadow & hero/bench classification)
float mapHero(vec3 p) {
return min(mapSteelBar(p), mapFirebrick(p));
}
// Full scene SDF including studio bench at y = 0
float mapScene(vec3 p) {
return min(p.y, mapHero(p));
}
// Unit-weight tetrahedral normal (zero-bug rule 1)
vec3 calcNormal(vec3 p) {
const vec2 k = vec2(1.0, -1.0);
const float h = 0.0007;
return normalize(
k.xyy * mapScene(p + k.xyy * h) +
k.yyx * mapScene(p + k.yyx * h) +
k.yxy * mapScene(p + k.yxy * h) +
k.xxx * mapScene(p + k.xxx * h)
);
}
// Clean hero-only soft shadow (zero-bug rule 3: res = min(res, k*h/t), no ph)
float calcSoftShadow(vec3 ro, vec3 rd, float tMax, float k) {
float res = 1.0;
float t = 0.025;
for (int i = 0; i < 48; i++) {
float h = mapHero(ro + rd * t);
if (h < 0.0006) return 0.0;
res = min(res, k * h / t);
t += max(h, 0.015);
if (t > tMax) break;
}
return clamp(res, 0.0, 1.0);
}
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 5; i++) {
float h = 0.014 + 0.036 * float(i);
float d = mapScene(p + n * h);
occ += (h - d) * sca;
sca *= 0.72;
}
return clamp(1.0 - 2.3 * occ, 0.18, 1.0);
}
// ----------------------------------------------------------------------------
// Thin-Film Iron-Oxide Tempering Spectrum
// Physically ordered bands along the thermal gradient:
// 0.00 - 0.18 : Bright machined silver carbon steel
// 0.18 - 0.34 : Pale straw (~220 C)
// 0.34 - 0.50 : Golden bronze / amber (~250 C)
// 0.50 - 0.64 : Crimson-purple (~280 C)
// 0.64 - 0.78 : Peacock violet-blue (~300 C)
// 0.78 - 0.90 : Slate blue-gray (~340 C)
// 0.90 - 1.00 : Dark heat-scale slate / oxidized tip (>400 C)
// Includes subtle viewing-angle thin-film interference phase shift.
// ----------------------------------------------------------------------------
vec3 oxideSpectrum(float heatCoord, float NdotV) {
// Thin-film refraction angle factor (iron oxide n ~ 2.40)
float sin2i = max(0.0, 1.0 - NdotV * NdotV);
float cosT = sqrt(max(0.15, 1.0 - sin2i / (2.40 * 2.40)));
// Optical thickness shifts slightly with grazing angle (authentic iridescent shift)
float s = clamp(heatCoord * (0.86 + 0.16 * cosT), 0.0, 1.0);
// Physically ordered color stops (linear RGB metallic F0 reflectance)
vec3 cSilver = vec3(0.76, 0.78, 0.81); // Bare machined carbon steel
vec3 cStraw = vec3(0.84, 0.74, 0.44); // Pale straw (220 C)
vec3 cBronze = vec3(0.68, 0.37, 0.12); // Golden bronze / warm copper-amber (250 C)
vec3 cCrimson = vec3(0.46, 0.11, 0.28); // Crimson-purple (280 C)
vec3 cPeacock = vec3(0.11, 0.24, 0.62); // Peacock violet-blue (300 C)
vec3 cSlate = vec3(0.28, 0.33, 0.39); // Slate blue-gray (340 C)
vec3 cScale = vec3(0.16, 0.17, 0.19); // Dark heat-scale oxide tip (>400 C)
vec3 col = cSilver;
col = mix(col, cStraw, smoothstep(0.10, 0.25, s));
col = mix(col, cBronze, smoothstep(0.26, 0.42, s));
col = mix(col, cCrimson, smoothstep(0.42, 0.56, s));
col = mix(col, cPeacock, smoothstep(0.56, 0.71, s));
col = mix(col, cSlate, smoothstep(0.71, 0.85, s));
col = mix(col, cScale, smoothstep(0.85, 0.97, s));
// Subtle analytic Airy interference modulation for extra iridescent shimmer
float opd = s * 520.0 * cosT;
vec3 airy = 0.5 + 0.5 * cos(2.0 * PI * opd / vec3(635.0, 540.0, 455.0) + vec3(0.0, 0.4, 0.9));
float bandStrength = smoothstep(0.08, 0.22, s) * (1.0 - smoothstep(0.76, 0.94, s));
col *= mix(vec3(1.0), 0.84 + 0.32 * airy, bandStrength * 0.42);
return col;
}
// Compute thermal progress parameter [0 = cool silver, 1 = hottest scaled tip]
// uOpen (0..1) advances the thermal tempering front smoothly down the bar.
float computeThermalCoord(vec3 qBar) {
// Base coordinate from cool end (+1.18) to hot tip (-1.18)
float u = clamp((1.18 - qBar.x) / 2.36, 0.0, 1.0);
// Physical isotherm curvature: bar edges/chamfers heat slightly faster than core
float edgeLead = 0.042 * (qBar.z * qBar.z / (0.295 * 0.295)) + 0.015 * max(0.0, qBar.y / 0.12);
// Subtle metallurgical grain / heat-flow waviness
float waviness = (fbm2(vec2(qBar.x * 3.8, qBar.z * 5.2) + vec2(1.7, -0.9)) - 0.5) * 0.048;
float uEff = u + edgeLead + waviness;
// uOpen = 0.0 -> tempering front reaches ~58% along bar (full rainbow already visible)
// uOpen = 1.0 -> tempering front advances down to ~92% along bar
float openShift = mix(-0.18, 0.22, clamp(uOpen, 0.0, 1.0));
float front = smoothstep(0.14 - openShift, 0.96 - openShift * 0.45, uEff);
return clamp(front, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Environment Map (Softboxes + Negative-Fill Flags)
// ----------------------------------------------------------------------------
vec3 sampleStudioEnv(vec3 dir, int lightMode) {
vec3 d = normalize(dir);
float y = d.y;
// Smooth studio cyclorama base (no pure black)
vec3 skyLow = vec3(0.055, 0.058, 0.064);
vec3 skyMid = vec3(0.125, 0.132, 0.145);
vec3 skyHigh = vec3(0.185, 0.195, 0.215);
vec3 env = mix(skyLow, skyMid, smoothstep(-0.25, 0.18, y));
env = mix(env, skyHigh, smoothstep(0.18, 0.85, y));
if (lightMode == 1) {
// Pure neutral grayscale studio environment
float lum = dot(env, vec3(0.2126, 0.7152, 0.0722));
env = vec3(lum);
}
// 1) Main overhead elongated diffuser softbox (sweeps crisp specular across bar)
vec3 sb1Dir = normalize(vec3(0.15, 0.90, 0.38));
if (lightMode == 2) sb1Dir = normalize(vec3(-0.78, 0.22, 0.58)); // Grazing raking strip
if (lightMode == 3) sb1Dir = normalize(vec3(-0.12, 0.48, -0.87)); // Backlit overhead rim strip
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 s1R = normalize(cross(up, sb1Dir));
vec3 s1U = cross(sb1Dir, s1R);
float u1 = dot(d, s1R);
float v1 = dot(d, s1U);
float f1 = dot(d, sb1Dir);
float box1 = smoothstep(0.52, 0.36, abs(u1)) * smoothstep(0.26, 0.14, abs(v1)) * smoothstep(0.2, 0.45, f1);
vec3 c1 = (lightMode == 1) ? vec3(2.4) :
(lightMode == 2) ? vec3(2.9, 2.75, 2.55) :
(lightMode == 3) ? vec3(3.1, 3.05, 2.95) :
vec3(2.65, 2.55, 2.40);
env += c1 * box1;
// 2) Secondary cool fill softbox (opposite side for metallic contrast)
vec3 sb2Dir = normalize(vec3(-0.72, 0.52, 0.46));
if (lightMode == 2) sb2Dir = normalize(vec3(0.82, 0.35, -0.45));
if (lightMode == 3) sb2Dir = normalize(vec3(0.65, 0.40, -0.64));
float fillMask = pow(max(0.0, dot(d, sb2Dir)), 7.0);
vec3 c2 = (lightMode == 1) ? vec3(1.15) : vec3(1.10, 1.24, 1.48);
env += c2 * fillMask;
// 3) Warm low accent bounce card (brings out bevels and straw/bronze tones)
vec3 sb3Dir = normalize(vec3(0.68, 0.24, 0.69));
float warmCard = pow(max(0.0, dot(d, sb3Dir)), 10.0);
vec3 c3 = (lightMode == 1) ? vec3(0.75) : vec3(1.15, 0.96, 0.74);
env += c3 * warmCard * ((lightMode == 3) ? 0.35 : 0.85);
// 4) Negative-fill black flags (sculptural dark reflection bands on metal)
vec3 nf1Dir = normalize(vec3(-0.35, 0.42, 0.84));
vec3 nf2Dir = normalize(vec3(0.84, 0.32, -0.44));
float flag1 = smoothstep(0.74, 0.92, dot(d, nf1Dir));
float flag2 = smoothstep(0.78, 0.94, dot(d, nf2Dir));
env *= (1.0 - 0.72 * flag1) * (1.0 - 0.68 * flag2);
// Subtle ground bounce below horizon
float groundBounce = smoothstep(0.05, -0.35, y);
vec3 gCol = (lightMode == 1) ? vec3(0.075) : vec3(0.082, 0.074, 0.068);
env = mix(env, gCol, groundBounce * 0.75);
return env;
}
// ----------------------------------------------------------------------------
// Anisotropic GGX BRDF (Burley / Heitz formulation)
// ----------------------------------------------------------------------------
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float ax, float ay) {
float a2 = ax * ay;
vec3 v = vec3(ay * TdotH, ax * BdotH, a2 * NdotH);
float v2 = dot(v, v);
float w2 = a2 / max(v2, 1e-6);
return a2 * w2 * w2 * INV_PI;
}
float V_SmithGGX_Aniso(float NdotV, float NdotL, float TdotV, float BdotV, float TdotL, float BdotL, float ax, float ay) {
float lambdaV = NdotL * length(vec3(ax * TdotV, ay * BdotV, NdotV));
float lambdaL = NdotV * length(vec3(ax * TdotL, ay * BdotL, NdotL));
return 0.5 / max(lambdaV + lambdaL, 1e-5);
}
vec3 F_Schlick(float VdotH, vec3 F0) {
float f = pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
return F0 + (1.0 - F0) * f;
}
vec3 evalAnisoPBR(
vec3 N, vec3 V, vec3 L, vec3 T, vec3 B,
vec3 albedo, vec3 F0, float metallic, float ax, float ay, vec3 lightCol
) {
float NdotL = max(dot(N, L), 0.0);
float NdotV = max(dot(N, V), 1e-4);
if (NdotL <= 0.0) return vec3(0.0);
vec3 H = normalize(V + L);
float NdotH = max(dot(N, H), 0.0);
float VdotH = max(dot(V, H), 0.0);
float TdotH = dot(T, H);
float BdotH = dot(B, H);
float TdotV = dot(T, V);
float BdotV = dot(B, V);
float TdotL = dot(T, L);
float BdotL = dot(B, L);
float D = D_GGX_Aniso(NdotH, TdotH, BdotH, ax, ay);
float Vis = V_SmithGGX_Aniso(NdotV, NdotL, TdotV, BdotV, TdotL, BdotL, ax, ay);
vec3 F = F_Schlick(VdotH, F0);
vec3 spec = D * Vis * F;
vec3 kD = (vec3(1.0) - F) * (1.0 - metallic);
vec3 diff = kD * albedo * INV_PI;
return (diff + spec) * lightCol * NdotL;
}
// ----------------------------------------------------------------------------
// ACES Filmic Tone Mapping
// ----------------------------------------------------------------------------
vec3 acesToneMap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// Studio Lighting Rig
// ----------------------------------------------------------------------------
void getLights(
int lightMode,
out vec3 L1, out vec3 C1,
out vec3 L2, out vec3 C2,
out vec3 L3, out vec3 C3
) {
if (lightMode == 1) {
// Pure neutral grayscale lighting
L1 = normalize(vec3(0.45, 0.82, 0.55));
C1 = vec3(2.85);
L2 = normalize(vec3(-0.72, 0.48, 0.50));
C2 = vec3(1.15);
L3 = normalize(vec3(-0.18, 0.52, -0.83));
C3 = vec3(0.95);
} else if (lightMode == 2) {
// Grazing raking key to accentuate brushed anisotropy & heat-scale pitting
L1 = normalize(vec3(-0.88, 0.21, 0.42));
C1 = vec3(3.60, 3.35, 3.05);
L2 = normalize(vec3(0.75, 0.34, 0.56));
C2 = vec3(0.85, 0.96, 1.15);
L3 = normalize(vec3(0.10, 0.45, -0.88));
C3 = vec3(0.75, 0.80, 0.90);
} else if (lightMode == 3) {
// Backlit rim light
L1 = normalize(vec3(-0.22, 0.50, -0.84));
C1 = vec3(4.10, 3.95, 3.75);
L2 = normalize(vec3(0.72, 0.36, -0.59));
C2 = vec3(1.55, 1.65, 1.85);
L3 = normalize(vec3(0.28, 0.42, 0.86));
C3 = vec3(0.55, 0.58, 0.65);
} else {
// Hero museum studio rig
L1 = normalize(vec3(0.42, 0.80, 0.43));
C1 = vec3(3.05, 2.92, 2.75);
L2 = normalize(vec3(-0.76, 0.48, 0.44));
C2 = vec3(1.05, 1.20, 1.42);
L3 = normalize(vec3(-0.15, 0.54, -0.83));
C3 = vec3(1.15, 1.12, 1.08);
}
}
// ----------------------------------------------------------------------------
// Main Render
// ----------------------------------------------------------------------------
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera setup: 0 = Hero 3/4 view, 1 = ~2.5x Macro on tempering oxide band
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
// ~2.5x macro focused on the iridescent tempering band transition zone
float macroShift = mix(-0.28, 0.14, clamp(uOpen, 0.0, 1.0));
vec2 targetXZ = rot2(BAR_ANGLE) * vec2(macroShift, 0.0);
ta = vec3(targetXZ.x, BRICK_H + 0.16, targetXZ.y);
ro = ta + vec3(0.28, 0.68, 1.18);
fov = 1.95;
} else {
// Hero museum specimen view
ta = vec3(0.02, BRICK_H + 0.11, 0.0);
ro = vec3(0.32, 1.38, 2.68);
fov = 1.62;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
// Raymarch scene
float t = 0.0;
float tMax = 16.0;
bool hit = false;
for (int i = 0; i < 120; i++) {
vec3 p = ro + rd * t;
float d = mapScene(p);
if (d < 0.00055) {
hit = true;
break;
}
t += d;
if (t > tMax) break;
}
// Background studio cyclorama
vec3 bg = sampleStudioEnv(rd, uLightMode) * 0.58;
// Soft vignette on backdrop
float vig = 1.0 - 0.18 * dot(uv, uv);
vec3 col = bg * vig;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float dHero = mapHero(p);
// Zero-bug rule 2: exact bench classification
bool isBench = (p.y <= dHero + 0.001);
// Determine if steel bar vs ceramic firebrick plinth
float dBar = mapSteelBar(p);
float dBrick = mapFirebrick(p);
bool isSteel = (!isBench) && (dBar <= dBrick + 0.001);
// Construct anisotropic tangent frame
vec3 T, B;
if (isSteel) {
// Bar longitudinal axis in world space (direction of machined brushing)
vec2 axXZ = rot2(BAR_ANGLE) * vec2(1.0, 0.0);
vec3 barAxis = vec3(axXZ.x, 0.0, axXZ.y);
T = normalize(barAxis - N * dot(barAxis, N));
if (length(barAxis - N * dot(barAxis, N)) < 0.05) {
vec2 sideXZ = rot2(BAR_ANGLE) * vec2(0.0, 1.0);
T = normalize(vec3(sideXZ.x, 0.0, sideXZ.y));
}
B = normalize(cross(N, T));
} else {
vec3 upRef = (abs(N.y) < 0.99) ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
T = normalize(cross(upRef, N));
B = cross(N, T);
}
// Material parameters
vec3 albedo = vec3(0.18);
vec3 F0 = vec3(0.04);
float metallic = 0.0;
float ax = 0.45;
float ay = 0.45;
vec3 Nshade = N;
if (isSteel) {
vec3 qBar = toBarLocal(p);
float heatCoord = computeThermalCoord(qBar);
// Longitudinal brushed steel micro-grooves
float brush1 = vnoise2(vec2(qBar.x * 16.0, qBar.z * 260.0 + qBar.y * 220.0));
float brush2 = vnoise2(vec2(qBar.x * 42.0, qBar.z * 520.0 + qBar.y * 440.0));
float brush = (brush1 * 0.65 + brush2 * 0.35) - 0.5;
// Fine transverse chatter on chamfers/end-faces
float isEnd = smoothstep(0.75, 0.95, abs(dot(N, vec3(rot2(BAR_ANGLE) * vec2(1.0, 0.0), 0.0))));
float endMill = (vnoise2(vec2(qBar.z * 140.0, qBar.y * 140.0)) - 0.5) * isEnd;
// Heat-scale pitting at hottest tip
float scaleZone = smoothstep(0.78, 0.97, heatCoord);
float pitCell = voronoiPit(qBar.xz * 34.0 + vec2(qBar.y * 24.0, 1.9));
float pitMask = smoothstep(0.32, 0.10, pitCell) * scaleZone;
float flake = fbm2(qBar.xz * 28.0 + qBar.y * 14.0);
// Perturb normal slightly for brushed grooves and heat-scale pits
float grooveAmp = mix(0.055, 0.025, scaleZone);
Nshade = normalize(
N +
B * (brush * grooveAmp + endMill * 0.04) +
T * ((flake - 0.5) * 0.11 * scaleZone) +
B * ((pitCell - 0.45) * 0.14 * pitMask)
);
// Re-orthogonalize tangent frame to perturbed normal
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
float NdotV = max(dot(Nshade, V), 0.001);
// Thin-film iron oxide reflectance
vec3 oxCol = oxideSpectrum(heatCoord, NdotV);
// Subtle micro-variation from brushed grain
oxCol *= (0.94 + 0.12 * brush1);
// Darken inside heat-scale pits
oxCol = mix(oxCol, vec3(0.09, 0.095, 0.105), pitMask * 0.72);
if (uLightMode == 1) {
// Pure neutral grayscale albedo/F0 in LightMode 1
oxCol = vec3(0.68) * (0.94 + 0.12 * brush1);
oxCol = mix(oxCol, vec3(0.24), pitMask * 0.65);
}
metallic = mix(0.96, 0.52, scaleZone * (0.45 + 0.55 * pitMask));
albedo = mix(oxCol * 0.18, oxCol * 0.45, scaleZone);
F0 = mix(vec3(0.06), oxCol, metallic);
// Anisotropic roughness: smoother along longitudinal brush direction (ax),
// wider specular streak across brush lines (ay)
float baseAx = mix(0.11, 0.48, scaleZone) + pitMask * 0.22;
float baseAy = mix(0.34, 0.58, scaleZone) + pitMask * 0.18;
ax = clamp(baseAx + brush * 0.03, 0.07, 0.75);
ay = clamp(baseAy + brush * 0.05, 0.14, 0.85);
} else if (!isBench) {
// Refractory ceramic firebrick plinth (porous alumina-silicate firebrick)
vec3 qBrick = toBrickLocal(p);
float grain = fbm2(qBrick.xz * 22.0 + qBrick.y * 14.0);
float pores = voronoiPit(qBrick.xz * 58.0 + qBrick.y * 32.0);
float poreMask = smoothstep(0.24, 0.08, pores);
// Subtle thermal scorch / heat-halo on the firebrick beneath the hot tip
vec3 qBar = toBarLocal(p);
float hotDist = length((qBar.xz - vec2(-0.88, 0.0)) * vec2(0.85, 1.35));
float scorch = smoothstep(0.68, 0.12, hotDist) * smoothstep(-0.02, 0.05, qBrick.y);
vec3 brickCol = mix(vec3(0.38, 0.34, 0.29), vec3(0.49, 0.44, 0.37), grain);
brickCol *= (1.0 - 0.26 * poreMask);
brickCol = mix(brickCol, vec3(0.16, 0.14, 0.13), scorch * 0.58);
if (uLightMode == 1) {
float lum = dot(brickCol, vec3(0.2126, 0.7152, 0.0722));
brickCol = vec3(lum);
}
// Micro-bump for porous refractory clay
vec2 gOff = vec2(0.015, 0.0);
float gx = fbm2((qBrick.xz + gOff.xy) * 32.0) - fbm2((qBrick.xz - gOff.xy) * 32.0);
float gz = fbm2((qBrick.xz + gOff.yx) * 32.0) - fbm2((qBrick.xz - gOff.yx) * 32.0);
Nshade = normalize(N + vec3(gx, 0.0, gz) * 0.22);
T = normalize(T - Nshade * dot(T, Nshade));
B = normalize(cross(Nshade, T));
albedo = brickCol;
F0 = vec3(0.035);
metallic = 0.0;
ax = 0.78 + poreMask * 0.14;
ay = ax;
} else {
// Studio bench surface at y = 0 (matte dark architectural slate / lab bench)
float benchTex = fbm2(p.xz * 2.8);
float fineTex = vnoise2(p.xz * 28.0);
vec3 benchCol = mix(vec3(0.068, 0.072, 0.078), vec3(0.098, 0.102, 0.108), benchTex);
benchCol *= (0.95 + 0.10 * fineTex);
// Radial falloff on bench so it blends smoothly into the studio backdrop
float rFade = smoothstep(5.5, 1.2, length(p.xz));
benchCol *= (0.72 + 0.28 * rFade);
if (uLightMode == 1) {
float lum = dot(benchCol, vec3(0.2126, 0.7152, 0.0722));
benchCol = vec3(lum);
}
albedo = benchCol;
F0 = vec3(0.032);
metallic = 0.0;
ax = 0.56 + 0.14 * benchTex;
ay = ax;
}
// Lighting
vec3 L1, C1, L2, C2, L3, C3;
getLights(uLightMode, L1, C1, L2, C2, L3, C3);
float ao = calcAO(p, N);
// Hero-only soft shadow with exact rule-3 bias p + N * 0.014
float sh1 = calcSoftShadow(p + N * 0.014, L1, 6.0, 14.0);
float sh2 = calcSoftShadow(p + N * 0.014, L2, 6.0, 9.0);
vec3 Lo = vec3(0.0);
Lo += evalAnisoPBR(Nshade, V, L1, T, B, albedo, F0, metallic, ax, ay, C1) * sh1;
Lo += evalAnisoPBR(Nshade, V, L2, T, B, albedo, F0, metallic, ax, ay, C2) * (0.35 + 0.65 * sh2);
Lo += evalAnisoPBR(Nshade, V, L3, T, B, albedo, F0, metallic, ax, ay, C3);
// Anisotropic IBL reflection from studio softboxes + negative-fill flags
// Bend reflection normal along anisotropic stretch direction
float aniso = clamp((ay - ax) / max(ay, 0.001), 0.0, 0.85);
vec3 anisoT = cross(B, V);
vec3 anisoN = cross(anisoT, B);
float anisoLen = length(anisoN);
vec3 bentN = (anisoLen > 1e-4)
? normalize(mix(Nshade, anisoN / anisoLen, aniso * 0.45))
: Nshade;
vec3 R = reflect(-V, bentN);
float NdotV = max(dot(Nshade, V), 0.001);
vec3 Fenv = F_Schlick(NdotV, F0);
float roughMean = 0.5 * (ax + ay);
// Dual-lobe studio IBL approximation (sharp + blurred reflection)
vec3 envSharp = sampleStudioEnv(R, uLightMode);
vec3 envBlur = sampleStudioEnv(normalize(mix(R, Nshade, clamp(roughMean * 0.72, 0.0, 0.9))), uLightMode);
vec3 envSpec = mix(envSharp, envBlur, clamp(roughMean * 1.15, 0.0, 1.0));
vec3 envDiff = sampleStudioEnv(Nshade, uLightMode);
// Environment specular occlusion & energy conservation
float specAO = clamp(pow(NdotV + ao, exp2(-16.0 * roughMean - 1.0)) - 1.0 + ao, 0.15, 1.0);
vec3 iblSpec = envSpec * Fenv * (1.0 - roughMean * 0.42) * specAO;
vec3 iblDiff = envDiff * albedo * (1.0 - metallic) * (vec3(1.0) - Fenv) * ao * 0.85;
col = Lo + iblSpec + iblDiff;
// Subtle atmospheric distance blend into studio cyclorama at bench horizon
if (isBench) {
float fog = 1.0 - exp(-0.018 * t * t);
col = mix(col, bg * vig, clamp(fog, 0.0, 0.92));
}
}
// Exposure & ACES Filmic Tone Mapping (keeps hero luminance cleanly inside 10-248)
float exposure = (uLightMode == 3) ? 0.92 : 0.98;
col = acesToneMap(col * exposure);
// Pure neutral grayscale enforcement for uLightMode == 1
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
// Subtle lift floor & ceiling roll-off to guarantee hero lum in 10-248 (0% black/clipped)
col = pow(clamp(col * 0.935 + 0.0025, 0.0, 0.938), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
`;
export function createHeatTemperedOxideSteelMaterial(width = 1024, height = 1024) {
const material = new THREE.ShaderMaterial({
glslVersion: THREE.GLSL3,
vertexShader,
fragmentShader,
uniforms: {
uResolution: { value: new THREE.Vector2(width, height) },
uTime: { value: 1.2 },
uOpen: { value: 0.0 },
uLightMode: { value: 0 },
uCamMode: { value: 1 },
},
});
return {
material,
update(elapsedSeconds) {
material.uniforms.uTime.value = elapsedSeconds * 1.0;
},
resize(nextW, nextH) {
material.uniforms.uResolution.value.set(nextW, nextH);
},
};
}
| Identifier | heat-tempered-oxide-steel |
|---|---|
| Category | Metals & Armor Shaders · Industrial Metals |
| Upstream study | thermal/lib/02_steel_heat_tempering_oxide_band.glsl (commit 095539c) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 745 lines · 28.5 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT fire sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Voronoi/Worley cellular fields (Voronoi 1908; Worley 1996); GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, distance formulation · Inigo Quilez, quadratic distance blend · Inigo Quilez, tetrahedral SDF normal
PBR StudyEuropean 4-in-1 riveted iron maille rings with accurate over-under interlocking and specular glints.
PBR StudyLocalized chloride-eaten cavities breaking through aged steel plate with dark ferric rims.
PBR StudyOxidized bronze and copper plating streaked with seafoam-green carbonate verdigris runoff.
AnimatedEncroaching flaky orange-ochre iron oxide eating across painted industrial steel.
AnimatedCNC-lathed 6061 aluminum surface with concentric anisotropic micro-grooves and bowtie specular.
AnimatedHot-dip galvanized steel sheet with Voronoi crystalline zinc spangle facets and grain orientation.