mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fading out fragment
This commit is contained in:
1 parent
0d1088fefb
commit
32e4bf3fd2
3 files changed
+36
-6
No files matched your search
+12
-6
@@ -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>
|
||||||
);
|
);
|
||||||
|
|||||||
+16
@@ -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);
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
varying vec3 vWorldPosition;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 worldPos = modelMatrix * vec4(position, 1.0);
|
||||||
|
vWorldPosition = worldPos.xyz;
|
||||||
|
|
||||||
|
gl_Position = projectionMatrix * viewMatrix * worldPos;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user