Skip to content

Commit

Permalink
Add vite-plugin-glsl to support GLSL external shader files and add de…
Browse files Browse the repository at this point in the history
…claration file to help Typescript to resolve shader import
  • Loading branch information
Adam N authored and Adam N committed Jun 30, 2022
1 parent 2ee77f1 commit f429246
Show file tree
Hide file tree
Showing 8 changed files with 1,569 additions and 318 deletions.
1,307 changes: 1,307 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/three": "^0.141.0",
"sass": "^1.52.3",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"vite": "^2.9.12",
"vite-plugin-glsl": "^0.1.5"
}
}
3 changes: 0 additions & 3 deletions src/example/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { createLights } from './create-lights'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { calculateCanvasSize } from '../utils/calculate-canvas-size'
import { animateCharacter, positionCharacter } from './transform-character'


/**
* Creates an example scene with a rotating character.
*/
Expand Down Expand Up @@ -75,4 +73,3 @@ animate()
renderer.setSize(size.width, size.height)
})
}

5 changes: 5 additions & 0 deletions src/shaders/example/fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#version 120

void main() {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
5 changes: 5 additions & 0 deletions src/shaders/example/vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#version 120

void main() {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
}
4 changes: 4 additions & 0 deletions src/shaders/glsl.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.glsl" {
const value: string;
export default value;
}
6 changes: 6 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import glsl from "vite-plugin-glsl";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [glsl.default()] //For some reason, cannot resolve glsl(). Workaround found on vite-plugin-glsl issue (https://github.com/UstymUkhman/vite-plugin-glsl/issues/1#issuecomment-972660771)
});
554 changes: 240 additions & 314 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit f429246

Please sign in to comment.