Skip to content

Commit 334006c

Browse files
committed
add glsl test
1 parent ad8c4a1 commit 334006c

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

package-lock.json

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"devDependencies": {
1313
"prettier": "^3.5.3",
14-
"vite": "^6.3.5"
14+
"vite": "^6.3.5",
15+
"vite-plugin-glsl": "^1.4.2"
1516
},
1617
"dependencies": {
1718
"@mediapipe/tasks-vision": "^0.10.22-rc.20250304"

test/fragment.glsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
precision mediump float;
2+
3+
uniform float uTime;
4+
uniform sampler2D uTexture;
5+
6+
varying vec2 vUv;
7+
8+
void main() {
9+
vec4 texColor = texture2D(uTexture, vUv);
10+
gl_FragColor = vec4(texColor.rgb, 1.0);
11+
}

test/test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import { Mesh } from "@/objects/Mesh"
1919
import { Color } from "@/math/Color"
2020
import { RawShaderMaterial } from "@/materials/RawShaderMaterial"
2121

22+
import vertexShader from "./vertex.glsl"
23+
import fragmentShader from "./fragment.glsl"
24+
2225
class CubeRotateSample {
2326
constructor() {
2427
this.scene = new Scene()
@@ -78,8 +81,8 @@ class CubeRotateSample {
7881
// })
7982
const geometry = new BoxGeometry(1, 1, 1)
8083
const material = new RawShaderMaterial({
81-
vertexShader: this.vertexShader(),
82-
fragmentShader: this.fragmentShader(),
84+
vertexShader: vertexShader,
85+
fragmentShader: fragmentShader,
8386
uniforms: this.uniforms,
8487
side: DoubleSide,
8588
})

test/vertex.glsl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
precision mediump float;
2+
3+
uniform mat4 modelViewMatrix;
4+
uniform mat4 projectionMatrix;
5+
6+
attribute vec3 position;
7+
attribute vec2 uv;
8+
9+
varying vec2 vUv;
10+
11+
void main() {
12+
vUv = uv;
13+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
14+
}

vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glsl from 'vite-plugin-glsl';
12
import { resolve, dirname } from "path"
23
import { fileURLToPath } from "url"
34
import path from "path"
@@ -40,4 +41,5 @@ export default defineConfig({
4041
exclude: [],
4142
},
4243
assetsInclude: ["**/*.wasm", "**/*.ktx2", "**/*.glb", "**/*.gltf", "**/*.png"],
44+
plugins: [glsl()],
4345
})

0 commit comments

Comments
 (0)