Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pkgs/configs/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const templateIndentTags = [
"ts",
"tsx",
"html",
"glsl",
"dedent",
"outdent",
];
Expand Down
1 change: 1 addition & 0 deletions .pkgs/configs/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const templateIndentTags = [
"ts",
"tsx",
"html",
"glsl",
"dedent",
"outdent",
];
Expand Down
2 changes: 2 additions & 0 deletions apps/website/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Background } from "#/components/Background";
import { ESLintReact } from "#/components/ESLintReact";
import { Card, Cards } from "fumadocs-ui/components/card";
import { CircleDotDashed, Gauge, Sliders, Zap } from "lucide-react";
Expand All @@ -17,6 +18,7 @@ const features = [
export default function HomePage() {
return (
<main className="w-full min-w-0 max-w-6xl px-8 pt-4 pb-12 md:px-12 mx-auto">
<Background />
<ESLintReact />
<article className="prose max-w-none">
<p className="text-center">
Expand Down
1 change: 1 addition & 0 deletions apps/website/app/layout.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export const baseOptions: BaseLayoutProps = {
<span>ESLint React</span>
</div>
),
transparentMode: "always",
},
};
4 changes: 4 additions & 0 deletions apps/website/app/overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
filter: brightness(0.5);
}

#nd-home-layout {
position: relative;
}

#nd-page .bsky-post [class*="embed-module_external"] {
display: none;
}
299 changes: 299 additions & 0 deletions apps/website/components/Background.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
"use client";

import type { PropsWithChildren } from "react";
import { cn } from "#/lib/cn";
import glsl from "dedent";
import { Mesh, Program, Renderer, Triangle, Vec2, Vec3 } from "ogl";
import { useEffect, useRef } from "react";

const vertex = glsl`
#version 300 es

precision highp float;

in vec3 position;
out vec2 vPos;

void main(){
gl_Position=vec4(position,1.);
vPos=position.xy;
}
`;

const fragment = glsl`
#version 300 es

precision highp float;

uniform float uTime;
uniform vec2 uResolution;
uniform vec3 color1;
uniform float colorSpacing;
uniform vec3 color4;
uniform float displacement;
uniform float zoom;
uniform float spacing;
uniform vec2 colorOffset;
uniform vec2 transformPosition;
uniform float noiseSize;
uniform float noiseIntensity;

in vec2 vPos;
out vec4 outColor;

// The MIT License
// Copyright © 2017 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Computes the analytic derivatives of a 3D Gradient Noise. This can be used for example to compute normals to a
// 3d rocks based on Gradient Noise without approximating the gradient by having to take central differences. More
// info here: http://iquilezles.org/www/articles/gradientnoise/gradientnoise.htm

// Value Noise 2D, Derivatives: https://www.shadertoy.com/view/4dXBRH
// Gradient Noise 2D, Derivatives: https://www.shadertoy.com/view/XdXBRH
// Value Noise 3D, Derivatives: https://www.shadertoy.com/view/XsXfRH
// Gradient Noise 3D, Derivatives: https://www.shadertoy.com/view/4dffRH
// Value Noise 2D : https://www.shadertoy.com/view/lsf3WH
// Value Noise 3D : https://www.shadertoy.com/view/4sfGzS
// Gradient Noise 2D : https://www.shadertoy.com/view/XdXGW8
// Gradient Noise 3D : https://www.shadertoy.com/view/Xsl3Dl
// Simplex Noise 2D : https://www.shadertoy.com/view/Msf3WH

vec3 gradientDerivativesNoise3DHash(vec3 p){
p=fract(p*vec3(.1031,.1030,.0973));
p+=dot(p,p.yxz+33.3333);
return fract((p.xxy+p.yxx)*p.zyx);
}

// return value noise (in x) and its derivatives (in yzw)
vec4 gradientDerivativesNoise3D(in vec3 x){
// grid
vec3 p=floor(x);
vec3 w=fract(x);

// quintic interpolant
vec3 u=w*w*w*(w*(w*6.-15.)+10.);
vec3 du=30.*w*w*(w*(w-2.)+1.);

// gradients
vec3 ga=gradientDerivativesNoise3DHash(p+vec3(0.,0.,0.));
vec3 gb=gradientDerivativesNoise3DHash(p+vec3(1.,0.,0.));
vec3 gc=gradientDerivativesNoise3DHash(p+vec3(0.,1.,0.));
vec3 gd=gradientDerivativesNoise3DHash(p+vec3(1.,1.,0.));
vec3 ge=gradientDerivativesNoise3DHash(p+vec3(0.,0.,1.));
vec3 gf=gradientDerivativesNoise3DHash(p+vec3(1.,0.,1.));
vec3 gg=gradientDerivativesNoise3DHash(p+vec3(0.,1.,1.));
vec3 gh=gradientDerivativesNoise3DHash(p+vec3(1.,1.,1.));

// projections
float va=dot(ga,w-vec3(0.,0.,0.));
float vb=dot(gb,w-vec3(1.,0.,0.));
float vc=dot(gc,w-vec3(0.,1.,0.));
float vd=dot(gd,w-vec3(1.,1.,0.));
float ve=dot(ge,w-vec3(0.,0.,1.));
float vf=dot(gf,w-vec3(1.,0.,1.));
float vg=dot(gg,w-vec3(0.,1.,1.));
float vh=dot(gh,w-vec3(1.,1.,1.));

// interpolations
return vec4(va+u.x*(vb-va)+u.y*(vc-va)+u.z*(ve-va)+u.x*u.y*(va-vb-vc+vd)+u.y*u.z*(va-vc-ve+vg)+u.z*u.x*(va-vb-ve+vf)+(-va+vb+vc-vd+ve-vf-vg+vh)*u.x*u.y*u.z,// value
ga+u.x*(gb-ga)+u.y*(gc-ga)+u.z*(ge-ga)+u.x*u.y*(ga-gb-gc+gd)+u.y*u.z*(ga-gc-ge+gg)+u.z*u.x*(ga-gb-ge+gf)+(-ga+gb+gc-gd+ge-gf-gg+gh)*u.x*u.y*u.z+// derivatives
du*(vec3(vb,vc,ve)-va+u.yzx*vec3(va-vb-vc+vd,va-vc-ve+vg,va-vb-ve+vf)+u.zxy*vec3(va-vb-ve+vf,va-vb-vc+vd,va-vc-ve+vg)+u.yzx*u.zxy*(-va+vb+vc-vd+ve-vf-vg+vh)));
}

float hash(vec2 p){
p=50.*fract(p*.3183099+vec2(.71,.113));
return-1.+2.*fract(p.x*p.y*(p.x+p.y));
}

float computeNoise(in vec2 p){
vec2 i=floor(p);
vec2 f=fract(p);

vec2 u=f*f*(3.-2.*f);

return mix(mix(hash(i+vec2(0.,0.)),
hash(i+vec2(1.,0.)),u.x),
mix(hash(i+vec2(0.,1.)),
hash(i+vec2(1.,1.)),u.x),u.y);
}

void main(){
vec2 pos=vPos;
pos.x*=min(1.,uResolution.x/uResolution.y);
pos.y*=min(1.,uResolution.y/uResolution.x);
pos/=zoom;
pos+=transformPosition;

vec2 noiseLocalPosition=pos*.5+.5;
vec3 displacementNoise=gradientDerivativesNoise3D(vec3(noiseLocalPosition,uTime*.1)).xyz;

pos+=displacementNoise.xz*displacement;

vec2 offsettedPosition=pos;
offsettedPosition-=colorOffset;
offsettedPosition=mod(offsettedPosition-spacing,vec2(spacing*2.))-spacing;

vec3 color=vec3(0.);
color=mix(color1,color,smoothstep(0.,1.,distance(offsettedPosition,vec2(0.,colorSpacing*1.5))));
color=mix(color4,color,smoothstep(0.,1.,distance(offsettedPosition,vec2(0.,-colorSpacing*1.5))));
float noise=computeNoise(vPos*uResolution/noiseSize);
color+=noise*noiseIntensity;
color=clamp(color,0.,1.);

outColor=vec4(color,.0125);
}
`;

function createUniforms(width: number, height: number) {
return {
color1: {
value: new Vec3(0.247, 0.341, 0.463),
},
color4: {
value: new Vec3(0.4, 0.44, 0.54),
},
colorOffset: {
value: new Vec2(-0.774, -0.206),
},
colorRotation: {
value: -0.38,
},
colorSize: {
value: 0.58,
},
colorSpacing: {
value: 0.4,
},
colorSpread: {
value: 4.52,
},
displacement: {
value: 1.16,
},
noiseIntensity: {
value: 0.08,
},
noiseSize: {
value: 0.7,
},
spacing: {
value: 4.27,
},
transformPosition: {
value: new Vec2(-0.3, -0.439),
},
uResolution: {
value: new Vec2(width, height),
},
uTime: {
value: 0.8,
},
zoom: {
value: 0.62,
},
};
}

export type BackgroundProps = PropsWithChildren<{
className?: string;
}>;

export function Background({ children, className }: BackgroundProps) {
const rRaf = useRef<number>(null);
const rRoot = useRef<HTMLDivElement>(null);
const rCanvas = useRef<HTMLCanvasElement>(null);

useEffect(() => {
if (rRoot.current == null) return;
if (rCanvas.current == null) return;

const root = rRoot.current;
const canvas = rCanvas.current;
const rect = root.getBoundingClientRect();
const uniforms = createUniforms(rect.width, rect.height);
const renderer = new Renderer({
alpha: true,
antialias: false,
canvas,
depth: false,
dpr: window.devicePixelRatio,
height: rect.height,
powerPreference: "high-performance",
premultipliedAlpha: true,
webgl: 2,
width: rect.width,
});

const { gl } = renderer;
const geometry = new Triangle(gl);
const program = new Program(gl, {
fragment,
transparent: true,
uniforms,
vertex,
});
const mesh = new Mesh(gl, { geometry, program });

function update(time: number) {
uniforms.uTime.value = time * 0.0005;
renderer.render({ scene: mesh });
rRaf.current = requestAnimationFrame(update);
}

const ro = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.target !== root) continue;
const rect = entry.contentRect;
uniforms.uResolution.value.set(rect.width, rect.height);
renderer.setSize(rect.width, rect.height);
renderer.render({ scene: mesh });
return;
}
});

ro.observe(root);
rRaf.current = requestAnimationFrame(update);
canvas.style.opacity = "1";

return () => {
ro.disconnect();
if (rRaf.current == null) return;
cancelAnimationFrame(rRaf.current);
};
}, []);

return (
<div
className={cn(styles.root, className)}
ref={rRoot}
>
<canvas
className={styles.canvas}
ref={rCanvas}
/>
{children}
</div>
);
}

const styles = {
root: cn(
"absolute",
"left-0",
"top-0",
"w-full",
"h-full",
"pointer-events-none",
),

canvas: cn(
"w-full",
"h-full",
"bg-transparent",
"opacity-0",
"transition-opacity",
"duration",
"ease-[ease-in-out]",
),
};
1 change: 1 addition & 0 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lucide-react": "^0.503.0",
"next": "^15.3.1",
"next-view-transitions": "^0.3.4",
"ogl": "^1.0.11",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"shiki": "^3.3.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.