feat: add psx style vertex snapping and affine distortion

This commit is contained in:
2026-06-02 03:29:07 -03:00
parent b7e61b4240
commit 8dcc888d5c
3 changed files with 71 additions and 14 deletions
+2 -1
View File
@@ -28,7 +28,7 @@ function PostProcessing() {
}, []); }, []);
return (<EffectComposer> return (<EffectComposer>
<Pixelation granularity={wasCaught ? 18 : 12} /> <Pixelation granularity={wasCaught ? 18 : 10} />
<Vignette /> <Vignette />
<Noise opacity={wasCaught ? 0.01 : 0.005} /> <Noise opacity={wasCaught ? 0.01 : 0.005} />
<BrightnessContrast <BrightnessContrast
@@ -87,6 +87,7 @@ export default function Fear() {
<color attach="background" args={['#050505']} /> <color attach="background" args={['#050505']} />
<ambientLight intensity={0.0225} /> <ambientLight intensity={0.0225} />
{/* <ambientLight intensity={2} /> */}
<fogExp2 attach='fog' args={[0x050505, 0.035]} /> <fogExp2 attach='fog' args={[0x050505, 0.035]} />
<PostProcessing /> <PostProcessing />
@@ -15,7 +15,6 @@ export default function FinaleText() {
return () => unsubscribe(); return () => unsubscribe();
}); });
let elementCount = (FEAR_SETTINGS.EVENT_FINALE_TEXT_COUNT / FEAR_SETTINGS.EVENT_FINALE_DURATION) * progression; let elementCount = (FEAR_SETTINGS.EVENT_FINALE_TEXT_COUNT / FEAR_SETTINGS.EVENT_FINALE_DURATION) * progression;
let testElements: Array<JSX.Element> = []; let testElements: Array<JSX.Element> = [];
+69 -12
View File
@@ -5,6 +5,64 @@ import { useTexture, PositionalAudio } from "@react-three/drei";
import * as THREE from "three"; import * as THREE from "three";
import { useFrame } from "@react-three/fiber"; import { useFrame } from "@react-three/fiber";
function ShaderPatch(shader: { vertexShader: string, fragmentShader: string, uniforms: Object }) {
shader.vertexShader = `
varying float vDepth;
#ifdef USE_MAP
varying vec2 vAffineUv;
#endif
${shader.vertexShader}
`;
shader.vertexShader = shader.vertexShader.replace(
`#include <project_vertex>`,
`
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
float precisionModifier = 200.0;
gl_Position.xy /= gl_Position.w;
gl_Position.xy = floor(gl_Position.xy * precisionModifier) / precisionModifier;
gl_Position.xy *= gl_Position.w;
vDepth = gl_Position.w;
#ifdef USE_MAP
vAffineUv = vMapUv * gl_Position.w;
#endif
`
);
shader.fragmentShader = `
varying float vDepth;
#ifdef USE_MAP
varying vec2 vAffineUv;
#endif
${shader.fragmentShader}
`;
shader.fragmentShader = shader.fragmentShader.replace(
`#include <map_fragment>`,
`
#ifdef USE_MAP
vec2 flatAffineUV = vAffineUv / max(vDepth, 0.001);
vec2 warpDiff = flatAffineUV - vMapUv;
float warpDist = length(warpDiff);
float maxDistortion = 0.25;
float falloff = maxDistortion / (maxDistortion + warpDist);
vec2 finalUV = vMapUv + (warpDiff * falloff);
vec4 texelColor = texture2D( map, finalUV );
diffuseColor *= texelColor;
#endif
`
);
}
interface DoorProps { interface DoorProps {
position: [number, number, number]; position: [number, number, number];
rotation: [number, number, number]; rotation: [number, number, number];
@@ -283,6 +341,7 @@ export default function Hallway() {
emissive="#a8a1a1" emissive="#a8a1a1"
emissiveIntensity={0.8} emissiveIntensity={0.8}
roughness={0.9} roughness={0.9}
onBeforeCompile={ShaderPatch}
/> />
</mesh> </mesh>
</group> </group>
@@ -293,12 +352,11 @@ export default function Hallway() {
rotation={[-Math.PI / 2, 0, 0]} rotation={[-Math.PI / 2, 0, 0]}
position={[0, 0, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]} position={[0, 0, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}
> >
<planeGeometry args={[FEAR_SETTINGS.HALLWAY_WIDTH, FEAR_SETTINGS.HALLWAY_LENGTH]} /> <planeGeometry args={[FEAR_SETTINGS.HALLWAY_WIDTH, FEAR_SETTINGS.HALLWAY_LENGTH, 4, 10]} />
<meshStandardMaterial <meshStandardMaterial
ref={(el) => { if (el) floorMaterialsRef.current.push(el); }} ref={(el) => { if (el) floorMaterialsRef.current.push(el); }}
map={floorTex} map={floorTex}
roughness={0.8} onBeforeCompile={ShaderPatch}
metalness={0.2}
/> />
</mesh> </mesh>
@@ -308,24 +366,22 @@ export default function Hallway() {
rotation={[Math.PI / 2, 0, 0]} rotation={[Math.PI / 2, 0, 0]}
position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]} position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}
> >
<planeGeometry args={[FEAR_SETTINGS.HALLWAY_WIDTH, FEAR_SETTINGS.HALLWAY_LENGTH]} /> <planeGeometry args={[FEAR_SETTINGS.HALLWAY_WIDTH, FEAR_SETTINGS.HALLWAY_LENGTH, 4, 10]} />
<meshStandardMaterial <meshStandardMaterial
ref={(el) => { if (el) floorMaterialsRef.current.push(el); }} ref={(el) => { if (el) floorMaterialsRef.current.push(el); }}
map={floorTex} map={floorTex}
roughness={0.8} onBeforeCompile={ShaderPatch}
metalness={0.2}
/> />
</mesh> </mesh>
{/* left wall */} {/* left wall */}
<group name="left-wall-group"> <group name="left-wall-group">
<mesh rotation={[0, Math.PI / 2, 0]} position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT / 2, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}> <mesh rotation={[0, Math.PI / 2, 0]} position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT / 2, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}>
<planeGeometry args={[FEAR_SETTINGS.HALLWAY_LENGTH, FEAR_SETTINGS.HALLWAY_HEIGHT]} /> <planeGeometry args={[FEAR_SETTINGS.HALLWAY_LENGTH, FEAR_SETTINGS.HALLWAY_HEIGHT, 10, 4]} />
<meshStandardMaterial <meshStandardMaterial
ref={(el) => { if (el) wallMaterialsRef.current.push(el); }} ref={(el) => { if (el) wallMaterialsRef.current.push(el); }}
map={wallTex} map={wallTex}
roughness={0.7} onBeforeCompile={ShaderPatch}
metalness={0.1}
/> />
</mesh> </mesh>
{!isRustActive && ( {!isRustActive && (
@@ -339,12 +395,11 @@ export default function Hallway() {
{/* right wall */} {/* right wall */}
<group name="right-wall-group"> <group name="right-wall-group">
<mesh rotation={[0, -Math.PI / 2, 0]} position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT / 2, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}> <mesh rotation={[0, -Math.PI / 2, 0]} position={[0, FEAR_SETTINGS.HALLWAY_HEIGHT / 2, -FEAR_SETTINGS.HALLWAY_LENGTH / 2]}>
<planeGeometry args={[FEAR_SETTINGS.HALLWAY_LENGTH, FEAR_SETTINGS.HALLWAY_HEIGHT]} /> <planeGeometry args={[FEAR_SETTINGS.HALLWAY_LENGTH, FEAR_SETTINGS.HALLWAY_HEIGHT, 10, 4]} />
<meshStandardMaterial <meshStandardMaterial
ref={(el) => { if (el) wallMaterialsRef.current.push(el); }} ref={(el) => { if (el) wallMaterialsRef.current.push(el); }}
map={wallTex} map={wallTex}
roughness={0.7} onBeforeCompile={ShaderPatch}
metalness={0.1}
/> />
</mesh> </mesh>
{!isRustActive && ( {!isRustActive && (
@@ -366,6 +421,7 @@ export default function Hallway() {
color="#a5aca8" color="#a5aca8"
roughness={0.0} roughness={0.0}
metalness={0.4} metalness={0.4}
onBeforeCompile={ShaderPatch}
/> />
</mesh> </mesh>
))} ))}
@@ -385,6 +441,7 @@ export default function Hallway() {
color="#a5aca8" color="#a5aca8"
roughness={0.0} roughness={0.0}
metalness={0.4} metalness={0.4}
onBeforeCompile={ShaderPatch}
/> />
</mesh> </mesh>
); );