Skip to content

Commit

Permalink
glsl functions
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Oct 8, 2024
1 parent c6594d7 commit fc4c8d5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
15 changes: 14 additions & 1 deletion libs/webgl/utils/blend.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
export const BLEND = {
NORMAL: `
NORMAL: /* glsl */ `
vec3 blendNormal(vec3 base, vec3 blend) {
return blend;
}
vec3 blendNormal(vec3 base, vec3 blend, float opacity) {
return (blendNormal(base, blend) * opacity + base * (1.0 - opacity));
}`,
COLOR_DODGE: /* glsl */ `
float blendColorDodge(float base, float blend) {
return (blend==1.0)?blend:min(base/(1.0-blend),1.0);
}
vec3 blendColorDodge(vec3 base, vec3 blend) {
return vec3(blendColorDodge(base.r,blend.r),blendColorDodge(base.g,blend.g),blendColorDodge(base.b,blend.b));
}
vec3 blendColorDodge(vec3 base, vec3 blend, float opacity) {
return (blendColorDodge(base, blend) * opacity + base * (1.0 - opacity));
}
`,
}
12 changes: 9 additions & 3 deletions libs/webgl/utils/functions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
export const FUNCTIONS = {
PI: `#define PI 3.14159265359`,
MAP_RANGE: `
PI: /* glsl */ `#define PI 3.14159265359`,
MAP_RANGE: /* glsl */ `
float mapRange(float min1, float max1,float value, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}`,
GREYSCALE: `
GREYSCALE: /* glsl */ `
vec3 greyscale(vec3 color) {
float average = (color.r + color.g + color.b) / 3.;
return vec3(average);
}`,
RANDOM: /* glsl */ `
float random(vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}`,
}
3 changes: 0 additions & 3 deletions libs/webgl/utils/glsl.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@theatre/studio": "^0.7.2",
"clsx": "^2.1.1",
"gsap": "^3.12.5",
"lenis": "1.1.13",
"lenis": "1.1.14-dev.0",
"next": "14.2.13",
"postprocessing": "^6.36.2",
"react": "18.3.1",
Expand Down
15 changes: 7 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc4c8d5

Please sign in to comment.