Skip to content

Commit 3cb05da

Browse files
committed
Checking in changes made to secret modal and context
1 parent 274fec7 commit 3cb05da

4 files changed

Lines changed: 242 additions & 32 deletions

File tree

‎src/components/background/PixelatedBackground.tsx‎

Lines changed: 174 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,182 @@
22

33
import React, { useEffect, useRef } from 'react';
44
import "./pixelatedBackground.css";
5+
import { useSecret } from '@src/context/SecretContext';
56

6-
// 2. Define Vertex Shader (Draws a full-screen quad)
7-
const vsSource = `
7+
export default function PixelatedBackground() {
8+
const canvasRef = useRef<HTMLCanvasElement | null>(null);
9+
const contextRef = useRef<WebGLRenderingContext | null>(null);
10+
const shaderProgramRef = useRef<WebGLProgram | null>(null);
11+
const positionLocationRef = useRef<number | null>(null);
12+
const timeUniformLocationRef = useRef<WebGLUniformLocation | null>(null);
13+
const resolutionUniformLocationRef = useRef<WebGLUniformLocation | null>(null);
14+
const positionBufferRef = useRef<WebGLBuffer | null>(null);
15+
const frameRef = useRef<number | null>(null);
16+
const { isMissingNoSecretActive, is404SecretActive } = useSecret();
17+
18+
// 2. Define Vertex Shader (Draws a full-screen quad)
19+
const vsSource = `
820
attribute vec2 position;
921
void main() {
1022
gl_Position = vec4(position, 0.0, 1.0);
1123
}
1224
`;
1325

14-
// 3. Define Fragment Shader (Generates pixelated procedural waves)
15-
const fsSource = `
16-
precision mediump float;
17-
uniform vec2 u_resolution;
18-
uniform float u_time;
26+
// 3. Define Fragment Shader (Generates pixelated procedural waves)
27+
const defaultfsSource = `
28+
precision mediump float;
29+
uniform vec2 u_resolution;
30+
uniform float u_time;
1931
20-
void main() {
21-
// Pixel grid sizing: Adjust this number to change pixel size
22-
float pixelSize = 12.0; // 8.0
32+
void main() {
33+
// Pixel grid sizing: Adjust this number to change pixel size
34+
float pixelSize = 12.0; // 8.0
2335
24-
// Quantize coordinates to create the pixelated effect
25-
vec2 uv = floor(gl_FragCoord.xy / pixelSize) * pixelSize / u_resolution.xy;
36+
// Quantize coordinates to create the pixelated effect
37+
vec2 uv = floor(gl_FragCoord.xy / pixelSize) * pixelSize / u_resolution.xy;
2638
27-
// Create an example retro procedural animation pattern
28-
float colorA = sin(uv.x * 4.0 + u_time) * 0.5 + 0.5;
29-
float colorB = cos(uv.y * 4.0 - u_time) * 0.5 + 0.5;
39+
// Create an example retro procedural animation pattern
40+
float colorA = sin(uv.x * 4.0 + u_time) * 0.5 + 0.5;
41+
float colorB = cos(uv.y * 4.0 - u_time) * 0.5 + 0.5;
3042
31-
gl_FragColor = vec4(colorA, colorB, 0.8, 1.0);
43+
gl_FragColor = vec4(colorA, colorB, 0.8, 1.0);
44+
}
45+
`;
46+
47+
const missingNofsSource = `
48+
precision mediump float;
49+
uniform vec2 u_resolution;
50+
uniform float u_time;
51+
52+
// Retro Pseudorandom Hash Function
53+
float rand(vec2 co) {
54+
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
55+
}
56+
57+
void main() {
58+
// 1. Define gameboy/retro-esque MissingNo. hex colors
59+
vec4 colorWhite = vec4(0.93, 0.93, 0.88, 0.5);
60+
vec4 colorLight = vec4(0.68, 0.65, 0.70, 0.5); // Iconic light purple/gray
61+
vec4 colorDark = vec4(0.40, 0.38, 0.35, 0.5); // Fawn / dark gray
62+
vec4 colorBlack = vec4(0.08, 0.08, 0.10, 0.5);
63+
64+
// 2. Set pixel sizes to look like a raw Game Boy VRAM dump
65+
// MissingNo blocks are wider horizontally than they are tall!
66+
vec2 blockDimensions = vec2(8.0, 4.0); //vec2(32.0, 12.0);
67+
68+
// Get base pixel coordinates
69+
vec2 blockCoord = floor(gl_FragCoord.xy / blockDimensions);
70+
71+
// 3. Inject horizontal shifting to simulate data misalignment
72+
// Every horizontal row shifts left or right based on time and row hash
73+
float shiftTime = floor(u_time * 2.0); // 8.0 Steps smoothly like 8-bit frames
74+
float rowShift = floor(rand(vec2(blockCoord.y, shiftTime)) * 12.0) - 6.0;
75+
blockCoord.x += rowShift;
76+
77+
// 4. Generate the glitch sequence hash value
78+
float noiseValue = rand(blockCoord);
79+
80+
// 5. Build an abstract shape bounding system
81+
// MissingNo looks like a rough 'reversed L' block shape
82+
vec2 uv = gl_FragCoord.xy / u_resolution.xy;
83+
84+
// Generate random empty transparent holes to break the background up
85+
float maskingNoise = rand(floor(gl_FragCoord.xy / vec2(64.0, 64.0)) + shiftTime);
86+
if (maskingNoise > 0.82) {
87+
//discard; // Erases sections dynamically to replicate broken sprite data
3288
}
89+
90+
// 6. Map the raw float noise cleanly to the 4 discrete colors
91+
vec4 finalColor;
92+
if (noiseValue < 0.25) {
93+
finalColor = colorBlack;
94+
} else if (noiseValue < 0.50) {
95+
finalColor = colorDark;
96+
} else if (noiseValue < 0.75) {
97+
finalColor = colorLight;
98+
} else {
99+
finalColor = colorWhite;
100+
}
101+
102+
gl_FragColor = finalColor;
103+
}
33104
`;
34105

35-
export default function PixelatedBackground() {
36-
const canvasRef = useRef<HTMLCanvasElement | null>(null);
37-
const contextRef = useRef<WebGLRenderingContext | null>(null);
38-
const shaderProgramRef = useRef<WebGLProgram | null>(null);
39-
const positionLocationRef = useRef<number | null>(null);
40-
const timeUniformLocationRef = useRef<WebGLUniformLocation | null>(null);
41-
const resolutionUniformLocationRef = useRef<WebGLUniformLocation | null>(null);
42-
const positionBufferRef = useRef<WebGLBuffer | null>(null);
43-
const frameRef = useRef<number | null>(null);
106+
const sh1fsSource = `
107+
precision mediump float;
108+
uniform vec2 u_resolution;
109+
uniform float u_time;
110+
111+
// Retro Pseudorandom Hash Function
112+
float rand(vec2 co) {
113+
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
114+
}
115+
116+
// 2D Noise for organic, rolling fog layers
117+
float noise(vec2 st) {
118+
vec2 i = floor(st);
119+
vec2 f = fract(st);
120+
float a = rand(i);
121+
float b = rand(i + vec2(1.0, 0.0));
122+
float c = rand(i + vec2(0.0, 1.0));
123+
float d = rand(i + vec2(1.0, 1.0));
124+
vec2 u = f * f * (3.0 - 2.0 * f);
125+
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
126+
}
127+
128+
void main() {
129+
// 1. Core PS1 Silent Hill Color Palette (Industrial, grime-tinted grays)
130+
vec3 fogDark = vec3(0.18, 0.18, 0.19); // Deep, oppressive background fog
131+
vec3 fogLight = vec3(0.42, 0.41, 0.40); // Ash-choked daylight sky fog
132+
vec3 ashColor = vec3(0.55, 0.55, 0.53); // Drifting burnt flakes
133+
134+
// 2. Pixelation Grid
135+
float pixelSize = 4.0;
136+
vec2 pixelCoord = floor(gl_FragCoord.xy / pixelSize) * pixelSize;
137+
vec2 uv = pixelCoord / u_resolution.xy;
138+
139+
// 3. Procedural Fog Simulation (Layered rolling noise)
140+
vec2 fogUV = uv * 3.0;
141+
fogUV.y -= u_time * 0.05; // Slow upward/forward drifting motion
142+
fogUV.x += sin(u_time * 0.1 + uv.y) * 0.2; // Eerie swaying swing
143+
144+
float fogDensity = noise(fogUV) * 0.6 + noise(fogUV * 2.5 + u_time * 0.02) * 0.4;
145+
vec3 finalFog = mix(fogDark, fogLight, fogDensity);
146+
147+
// 4. PS1 Ordering Dither Matrix Simulation (4x4 retro posterization grid)
148+
float ditherPattern = mod(pixelCoord.x / pixelSize, 4.0);
149+
float ditherPatternY = mod(pixelCoord.y / pixelSize, 4.0);
150+
float ditherThreshold = (ditherPattern * 4.0 + ditherPatternY) / 16.0;
151+
152+
// Crunch the fog colors into dithered gradients
153+
finalFog += (ditherThreshold - 0.5) * 0.07;
154+
finalFog = floor(finalFog * 8.0) / 8.0; // Hard clamp to 15-bit color space emulation
155+
156+
// 5. Slowly Falling Ash Layer
157+
vec2 ashUV = pixelCoord;
158+
ashUV.y += u_time * 45.0; // Drifts downwards continuously
159+
ashUV.x += sin(u_time * 0.5 + pixelCoord.y * 0.02) * 15.0; // Sideways wind swaying
160+
161+
// Slice screen into tiny discrete particle cell structures
162+
vec2 ashGrid = floor(ashUV / 16.0);
163+
float ashSpawnHash = rand(ashGrid);
164+
165+
float ashParticle = 0.0;
166+
// Generate individual falling flakes based on threshold matching
167+
if (ashSpawnHash > 0.96) {
168+
vec2 centerOffset = fract(ashUV / 16.0) - 0.5;
169+
// Keep flakes sharp and blocky instead of circular
170+
if (abs(centerOffset.x) < 0.2 && abs(centerOffset.y) < 0.2) {
171+
ashParticle = 1.0;
172+
}
173+
}
174+
175+
// 6. Blend Ash over Fog
176+
vec3 finalColor = mix(finalFog, ashColor, ashParticle * 0.7);
177+
178+
gl_FragColor = vec4(finalColor, 1.0);
179+
}
180+
`;
44181

45182
// Render loop
46183
function render(time: number) {
@@ -79,6 +216,18 @@ export default function PixelatedBackground() {
79216
const gl = contextRef.current;
80217
if (!gl) return;
81218

219+
let fsSource;
220+
221+
if (is404SecretActive) {
222+
fsSource = sh1fsSource;
223+
}
224+
else if (isMissingNoSecretActive) {
225+
fsSource = missingNofsSource;
226+
}
227+
else {
228+
fsSource = defaultfsSource;
229+
}
230+
82231
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vsSource);
83232
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fsSource);
84233

‎src/components/background/pixelatedBackground.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ canvas.pixelated {
33
image-rendering: -webkit-crisp-edges;
44
image-rendering: pixelated;
55
image-rendering: crisp-edges;
6+
opacity: 0.3;
7+
}
8+
9+
.missing-no {
10+
image-rendering: -moz-crisp-edges;
11+
image-rendering: -webkit-crisp-edges;
12+
image-rendering: pixelated;
13+
image-rendering: crisp-edges;
14+
opacity: 0.3;
615
}
716

817
.xmb-main, .xmb-category-title,

‎src/components/modal/views/secrets.tsx‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import React, { useCallback, useEffect, useRef, useState } from "react";
4-
import { useSecret, StatDefinition, PlayerStat, AchievementId } from "@context/SecretContext";
4+
import { useSecret, StatDefinition, PlayerStat, AchievementId, SecretGroupType } from "@context/SecretContext";
55
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
66
import { faQuestionCircle, faLock, faUnlock, faUnlockAlt, faCheck, faCheckCircle, faToggleOff, faToggleOn, IconDefinition, faMinus } from "@fortawesome/free-solid-svg-icons";
77
import "./secrets.css";
@@ -129,7 +129,7 @@ const SecretView = ({ id, stat }: SecretViewProps) => {
129129

130130
export const SecretsView = ({ title, description }: SecretsViewProps) => {
131131

132-
const { stats } = useSecret();
132+
const { stats, secrets, secretGroups } = useSecret();
133133

134134
return (
135135
<>
@@ -148,10 +148,30 @@ export const SecretsView = ({ title, description }: SecretsViewProps) => {
148148
</thead>
149149
<tbody className="bg-gray-600/40">
150150
{
151-
stats && Array.from(stats).map(([id, stat]) => {
152-
return (
153-
<SecretView key={id} id={id} stat={stat} />
154-
);
151+
stats &&
152+
Array.from(Object.keys(secretGroups)).map(g => {
153+
const type = g as SecretGroupType;
154+
const group = secretGroups[type];
155+
const items = Array.from(stats).filter(stat => {
156+
if (type === 'default') return stat[1].stat.type === undefined;
157+
return stat[1].stat.type === type;
158+
});
159+
return <>
160+
<tr className="text-xl secret-group-title my-2 text-left">
161+
<td colSpan={3} className="text-xl py-2">
162+
<div className="text-left w-full h-full pl-2">
163+
{group.title}
164+
</div>
165+
</td>
166+
</tr>
167+
{
168+
items && items.map(([id, stat]) => {
169+
return (
170+
<SecretView key={id} id={id} stat={stat} />
171+
);
172+
})
173+
}
174+
</>;
155175
})
156176
}
157177
</tbody>

‎src/context/SecretContext.tsx‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ const pspFont = localFont({
4343
preload: true,
4444
});
4545

46+
export type SecretGroupType = 'default' | 'bg' | 'icons';
47+
4648
export interface StatDefinition {
4749
id: AchievementId;
4850
title: string;
4951
description?: string;
52+
type?: SecretGroupType;
5053
// TODO: add icon for locked/unlocked
5154
// TODO: add a hint indicating how this can be unlocked
5255
}
@@ -58,6 +61,29 @@ export interface PlayerStat {
5861
isEnabled: boolean;
5962
}
6063

64+
export interface SecretGroup {
65+
type: SecretGroupType,
66+
title: string,
67+
}
68+
69+
export type SecretGroupMap = Record<SecretGroupType, SecretGroup>;
70+
71+
export const secretGroups: SecretGroupMap =
72+
{
73+
['default']: {
74+
type: 'default',
75+
title: 'Misc.',
76+
},
77+
['bg']: {
78+
type: 'bg',
79+
title: 'Background',
80+
},
81+
['icons']: {
82+
type: 'icons',
83+
title: 'Icons',
84+
},
85+
};
86+
6187
export type SecretMap = Record<AchievementId, StatDefinition>;
6288

6389
export const secrets: SecretMap =
@@ -66,16 +92,19 @@ export const secrets: SecretMap =
6692
id: AchievementId.konami_code,
6793
title: 'Konami Code',
6894
description: 'Entered the Konami Code.',
95+
type: 'bg',
6996
},
7097
[AchievementId.psp_code]: {
7198
id: AchievementId.psp_code,
7299
title: 'PSP Mode',
73100
description: 'Flash CFW.',
101+
type: 'icons',
74102
},
75103
[AchievementId._404]: {
76104
id: AchievementId._404,
77105
title: '404',
78106
description: "There was a page here, but it's gone now.",
107+
type: 'bg',
79108
},
80109
[AchievementId.iwhbyd]: {
81110
id: AchievementId.iwhbyd,
@@ -96,6 +125,7 @@ export const secrets: SecretMap =
96125
id: AchievementId.missing_no,
97126
title: 'MissingNo.',
98127
description: "<Memory Corrupted>",
128+
type: 'bg',
99129
},
100130
};
101131

@@ -125,7 +155,8 @@ export interface SecretContextType {
125155
lockSecret: (id: AchievementId) => Promise<void>;
126156
unlockSecret: (id: AchievementId) => Promise<void>;
127157
toggleSecret: (id: AchievementId) => Promise<void>;
128-
secrets: Record<AchievementId, StatDefinition>;
158+
secrets: Record<string, StatDefinition>;
159+
secretGroups: Record<SecretGroupType, SecretGroup>;
129160
stats: Map<AchievementId, PlayerStat> | null;
130161
pspFontClass: string;
131162
}
@@ -464,6 +495,7 @@ export function SecretProvider({ children }: { children: React.ReactNode }) {
464495
lockSecret,
465496
unlockSecret,
466497
toggleSecret,
498+
secretGroups,
467499
secrets,
468500
stats,
469501
pspFontClass: pspFont.className,

0 commit comments

Comments
 (0)