Skip to content

Commit 1ab8f95

Browse files
committed
feat: add WebGLShader component for an animated background with built-in performance monitoring and reduced motion fallback.
1 parent 68bbec4 commit 1ab8f95

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

components/ui/web-gl-shader.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function WebGLShader() {
4747
touchPoints: 0,
4848
colorDepth: 24,
4949
hdrSupported: false,
50+
colorGamut: "sRGB",
5051
// -- WebGL --
5152
webglVersion: "WebGL 1.0",
5253
maxTextureSize: 0,
@@ -167,10 +168,14 @@ export function WebGLShader() {
167168
const colorDepth = typeof screen !== "undefined" ? screen.colorDepth : 24;
168169
const nativeDpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
169170

170-
// HDR support detection
171+
// HDR & color gamut detection
171172
let hdrSupported = false;
173+
let colorGamut = "sRGB";
172174
if (typeof window !== "undefined") {
173175
hdrSupported = window.matchMedia("(dynamic-range: high)").matches;
176+
if (window.matchMedia("(color-gamut: rec2020)").matches) colorGamut = "Rec. 2020";
177+
else if (window.matchMedia("(color-gamut: p3)").matches) colorGamut = "Display P3";
178+
else colorGamut = "sRGB";
174179
}
175180

176181
// Connection info
@@ -309,6 +314,7 @@ export function WebGLShader() {
309314
touchPoints,
310315
colorDepth,
311316
hdrSupported,
317+
colorGamut,
312318
nativeDpr,
313319
dprMultiplier,
314320
actualDpr: currentPixelRatio,
@@ -522,7 +528,8 @@ export function WebGLShader() {
522528
<div className="flex justify-between gap-4"><span>Render Res</span><span className="text-white font-medium tabular-nums">{Math.round(stats.canvasWidth)}&times;{Math.round(stats.canvasHeight)}</span></div>
523529
<div className="flex justify-between gap-4 text-[10px] text-white/40"><span>Pixels/Frame</span><span className="tabular-nums">~{(stats.canvasWidth * stats.canvasHeight).toLocaleString()}</span></div>
524530
<div className="flex justify-between gap-4"><span>Color Depth</span><span className="text-white font-medium">{stats.colorDepth}-bit</span></div>
525-
<div className="flex justify-between gap-4"><span>HDR Display</span><span className={`font-medium ${stats.hdrSupported ? "text-emerald-400" : "text-white/50"}`}>{stats.hdrSupported ? "Supported" : "Not detected"}</span></div>
531+
<div className="flex justify-between gap-4"><span>Color Gamut</span><span className={`font-medium ${stats.colorGamut !== "sRGB" ? "text-emerald-400" : "text-white"}`}>{stats.colorGamut}</span></div>
532+
<div className="flex justify-between gap-4"><span>HDR Display</span><span className={`font-medium ${stats.hdrSupported ? "text-emerald-400" : "text-white/50"}`}>{stats.hdrSupported ? "Supported" : "Standard (SDR)"}</span></div>
526533
</div>
527534
</section>
528535

0 commit comments

Comments
 (0)