Skip to content

Commit

Permalink
✨ Add support for LYGIA Shader Library
Browse files Browse the repository at this point in the history
  • Loading branch information
mayacoda committed Mar 25, 2023
1 parent d314f4d commit c27b3a0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/shaders/lygia"]
path = src/shaders/lygia
url = https://github.com/patriciogonzalezvivo/lygia.git
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This scaffolding lets you easily get started with using Three.js and TypeScript.

![example scene](./assets/docs/example.jpg)
![example scene](./assets/docs/example.png)

## Features

Expand All @@ -12,6 +12,8 @@ This scaffolding lets you easily get started with using Three.js and TypeScript.
- Debugging GUI and Stats
- Social media and description overlay
- Simple loading animation
- Including shader chunks
- [LYGIA Shader Library](https://lygia.xyz/)

## Prerequisites

Expand Down Expand Up @@ -115,6 +117,22 @@ This will also clear the content of this README.md file to just the basic comman

Resources loaded through THREE.js loaders need to go in the `/public` directory to avoid being compiled by Vite. This includes textures and models.

More information about Vite's asset handling can be found [here](https://vitejs.dev/guide/assets.html).

### Including Shader Chunks

Shaders are loaded using the [vite-plugin-glsl](https://github.com/UstymUkhman/vite-plugin-glsl) Vite plugin and can be located anywhere within the `/src` directory.

More information about Vite's asset handling can be found [here](https://vitejs.dev/guide/assets.html).
The starter also includes the LYGIA Shader Library. To use it, import the shader chunks you need in your shader file.

```glsl
// in src/demo/shader.frag
#include "../shaders/lygia/color/palette/water.glsl"
varying vec2 vUv;
void main() {
gl_FragColor = vec4(water(vUv.y), 1.0);
}
```
Binary file removed assets/docs/example.jpg
Binary file not shown.
Binary file added assets/docs/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "tsc && vite build",
"preview": "vite preview",
"cleanup": "node ./scripts/cleanup.js",
"prepare": "husky install"
"prepare": "husky install",
"preinstall": "git submodule update --init --recursive"
},
"type": "module",
"dependencies": {
Expand Down
6 changes: 5 additions & 1 deletion src/demo/shader.frag
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "../shaders/lygia/color/palette/water.glsl"

varying vec2 vUv;

void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragColor = vec4(water(vUv.y), 1.0);
}
3 changes: 3 additions & 0 deletions src/demo/shader.vert
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
varying vec2 vUv;

void main() {
vUv = uv;
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
}
1 change: 1 addition & 0 deletions src/shaders/lygia
Submodule lygia added at 4dc380

0 comments on commit c27b3a0

Please sign in to comment.