fading out fragment

This commit is contained in:
tresabhi committed 2026-08-11 10:16:14 -05:00
1 parent 0d1088fefb
commit 32e4bf3fd2
3 files changed
+36 -6

No files matched your search

@@ -1,7 +1,9 @@
import { invalidate } from "@react-three/fiber"; import { invalidate } from "@react-three/fiber";
import { Quicklime, type QuicklimeEvent } from "quicklime"; import { Quicklime, type QuicklimeEvent } from "quicklime";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import { Mesh, MeshStandardMaterial } from "three"; import { Mesh, MeshStandardMaterial, Vector3 } from "three";
import fragmentShader from "./shaders/fragment.glsl?raw";
import vertexShader from "./shaders/vertex.glsl?raw";
const SIZE = 2 ** 5; const SIZE = 2 ** 5;
@@ -33,11 +35,15 @@ export function SceneProps() {
ref={mesh} ref={mesh}
> >
<planeGeometry args={[SIZE, SIZE]} /> <planeGeometry args={[SIZE, SIZE]} />
<meshStandardMaterial <shaderMaterial
ref={material} fragmentShader={fragmentShader}
color="black" vertexShader={vertexShader}
roughness={1} transparent
metalness={0} lights
uniforms={{
size: { value: SIZE / 2 },
color: { value: new Vector3(1, 1, 1).multiplyScalar(2 ** -3) },
}}
/> />
</mesh> </mesh>
); );
@@ -0,0 +1,16 @@
varying vec3 vWorldPosition;
uniform float size;
uniform vec3 color;
void main() {
vec3 scaled = vWorldPosition / size;
float radius = length(scaled.xz);
if(radius >= 1.0) {
discard;
}
float a = 1.0 - radius;
gl_FragColor = vec4(color, a);
}
@@ -0,0 +1,8 @@
varying vec3 vWorldPosition;
void main() {
vec4 worldPos = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPos.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPos;
}