Skip to content
Closed
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 bun.lock

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

2 changes: 1 addition & 1 deletion docs/src/shader-defs/dot-grid-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const dotGridDef: ShaderDef = {
type: 'enum',
defaultValue: defaultParams.shape,
description: 'The shape type',
options: ['circle', 'diamond', 'square', 'triangle'],
options: ['circle', 'diamond', 'square', 'triangle', 'stripe', 'cross'],
},
{
name: 'size',
Expand Down
49 changes: 47 additions & 2 deletions packages/shaders-react/src/shaders/dot-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,52 @@ const wallpaperPreset: DotGridPreset = {
},
};

export const dotGridPresets: DotGridPreset[] = [defaultPreset, trianglesPreset, treeLinePreset, wallpaperPreset];
// ── New: Stripe preset ────────────────────────────────────────────────────────
// Thin horizontal bars evenly spaced across the canvas.
const stripesPreset: DotGridPreset = {
name: 'Stripes',
params: {
...defaultPatternSizing,
colorBack: '#1a1a2e',
colorFill: '#e94560',
colorStroke: '#e94560',
size: 3, // half-thickness of each stripe bar
gapX: 40, // gapX has no visual effect for pure stripes but kept for uniformity
gapY: 24, // vertical spacing between stripe centres
strokeWidth: 0,
sizeRange: 0,
opacityRange: 0,
shape: 'stripe',
},
};

// ── New: Cross preset ─────────────────────────────────────────────────────────
// Plus-sign grid — looks like graph-paper crosshairs.
const crossesPreset: DotGridPreset = {
name: 'Crosses',
params: {
...defaultPatternSizing,
colorBack: '#f5f0e8',
colorFill: '#2d2d2d',
colorStroke: '#2d2d2d',
size: 2, // arm half-thickness
gapX: 28,
gapY: 28,
strokeWidth: 0,
sizeRange: 0.3,
opacityRange: 0.2,
shape: 'cross',
},
};

export const dotGridPresets: DotGridPreset[] = [
defaultPreset,
trianglesPreset,
treeLinePreset,
wallpaperPreset,
stripesPreset,
crossesPreset,
];

export const DotGrid: React.FC<DotGridProps> = memo(function DotGridImpl({
// Own props
Expand Down Expand Up @@ -142,4 +187,4 @@ export const DotGrid: React.FC<DotGridProps> = memo(function DotGridImpl({
return (
<ShaderMount {...props} maxPixelCount={maxPixelCount} fragmentShader={dotGridFragmentShader} uniforms={uniforms} />
);
}, colorPropsAreEqual);
}, colorPropsAreEqual);
19 changes: 15 additions & 4 deletions packages/shaders/src/shaders/dot-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
import { declarePI, simplexNoise } from '../shader-utils.js';

/**
* Static grid pattern made of circles, diamonds, squares or triangles.
* Static grid pattern made of circles, diamonds, squares, triangles, stripes or crosses.
*
* Fragment shader uniforms:
* - u_colorBack (vec4): Background color in RGBA
Expand All @@ -14,7 +14,7 @@ import { declarePI, simplexNoise } from '../shader-utils.js';
* - u_strokeWidth (float): Outline stroke width in pixels (0 to 50)
* - u_sizeRange (float): Random variation in shape size, 0 = uniform, higher = random up to base size (0 to 1)
* - u_opacityRange (float): Random variation in shape opacity, 0 = opaque, higher = semi-transparent (0 to 1)
* - u_shape (float): Shape type (0 = circle, 1 = diamond, 2 = square, 3 = triangle)
* - u_shape (float): Shape type (0 = circle, 1 = diamond, 2 = square, 3 = triangle, 4 = stripe, 5 = cross)
*
* Vertex shader outputs (used in fragment shader):
* - v_patternUV (vec2): UV coordinates in pixels (scaled by 0.01 for precision), with scale, rotation and offset applied
Expand Down Expand Up @@ -92,14 +92,23 @@ void main() {
} else if (u_shape < 2.5) {
// Square
dist = polygon(1.03 * p, 4., 1e-3);
} else {
} else if (u_shape < 3.5) {
// Triangle
strokeWidth *= 1.5;
p = p * 2. - 1.;
p *= .9;
p.y = 1. - p.y;
p.y -= .75 * baseSize;
dist = polygon(p, 3., 1e-3);
} else if (u_shape < 4.5) {
// Stripe — horizontal bar: thin rectangle spanning full cell width,
// centred vertically. dist = SDF of a box with half-extents (inf, baseSize).
// We only care about the Y axis to get a horizontal stripe.
dist = abs(p.y);
} else {
// Cross — union of a horizontal and a vertical stripe.
// dist = SDF of a plus sign: min of the two axis-aligned SDFs.
dist = min(abs(p.x), abs(p.y));
}

float edgeWidth = fwidth(dist);
Expand Down Expand Up @@ -159,6 +168,8 @@ export const DotGridShapes = {
diamond: 1,
square: 2,
triangle: 3,
stripe: 4,
cross: 5,
} as const;

export type DotGridShape = keyof typeof DotGridShapes;
export type DotGridShape = keyof typeof DotGridShapes;