@pinkaphant/kolmo 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,7 @@ import * as THREE from "three";
|
|
|
3
3
|
export declare const KEY_SUN_DIRECTION: THREE.Vector3;
|
|
4
4
|
export declare const RING_MOONLET_COUNT = 72;
|
|
5
5
|
export declare const ATMO_VERT = "\n uniform vec2 uPs1Grid; uniform float uSnapStrength; varying vec3 vNormalWorld, vWorldPos;\n void main() {\n vec4 wp = modelMatrix * vec4(position, 1.0); vWorldPos = wp.xyz; vNormalWorld = normalize(mat3(modelMatrix) * normal);\n vec4 clip = projectionMatrix * viewMatrix * wp;\n if (uSnapStrength > 0.001 && clip.w > 0.001) {\n vec4 snapped = clip; snapped.xyz = clip.xyz / clip.w;\n vec2 safeGrid = max(uPs1Grid * mix(2.5, 1.0, clamp(uSnapStrength, 0.0, 1.0)), vec2(1.0));\n snapped.xy = floor(safeGrid * snapped.xy + 0.5) / safeGrid; snapped.xyz *= clip.w; clip = snapped;\n }\n gl_Position = clip;\n }\n";
|
|
6
|
-
export declare const ATMO_FRAG = "\n uniform vec3 uSunDir, uColor; uniform float uDitherMix; varying vec3 vNormalWorld, vWorldPos;\n \nuniform float uDitherScale; uniform vec4 uColorQuant; uniform sampler2D uPaletteLut;\n\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n\nfloat ps1BayerDither(vec2 fragCoord) { return ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)); }\nvec3 ps1SamplePaletteLut(vec3 srgb) {\n vec3 c = clamp(srgb, 0.0, 1.0);\n return texture2D(uPaletteLut, vec2((floor(c.b * 31.0 + 0.5) * 32.0 + floor(c.r * 31.0 + 0.5) + 0.5) / 1024.0, (floor(c.g * 31.0 + 0.5) + 0.5) / 32.0)).rgb;\n}\nvec3 ps1QuantizeRetro(vec3 col, vec2 fragCoord, float ditherSpread) {\n if (uColorQuant.w < 0.5) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)), spread = clamp(ditherSpread, 0.0, 1.0);\n if (uColorQuant.w > 1.5) return ps1SamplePaletteLut(ps1LinearToSrgb(clamp(ps1SrgbToLinear(srgb) + (bayer - 0.5) * (uColorQuant.y * spread), 0.0, 1.0)));\n vec3 levels = max(uColorQuant.rgb, vec3(1.0)), c0 = floor(srgb * levels) / levels, c1 = min(c0 + 1.0 / levels, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, spread)), t));\n}\nvec4 ps1SampleN64ThreePoint(sampler2D tex, vec2 uv, float texSize, float mixStrength) {\n vec4 nearestSample = texture2D(tex, uv);\n if (mixStrength <= 0.001) return nearestSample;\n #if __VERSION__ >= 300\n vec2 ts = max(vec2(textureSize(tex, 0)), vec2(16.0));\n #else\n vec2 ts = vec2(max(16.0, texSize));\n #endif\n vec2 p = uv * ts - 0.5
|
|
6
|
+
export declare const ATMO_FRAG = "\n uniform vec3 uSunDir, uColor; uniform float uDitherMix; varying vec3 vNormalWorld, vWorldPos;\n \nuniform float uDitherScale; uniform vec4 uColorQuant; uniform sampler2D uPaletteLut;\n\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n\nfloat ps1BayerDither(vec2 fragCoord) { return ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)); }\nvec3 ps1SamplePaletteLut(vec3 srgb) {\n vec3 c = clamp(srgb, 0.0, 1.0);\n return texture2D(uPaletteLut, vec2((floor(c.b * 31.0 + 0.5) * 32.0 + floor(c.r * 31.0 + 0.5) + 0.5) / 1024.0, (floor(c.g * 31.0 + 0.5) + 0.5) / 32.0)).rgb;\n}\nvec3 ps1QuantizeRetro(vec3 col, vec2 fragCoord, float ditherSpread) {\n if (uColorQuant.w < 0.5) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)), spread = clamp(ditherSpread, 0.0, 1.0);\n if (uColorQuant.w > 1.5) return ps1SamplePaletteLut(ps1LinearToSrgb(clamp(ps1SrgbToLinear(srgb) + (bayer - 0.5) * (uColorQuant.y * spread), 0.0, 1.0)));\n vec3 levels = max(uColorQuant.rgb, vec3(1.0)), c0 = floor(srgb * levels) / levels, c1 = min(c0 + 1.0 / levels, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, spread)), t));\n}\nvec4 ps1SampleN64ThreePoint(sampler2D tex, vec2 uv, float texSize, float mixStrength) {\n vec4 nearestSample = texture2D(tex, uv);\n if (mixStrength <= 0.001) return nearestSample;\n #if __VERSION__ >= 300\n vec2 ts = max(vec2(textureSize(tex, 0)), vec2(16.0));\n #else\n vec2 ts = vec2(max(16.0, texSize));\n #endif\n vec2 p = uv * ts - 0.5, i = floor(p), f = p - i, inv = 1.0 / ts;\n vec4 c10 = texture2D(tex, (i + vec2(1.5, 0.5)) * inv), c01 = texture2D(tex, (i + vec2(0.5, 1.5)) * inv);\n vec4 n64Col;\n if (f.x + f.y < 1.0) { vec4 c00 = texture2D(tex, (i + vec2(0.5, 0.5)) * inv); n64Col = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }\n else { vec4 c11 = texture2D(tex, (i + vec2(1.5, 1.5)) * inv); n64Col = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }\n return mix(nearestSample, n64Col, clamp(mixStrength, 0.0, 1.0));\n}\nfloat ps1ProcTexelHash(vec2 cell) { return fract(sin(dot(cell, vec2(127.1, 311.7))) * 43758.5453); }\nfloat ps1ProcN64ThreePoint(vec2 uv, float mixStrength) {\n vec2 p = uv * 8.0 - 0.5, i = floor(p), f = p - i;\n float nearestVal = ps1ProcTexelHash(floor(uv * 8.0));\n if (mixStrength <= 0.001) return nearestVal;\n float c10 = ps1ProcTexelHash(i + vec2(1.0, 0.0)), c01 = ps1ProcTexelHash(i + vec2(0.0, 1.0)), n64Val;\n if (f.x + f.y < 1.0) { float c00 = ps1ProcTexelHash(i); n64Val = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }\n else { float c11 = ps1ProcTexelHash(i + vec2(1.0, 1.0)); n64Val = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }\n return mix(nearestVal, n64Val, clamp(mixStrength, 0.0, 1.0));\n}\n\n void main() {\n vec3 viewDir = normalize(cameraPosition - vWorldPos);\n float rim = pow(1.0 - max(0.0, dot(viewDir, vNormalWorld)), 2.6), nl = dot(vNormalWorld, normalize(uSunDir));\n float sunLit = mix(smoothstep(-0.3, 0.7, nl), step(-0.25, nl), uDitherMix) * 0.72 + 0.28, alpha = rim * sunLit;\n if (alpha < (ps1BayerDither(gl_FragCoord.xy) * 0.65 + 0.14) * uDitherMix) discard;\n vec3 col = ps1QuantizeRetro(ps1LinearToSrgb(uColor * (0.8 + sunLit * 0.55)), gl_FragCoord.xy, uDitherMix);\n gl_FragColor = vec4(col, mix(alpha * 0.85, 0.75, uDitherMix));\n }\n";
|
|
7
7
|
export interface KolmoSkyboxProps {
|
|
8
8
|
sunDirection?: [number, number, number];
|
|
9
9
|
}
|
|
@@ -86,7 +86,7 @@ export declare function syncRetroUniforms(presetId: RetroPresetId): RetroPreset;
|
|
|
86
86
|
export declare function syncRetroUniforms(ditherAmount: number, pixelSnapAmount?: number, renderScale?: number, colorMode?: RetroColorMode, ditherScale?: number, affineAmount?: number, gouraudAmount?: number, n64FilterAmount?: number): void;
|
|
87
87
|
export declare function syncRetroViewport(fbW: number, fbH: number, effectiveDpr: number): void;
|
|
88
88
|
export declare const GLSL_BAYER_RGB555 = "\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n";
|
|
89
|
-
export declare const GLSL_RETRO_QUANTIZE = "\nuniform float uDitherScale; uniform vec4 uColorQuant; uniform sampler2D uPaletteLut;\n\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n\nfloat ps1BayerDither(vec2 fragCoord) { return ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)); }\nvec3 ps1SamplePaletteLut(vec3 srgb) {\n vec3 c = clamp(srgb, 0.0, 1.0);\n return texture2D(uPaletteLut, vec2((floor(c.b * 31.0 + 0.5) * 32.0 + floor(c.r * 31.0 + 0.5) + 0.5) / 1024.0, (floor(c.g * 31.0 + 0.5) + 0.5) / 32.0)).rgb;\n}\nvec3 ps1QuantizeRetro(vec3 col, vec2 fragCoord, float ditherSpread) {\n if (uColorQuant.w < 0.5) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)), spread = clamp(ditherSpread, 0.0, 1.0);\n if (uColorQuant.w > 1.5) return ps1SamplePaletteLut(ps1LinearToSrgb(clamp(ps1SrgbToLinear(srgb) + (bayer - 0.5) * (uColorQuant.y * spread), 0.0, 1.0)));\n vec3 levels = max(uColorQuant.rgb, vec3(1.0)), c0 = floor(srgb * levels) / levels, c1 = min(c0 + 1.0 / levels, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, spread)), t));\n}\nvec4 ps1SampleN64ThreePoint(sampler2D tex, vec2 uv, float texSize, float mixStrength) {\n vec4 nearestSample = texture2D(tex, uv);\n if (mixStrength <= 0.001) return nearestSample;\n #if __VERSION__ >= 300\n vec2 ts = max(vec2(textureSize(tex, 0)), vec2(16.0));\n #else\n vec2 ts = vec2(max(16.0, texSize));\n #endif\n vec2 p = uv * ts - 0.5
|
|
89
|
+
export declare const GLSL_RETRO_QUANTIZE = "\nuniform float uDitherScale; uniform vec4 uColorQuant; uniform sampler2D uPaletteLut;\n\nvec3 ps1SrgbToLinear(vec3 s) { vec3 a = clamp(s, 0.0, 1.0); return a * (a * (a * 0.305306011 + 0.682171111) + 0.012522878); }\nvec3 ps1LinearToSrgb(vec3 l) { return max(1.055 * pow(clamp(l, 0.0, 1.0), vec3(0.416666667)) - 0.055, vec3(0.0)); }\nfloat ps1Bayer2(vec2 c) { return (c.y < 0.5) ? (c.x < 0.5 ? 0.0 : 2.0) : (c.x < 0.5 ? 3.0 : 1.0); }\nfloat ps1Bayer4x4(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) + 0.5) / 16.0; }\nfloat ps1Bayer8x8(vec2 p) { vec2 f = floor(p); return (ps1Bayer2(mod(f, 2.0)) * 16.0 + ps1Bayer2(mod(floor(f * 0.5), 2.0)) * 4.0 + ps1Bayer2(mod(floor(f * 0.25), 2.0)) + 0.5) / 64.0; }\nvec3 ps1QuantizeRGB555Mix(vec3 col, vec2 fragCoord, float mixAmt) {\n if (mixAmt <= 0.001) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord * 0.5);\n vec3 c0 = floor(srgb * 31.0) / 31.0, c1 = min(c0 + 1.0 / 31.0, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, clamp(mixAmt, 0.0, 1.0))), t));\n}\nvec3 ps1QuantizeRGB555(vec3 col, vec2 fragCoord) { return ps1QuantizeRGB555Mix(col, fragCoord, 1.0); }\n\nfloat ps1BayerDither(vec2 fragCoord) { return ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)); }\nvec3 ps1SamplePaletteLut(vec3 srgb) {\n vec3 c = clamp(srgb, 0.0, 1.0);\n return texture2D(uPaletteLut, vec2((floor(c.b * 31.0 + 0.5) * 32.0 + floor(c.r * 31.0 + 0.5) + 0.5) / 1024.0, (floor(c.g * 31.0 + 0.5) + 0.5) / 32.0)).rgb;\n}\nvec3 ps1QuantizeRetro(vec3 col, vec2 fragCoord, float ditherSpread) {\n if (uColorQuant.w < 0.5) return col;\n vec3 srgb = clamp(col, 0.0, 1.0); float bayer = ps1Bayer4x4(fragCoord / max(uDitherScale, 0.5)), spread = clamp(ditherSpread, 0.0, 1.0);\n if (uColorQuant.w > 1.5) return ps1SamplePaletteLut(ps1LinearToSrgb(clamp(ps1SrgbToLinear(srgb) + (bayer - 0.5) * (uColorQuant.y * spread), 0.0, 1.0)));\n vec3 levels = max(uColorQuant.rgb, vec3(1.0)), c0 = floor(srgb * levels) / levels, c1 = min(c0 + 1.0 / levels, vec3(1.0));\n vec3 l0 = ps1SrgbToLinear(c0), l1 = ps1SrgbToLinear(c1);\n vec3 t = clamp((ps1SrgbToLinear(srgb) - l0) / max(l1 - l0, vec3(1e-5)), 0.0, 1.0);\n return mix(c0, c1, step(vec3(mix(0.5, bayer, spread)), t));\n}\nvec4 ps1SampleN64ThreePoint(sampler2D tex, vec2 uv, float texSize, float mixStrength) {\n vec4 nearestSample = texture2D(tex, uv);\n if (mixStrength <= 0.001) return nearestSample;\n #if __VERSION__ >= 300\n vec2 ts = max(vec2(textureSize(tex, 0)), vec2(16.0));\n #else\n vec2 ts = vec2(max(16.0, texSize));\n #endif\n vec2 p = uv * ts - 0.5, i = floor(p), f = p - i, inv = 1.0 / ts;\n vec4 c10 = texture2D(tex, (i + vec2(1.5, 0.5)) * inv), c01 = texture2D(tex, (i + vec2(0.5, 1.5)) * inv);\n vec4 n64Col;\n if (f.x + f.y < 1.0) { vec4 c00 = texture2D(tex, (i + vec2(0.5, 0.5)) * inv); n64Col = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }\n else { vec4 c11 = texture2D(tex, (i + vec2(1.5, 1.5)) * inv); n64Col = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }\n return mix(nearestSample, n64Col, clamp(mixStrength, 0.0, 1.0));\n}\nfloat ps1ProcTexelHash(vec2 cell) { return fract(sin(dot(cell, vec2(127.1, 311.7))) * 43758.5453); }\nfloat ps1ProcN64ThreePoint(vec2 uv, float mixStrength) {\n vec2 p = uv * 8.0 - 0.5, i = floor(p), f = p - i;\n float nearestVal = ps1ProcTexelHash(floor(uv * 8.0));\n if (mixStrength <= 0.001) return nearestVal;\n float c10 = ps1ProcTexelHash(i + vec2(1.0, 0.0)), c01 = ps1ProcTexelHash(i + vec2(0.0, 1.0)), n64Val;\n if (f.x + f.y < 1.0) { float c00 = ps1ProcTexelHash(i); n64Val = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }\n else { float c11 = ps1ProcTexelHash(i + vec2(1.0, 1.0)); n64Val = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }\n return mix(nearestVal, n64Val, clamp(mixStrength, 0.0, 1.0));\n}\n";
|
|
90
90
|
export interface RetroMaterialOptions {
|
|
91
91
|
flatShading?: boolean;
|
|
92
92
|
snap?: number;
|
|
@@ -203,45 +203,21 @@ vec4 ps1SampleN64ThreePoint(sampler2D tex, vec2 uv, float texSize, float mixStre
|
|
|
203
203
|
#else
|
|
204
204
|
vec2 ts = vec2(max(16.0, texSize));
|
|
205
205
|
#endif
|
|
206
|
-
vec2 p = uv * ts - 0.5;
|
|
207
|
-
|
|
208
|
-
vec2 f = p - i;
|
|
209
|
-
vec2 inv = 1.0 / ts;
|
|
210
|
-
vec2 uv00 = (i + vec2(0.5, 0.5)) * inv;
|
|
211
|
-
vec2 uv10 = (i + vec2(1.5, 0.5)) * inv;
|
|
212
|
-
vec2 uv01 = (i + vec2(0.5, 1.5)) * inv;
|
|
213
|
-
vec2 uv11 = (i + vec2(1.5, 1.5)) * inv;
|
|
214
|
-
vec4 c10 = texture2D(tex, uv10);
|
|
215
|
-
vec4 c01 = texture2D(tex, uv01);
|
|
206
|
+
vec2 p = uv * ts - 0.5, i = floor(p), f = p - i, inv = 1.0 / ts;
|
|
207
|
+
vec4 c10 = texture2D(tex, (i + vec2(1.5, 0.5)) * inv), c01 = texture2D(tex, (i + vec2(0.5, 1.5)) * inv);
|
|
216
208
|
vec4 n64Col;
|
|
217
|
-
if (f.x + f.y < 1.0) {
|
|
218
|
-
|
|
219
|
-
n64Col = c00 + f.x * (c10 - c00) + f.y * (c01 - c00);
|
|
220
|
-
} else {
|
|
221
|
-
vec4 c11 = texture2D(tex, uv11);
|
|
222
|
-
n64Col = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11);
|
|
223
|
-
}
|
|
209
|
+
if (f.x + f.y < 1.0) { vec4 c00 = texture2D(tex, (i + vec2(0.5, 0.5)) * inv); n64Col = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }
|
|
210
|
+
else { vec4 c11 = texture2D(tex, (i + vec2(1.5, 1.5)) * inv); n64Col = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }
|
|
224
211
|
return mix(nearestSample, n64Col, clamp(mixStrength, 0.0, 1.0));
|
|
225
212
|
}
|
|
226
|
-
float ps1ProcTexelHash(vec2 cell) {
|
|
227
|
-
return fract(sin(dot(cell, vec2(127.1, 311.7))) * 43758.5453);
|
|
228
|
-
}
|
|
213
|
+
float ps1ProcTexelHash(vec2 cell) { return fract(sin(dot(cell, vec2(127.1, 311.7))) * 43758.5453); }
|
|
229
214
|
float ps1ProcN64ThreePoint(vec2 uv, float mixStrength) {
|
|
230
|
-
vec2 p = uv * 8.0 - 0.5;
|
|
231
|
-
vec2 i = floor(p);
|
|
232
|
-
vec2 f = p - i;
|
|
215
|
+
vec2 p = uv * 8.0 - 0.5, i = floor(p), f = p - i;
|
|
233
216
|
float nearestVal = ps1ProcTexelHash(floor(uv * 8.0));
|
|
234
217
|
if (mixStrength <= 0.001) return nearestVal;
|
|
235
|
-
float c10 = ps1ProcTexelHash(i + vec2(1.0, 0.0));
|
|
236
|
-
float
|
|
237
|
-
float n64Val;
|
|
238
|
-
if (f.x + f.y < 1.0) {
|
|
239
|
-
float c00 = ps1ProcTexelHash(i);
|
|
240
|
-
n64Val = c00 + f.x * (c10 - c00) + f.y * (c01 - c00);
|
|
241
|
-
} else {
|
|
242
|
-
float c11 = ps1ProcTexelHash(i + vec2(1.0, 1.0));
|
|
243
|
-
n64Val = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11);
|
|
244
|
-
}
|
|
218
|
+
float c10 = ps1ProcTexelHash(i + vec2(1.0, 0.0)), c01 = ps1ProcTexelHash(i + vec2(0.0, 1.0)), n64Val;
|
|
219
|
+
if (f.x + f.y < 1.0) { float c00 = ps1ProcTexelHash(i); n64Val = c00 + f.x * (c10 - c00) + f.y * (c01 - c00); }
|
|
220
|
+
else { float c11 = ps1ProcTexelHash(i + vec2(1.0, 1.0)); n64Val = c11 + (1.0 - f.y) * (c10 - c11) + (1.0 - f.x) * (c01 - c11); }
|
|
245
221
|
return mix(nearestVal, n64Val, clamp(mixStrength, 0.0, 1.0));
|
|
246
222
|
}
|
|
247
223
|
`, T = /* @__PURE__ */ new WeakSet();
|
|
@@ -251,9 +227,9 @@ function E(e, t) {
|
|
|
251
227
|
let n = e.onBeforeCompile, r = Object.prototype.hasOwnProperty.call(e, "customProgramCacheKey") ? e.customProgramCacheKey : null, i = t?.snap === void 0 ? d.uSnapStrength : { value: t.snap }, a = t?.dither === void 0 ? d.uDitherMix : { value: t.dither };
|
|
252
228
|
return e.onBeforeCompile = (t, r) => {
|
|
253
229
|
n && n.call(e, t, r), t.uniforms.uPs1Grid = d.uPs1Grid, t.uniforms.uSnapStrength = i, t.uniforms.uDitherMix = a, t.uniforms.uDitherScale = d.uDitherScale, t.uniforms.uColorQuant = d.uColorQuant, t.uniforms.uPaletteLut = d.uPaletteLut, t.uniforms.uAffineStrength = d.uAffineStrength, t.uniforms.uGouraudStrength = d.uGouraudStrength, t.uniforms.uN64FilterStrength = d.uN64FilterStrength, t.uniforms.uN64TexSize = d.uN64TexSize;
|
|
254
|
-
let o = t.vertexShader.includes("#include <defaultnormal_vertex>") || t.vertexShader.includes("transformedNormal"), s = t.vertexShader.includes("#include <begin_vertex>") || t.vertexShader.includes("transformed"),
|
|
255
|
-
t.vertexShader = "uniform vec2 uPs1Grid;\nuniform float uSnapStrength;\nuniform float uAffineStrength;\nuniform float uGouraudStrength;\nvarying float vRetroAffineW;\nvarying vec2 vRetroProcUv;\nvarying vec3 vRetroGouraud;\n" + t.vertexShader.replace("#include <project_vertex>", `#include <project_vertex>\n{\n vRetroAffineW = 1.0;\n vRetroProcUv = vec2(0.0);\n vRetroGouraud = vec3(1.0);\n if (uSnapStrength > 0.001 && gl_Position.w > 0.001) {\n vec4 snapped = gl_Position; snapped.xyz = gl_Position.xyz / gl_Position.w;\n vec2 ps1SafeGrid = max(uPs1Grid * mix(2.5, 1.0, clamp(uSnapStrength, 0.0, 1.0)), vec2(1.0));\n snapped.xy = floor(ps1SafeGrid * snapped.xy + 0.5) / ps1SafeGrid;\n snapped.xyz *= gl_Position.w; gl_Position = snapped;\n }\n${
|
|
256
|
-
}, e.customProgramCacheKey = () => r ? `${r.call(e)}
|
|
230
|
+
let o = t.vertexShader.includes("#include <defaultnormal_vertex>") || t.vertexShader.includes("transformedNormal"), s = e.type === "MeshBasicMaterial" || /#if\s+defined\s*\(\s*USE_ENVMAP\s*\)\s*\|\|\s*defined\s*\(\s*USE_SKINNING\s*\)[\s\S]*?#include\s*<defaultnormal_vertex>/.test(t.vertexShader), c = t.vertexShader.includes("#include <begin_vertex>") || t.vertexShader.includes("transformed"), l = o ? ` if (uGouraudStrength > 0.001) {\n${s ? "#if defined(USE_ENVMAP) || defined(USE_SKINNING)\n vec3 gN = normalize(transformedNormal);\n#else\n vec3 gN = vec3(0.0, 0.0, 1.0);\n#endif" : " vec3 gN = normalize(transformedNormal);"}\n vec3 gKey = normalize(vec3(-0.55, 0.72, 0.42));\n vec3 gRim = normalize(vec3(0.58, -0.25, -0.77));\n float gDiff = max(dot(gN, gKey), 0.0) * 0.85 + max(dot(gN, gRim), 0.0) * 0.30 + 0.18;\n float gSpec = pow(max(dot(reflect(-gKey, gN), vec3(0.0, 0.0, 1.0)), 0.0), 16.0) * 0.48;\n vRetroGouraud = mix(vec3(1.0), vec3(gDiff + gSpec), uGouraudStrength);\n }\n` : "", u = c ? " vRetroProcUv = vec2(transformed.x + transformed.z * 0.5, transformed.y + transformed.z * 0.5) * 0.5;\n if (uAffineStrength > 0.001 && gl_Position.w > 0.001) {\n float ps1ProcW = mix(1.0, max(gl_Position.w, 0.05), uAffineStrength);\n vRetroProcUv *= ps1ProcW; vRetroAffineW = ps1ProcW;\n }\n" : "";
|
|
231
|
+
t.vertexShader = "uniform vec2 uPs1Grid;\nuniform float uSnapStrength;\nuniform float uAffineStrength;\nuniform float uGouraudStrength;\nvarying float vRetroAffineW;\nvarying vec2 vRetroProcUv;\nvarying vec3 vRetroGouraud;\n" + t.vertexShader.replace("#include <project_vertex>", `#include <project_vertex>\n{\n vRetroAffineW = 1.0;\n vRetroProcUv = vec2(0.0);\n vRetroGouraud = vec3(1.0);\n if (uSnapStrength > 0.001 && gl_Position.w > 0.001) {\n vec4 snapped = gl_Position; snapped.xyz = gl_Position.xyz / gl_Position.w;\n vec2 ps1SafeGrid = max(uPs1Grid * mix(2.5, 1.0, clamp(uSnapStrength, 0.0, 1.0)), vec2(1.0));\n snapped.xy = floor(ps1SafeGrid * snapped.xy + 0.5) / ps1SafeGrid;\n snapped.xyz *= gl_Position.w; gl_Position = snapped;\n }\n${u} #ifdef USE_MAP\n if (uAffineStrength > 0.001 && gl_Position.w > 0.001) {\n float ps1W = mix(1.0, max(gl_Position.w, 0.05), uAffineStrength);\n vMapUv *= ps1W; vRetroAffineW = ps1W;\n }\n #endif\n${l}}`), t.fragmentShader = `uniform float uDitherMix;\nuniform float uAffineStrength;\nuniform float uGouraudStrength;\nuniform float uN64FilterStrength;\nuniform float uN64TexSize;\nvarying float vRetroAffineW;\nvarying vec2 vRetroProcUv;\nvarying vec3 vRetroGouraud;\n${w}\n` + t.fragmentShader.replace("#include <map_fragment>", "#ifdef USE_MAP\n{\n vec2 ps1Uv = (uAffineStrength > 0.001 && vRetroAffineW > 0.0001) ? (vMapUv / vRetroAffineW) : vMapUv;\n diffuseColor *= ps1SampleN64ThreePoint( map, ps1Uv, uN64TexSize, uN64FilterStrength );\n}\n#else\nif (uAffineStrength > 0.001 || uN64FilterStrength > 0.001) {\n vec2 ps1ProcUv = (uAffineStrength > 0.001 && vRetroAffineW > 0.0001) ? (vRetroProcUv / vRetroAffineW) : vRetroProcUv;\n float procGrain = ps1ProcN64ThreePoint(ps1ProcUv, uN64FilterStrength);\n diffuseColor.rgb *= mix(1.0, mix(0.86, 1.14, procGrain), max(uN64FilterStrength * 0.65, uAffineStrength * 0.85));\n}\n#endif").replace("#include <dithering_fragment>", "gl_FragColor.rgb *= mix(vec3(1.0), vRetroGouraud, uGouraudStrength);\ngl_FragColor.rgb = ps1QuantizeRetro(gl_FragColor.rgb, gl_FragCoord.xy, uDitherMix);");
|
|
232
|
+
}, e.customProgramCacheKey = () => r ? `${r.call(e)}_dream_nuschool_retro_v4` : "dream_nuschool_retro_v4", e.needsUpdate = !0, e;
|
|
257
233
|
}
|
|
258
234
|
var D = E;
|
|
259
235
|
function O(e, t) {
|