-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
349ca91
commit 6c43d8c
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma glslify: random = require(../../../glsl-modules/random) | ||
|
||
uniform uint u_cell_count; | ||
uniform float u_luminosity; | ||
|
||
varying vec2 v_uv; | ||
|
||
const float infinity = 1.0 / 0.0; | ||
|
||
void main() { | ||
vec2 size = gl_FragCoord.xy / v_uv; | ||
float ratio = size.x / size.y; | ||
vec2 uv = v_uv * vec2(ratio, 1.0); | ||
|
||
float min_dist = infinity; | ||
for (uint i = 0u; i<u_cell_count; i++) { | ||
vec2 v_cell = vec2(random(vec2(float(i), 0.0)), random(vec2(float(i), 1.0)))*ratio; | ||
min_dist = min(min_dist, distance(v_cell, uv)); | ||
} | ||
|
||
gl_FragColor = vec4(vec3(u_luminosity*min_dist), 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client"; | ||
|
||
import { NumberInput } from "@mantine/core"; | ||
import fragmentShader from "./fragment.glsl"; | ||
import { FragmentLogic, FragmentView } from "@/components/shaders/FragmentView"; | ||
import styles from "../../../styles/shaderControl.module.css"; | ||
import { useUniform } from "@/components/shaders/uniforms"; | ||
|
||
const UNIFORMS = { | ||
u_cell_count: { | ||
value: 20, | ||
}, | ||
u_luminosity: { | ||
value: 2.0, | ||
}, | ||
}; | ||
|
||
function VoronoidNoiseControl({controlUiTunnel}: FragmentLogic) { | ||
|
||
const [cellCount, setCellCount] = useUniform("u_cell_count", UNIFORMS.u_cell_count.value); | ||
const [luminosity, setLuminosity] = useUniform("u_luminosity", UNIFORMS.u_luminosity.value); | ||
|
||
const ControlUiTunnel = controlUiTunnel; | ||
|
||
return ( | ||
<ControlUiTunnel> | ||
<div className={styles.shaderControlWrapper}> | ||
<NumberInput className={styles.shaderControl} label="Number of cells" onChange={setCellCount} value={cellCount} min={1} max={500} allowDecimal={false} /> | ||
<NumberInput className={styles.shaderControl} label="Luminosity" onChange={setLuminosity} value={luminosity} min={0.0} max={10.0} step={0.1} decimalScale={2} /> | ||
</div> | ||
</ControlUiTunnel> | ||
); | ||
} | ||
|
||
|
||
export default function Page() { | ||
return ( | ||
<FragmentView | ||
title="Voronoid Noise" | ||
fragmentShader={fragmentShader} | ||
uniforms={UNIFORMS} | ||
withUi={true} | ||
control={VoronoidNoiseControl} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters