Skip to content

Commit a411588

Browse files
committed
fix: revert incompatible webgl1 code
1 parent 5632800 commit a411588

File tree

8 files changed

+12
-646
lines changed

8 files changed

+12
-646
lines changed

public/r/PixelBlast-JS-CSS.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/r/PixelBlast-JS-TW.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/r/PixelBlast-TS-CSS.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/r/PixelBlast-TS-TW.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/content/Backgrounds/PixelBlast/PixelBlast.jsx

Lines changed: 2 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -291,164 +291,6 @@ void main(){
291291
}
292292
`;
293293

294-
const FRAGMENT_SRC_GLSL1 = `
295-
#extension GL_OES_standard_derivatives : enable
296-
precision highp float;
297-
298-
uniform vec3 uColor;
299-
uniform vec2 uResolution;
300-
uniform float uTime;
301-
uniform float uPixelSize;
302-
uniform float uScale;
303-
uniform float uDensity;
304-
uniform float uPixelJitter;
305-
uniform int uEnableRipples;
306-
uniform float uRippleSpeed;
307-
uniform float uRippleThickness;
308-
uniform float uRippleIntensity;
309-
uniform float uEdgeFade;
310-
311-
uniform int uShapeType;
312-
const int SHAPE_SQUARE = 0;
313-
const int SHAPE_CIRCLE = 1;
314-
const int SHAPE_TRIANGLE = 2;
315-
const int SHAPE_DIAMOND = 3;
316-
317-
const int MAX_CLICKS = 10;
318-
319-
uniform vec2 uClickPos [MAX_CLICKS];
320-
uniform float uClickTimes[MAX_CLICKS];
321-
322-
float Bayer2(vec2 a) {
323-
a = floor(a);
324-
return fract(a.x / 2. + a.y * a.y * .75);
325-
}
326-
#define Bayer4(a) (Bayer2(.5*(a))*0.25 + Bayer2(a))
327-
#define Bayer8(a) (Bayer4(.5*(a))*0.25 + Bayer2(a))
328-
329-
#define FBM_OCTAVES 5
330-
#define FBM_LACUNARITY 1.25
331-
#define FBM_GAIN 1.0
332-
333-
float hash11(float n){ return fract(sin(n)*43758.5453); }
334-
335-
float vnoise(vec3 p){
336-
vec3 ip = floor(p);
337-
vec3 fp = fract(p);
338-
float n000 = hash11(dot(ip + vec3(0.0,0.0,0.0), vec3(1.0,57.0,113.0)));
339-
float n100 = hash11(dot(ip + vec3(1.0,0.0,0.0), vec3(1.0,57.0,113.0)));
340-
float n010 = hash11(dot(ip + vec3(0.0,1.0,0.0), vec3(1.0,57.0,113.0)));
341-
float n110 = hash11(dot(ip + vec3(1.0,1.0,0.0), vec3(1.0,57.0,113.0)));
342-
float n001 = hash11(dot(ip + vec3(0.0,0.0,1.0), vec3(1.0,57.0,113.0)));
343-
float n101 = hash11(dot(ip + vec3(1.0,0.0,1.0), vec3(1.0,57.0,113.0)));
344-
float n011 = hash11(dot(ip + vec3(0.0,1.0,1.0), vec3(1.0,57.0,113.0)));
345-
float n111 = hash11(dot(ip + vec3(1.0,1.0,1.0), vec3(1.0,57.0,113.0)));
346-
vec3 w = fp*fp*fp*(fp*(fp*6.0-15.0)+10.0);
347-
float x00 = mix(n000, n100, w.x);
348-
float x10 = mix(n010, n110, w.x);
349-
float x01 = mix(n001, n101, w.x);
350-
float x11 = mix(n011, n111, w.x);
351-
float y0 = mix(x00, x10, w.y);
352-
float y1 = mix(x01, x11, w.y);
353-
return mix(y0, y1, w.z) * 2.0 - 1.0;
354-
}
355-
356-
float fbm2(vec2 uv, float t){
357-
vec3 p = vec3(uv * uScale, t);
358-
float amp = 1.0;
359-
float freq = 1.0;
360-
float sum = 1.0;
361-
for (int i = 0; i < FBM_OCTAVES; ++i){
362-
sum += amp * vnoise(p * freq);
363-
freq *= FBM_LACUNARITY;
364-
amp *= FBM_GAIN;
365-
}
366-
return sum * 0.5 + 0.5;
367-
}
368-
369-
float maskCircle(vec2 p, float cov){
370-
float r = sqrt(cov) * .25;
371-
float d = length(p - 0.5) - r;
372-
float aa = 0.5 * fwidth(d);
373-
return cov * (1.0 - smoothstep(-aa, aa, d * 2.0));
374-
}
375-
376-
float maskTriangle(vec2 p, vec2 id, float cov){
377-
bool flip = mod(id.x + id.y, 2.0) > 0.5;
378-
if (flip) p.x = 1.0 - p.x;
379-
float r = sqrt(cov);
380-
float d = p.y - r*(1.0 - p.x);
381-
float aa = fwidth(d);
382-
return cov * clamp(0.5 - d/aa, 0.0, 1.0);
383-
}
384-
385-
float maskDiamond(vec2 p, float cov){
386-
float r = sqrt(cov) * 0.564;
387-
return step(abs(p.x - 0.49) + abs(p.y - 0.49), r);
388-
}
389-
390-
void main(){
391-
float pixelSize = uPixelSize;
392-
vec2 fragCoord = gl_FragCoord.xy - uResolution * .5;
393-
float aspectRatio = uResolution.x / uResolution.y;
394-
395-
vec2 pixelId = floor(fragCoord / pixelSize);
396-
vec2 pixelUV = fract(fragCoord / pixelSize);
397-
398-
float cellPixelSize = 8.0 * pixelSize;
399-
vec2 cellId = floor(fragCoord / cellPixelSize);
400-
vec2 cellCoord = cellId * cellPixelSize;
401-
vec2 uv = cellCoord / uResolution * vec2(aspectRatio, 1.0);
402-
403-
float base = fbm2(uv, uTime * 0.05);
404-
base = base * 0.5 - 0.65;
405-
406-
float feed = base + (uDensity - 0.5) * 0.3;
407-
408-
float speed = uRippleSpeed;
409-
float thickness = uRippleThickness;
410-
const float dampT = 1.0;
411-
const float dampR = 10.0;
412-
413-
if (uEnableRipples == 1) {
414-
for (int i = 0; i < MAX_CLICKS; ++i){
415-
vec2 pos = uClickPos[i];
416-
if (pos.x < 0.0) continue;
417-
float cellPixelSize = 8.0 * pixelSize;
418-
vec2 cuv = (((pos - uResolution * .5 - cellPixelSize * .5) / (uResolution))) * vec2(aspectRatio, 1.0);
419-
float t = max(uTime - uClickTimes[i], 0.0);
420-
float r = distance(uv, cuv);
421-
float waveR = speed * t;
422-
float ring = exp(-pow((r - waveR) / thickness, 2.0));
423-
float atten = exp(-dampT * t) * exp(-dampR * r);
424-
feed = max(feed, ring * atten * uRippleIntensity);
425-
}
426-
}
427-
428-
float bayer = Bayer8(fragCoord / uPixelSize) - 0.5;
429-
float bw = step(0.5, feed + bayer);
430-
431-
float h = fract(sin(dot(floor(fragCoord / uPixelSize), vec2(127.1, 311.7))) * 43758.5453);
432-
float jitterScale = 1.0 + (h - 0.5) * uPixelJitter;
433-
float coverage = bw * jitterScale;
434-
float M;
435-
if (uShapeType == SHAPE_CIRCLE) M = maskCircle (pixelUV, coverage);
436-
else if (uShapeType == SHAPE_TRIANGLE) M = maskTriangle(pixelUV, pixelId, coverage);
437-
else if (uShapeType == SHAPE_DIAMOND) M = maskDiamond(pixelUV, coverage);
438-
else M = coverage;
439-
440-
if (uEdgeFade > 0.0) {
441-
vec2 norm = gl_FragCoord.xy / uResolution;
442-
float edge = min(min(norm.x, norm.y), min(1.0 - norm.x, 1.0 - norm.y));
443-
float fade = smoothstep(0.0, uEdgeFade, edge);
444-
M *= fade;
445-
}
446-
447-
vec3 color = uColor;
448-
gl_FragColor = vec4(color, M);
449-
}
450-
`;
451-
452294
const MAX_CLICKS = 10;
453295

454296
const PixelBlast = ({
@@ -542,15 +384,14 @@ const PixelBlast = ({
542384
};
543385
const scene = new THREE.Scene();
544386
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
545-
const isWebGL2 = renderer.capabilities.isWebGL2;
546387
const material = new THREE.ShaderMaterial({
547388
vertexShader: VERTEX_SRC,
548-
fragmentShader: isWebGL2 ? FRAGMENT_SRC : FRAGMENT_SRC_GLSL1,
389+
fragmentShader: FRAGMENT_SRC,
549390
uniforms,
550391
transparent: true,
551392
depthTest: false,
552393
depthWrite: false,
553-
glslVersion: isWebGL2 ? THREE.GLSL3 : undefined
394+
glslVersion: THREE.GLSL3
554395
});
555396
const quadGeom = new THREE.PlaneGeometry(2, 2);
556397
const quad = new THREE.Mesh(quadGeom, material);

src/tailwind/Backgrounds/PixelBlast/PixelBlast.jsx

Lines changed: 2 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -290,164 +290,6 @@ void main(){
290290
}
291291
`;
292292

293-
const FRAGMENT_SRC_GLSL1 = `
294-
#extension GL_OES_standard_derivatives : enable
295-
precision highp float;
296-
297-
uniform vec3 uColor;
298-
uniform vec2 uResolution;
299-
uniform float uTime;
300-
uniform float uPixelSize;
301-
uniform float uScale;
302-
uniform float uDensity;
303-
uniform float uPixelJitter;
304-
uniform int uEnableRipples;
305-
uniform float uRippleSpeed;
306-
uniform float uRippleThickness;
307-
uniform float uRippleIntensity;
308-
uniform float uEdgeFade;
309-
310-
uniform int uShapeType;
311-
const int SHAPE_SQUARE = 0;
312-
const int SHAPE_CIRCLE = 1;
313-
const int SHAPE_TRIANGLE = 2;
314-
const int SHAPE_DIAMOND = 3;
315-
316-
const int MAX_CLICKS = 10;
317-
318-
uniform vec2 uClickPos [MAX_CLICKS];
319-
uniform float uClickTimes[MAX_CLICKS];
320-
321-
float Bayer2(vec2 a) {
322-
a = floor(a);
323-
return fract(a.x / 2. + a.y * a.y * .75);
324-
}
325-
#define Bayer4(a) (Bayer2(.5*(a))*0.25 + Bayer2(a))
326-
#define Bayer8(a) (Bayer4(.5*(a))*0.25 + Bayer2(a))
327-
328-
#define FBM_OCTAVES 5
329-
#define FBM_LACUNARITY 1.25
330-
#define FBM_GAIN 1.0
331-
332-
float hash11(float n){ return fract(sin(n)*43758.5453); }
333-
334-
float vnoise(vec3 p){
335-
vec3 ip = floor(p);
336-
vec3 fp = fract(p);
337-
float n000 = hash11(dot(ip + vec3(0.0,0.0,0.0), vec3(1.0,57.0,113.0)));
338-
float n100 = hash11(dot(ip + vec3(1.0,0.0,0.0), vec3(1.0,57.0,113.0)));
339-
float n010 = hash11(dot(ip + vec3(0.0,1.0,0.0), vec3(1.0,57.0,113.0)));
340-
float n110 = hash11(dot(ip + vec3(1.0,1.0,0.0), vec3(1.0,57.0,113.0)));
341-
float n001 = hash11(dot(ip + vec3(0.0,0.0,1.0), vec3(1.0,57.0,113.0)));
342-
float n101 = hash11(dot(ip + vec3(1.0,0.0,1.0), vec3(1.0,57.0,113.0)));
343-
float n011 = hash11(dot(ip + vec3(0.0,1.0,1.0), vec3(1.0,57.0,113.0)));
344-
float n111 = hash11(dot(ip + vec3(1.0,1.0,1.0), vec3(1.0,57.0,113.0)));
345-
vec3 w = fp*fp*fp*(fp*(fp*6.0-15.0)+10.0);
346-
float x00 = mix(n000, n100, w.x);
347-
float x10 = mix(n010, n110, w.x);
348-
float x01 = mix(n001, n101, w.x);
349-
float x11 = mix(n011, n111, w.x);
350-
float y0 = mix(x00, x10, w.y);
351-
float y1 = mix(x01, x11, w.y);
352-
return mix(y0, y1, w.z) * 2.0 - 1.0;
353-
}
354-
355-
float fbm2(vec2 uv, float t){
356-
vec3 p = vec3(uv * uScale, t);
357-
float amp = 1.0;
358-
float freq = 1.0;
359-
float sum = 1.0;
360-
for (int i = 0; i < FBM_OCTAVES; ++i){
361-
sum += amp * vnoise(p * freq);
362-
freq *= FBM_LACUNARITY;
363-
amp *= FBM_GAIN;
364-
}
365-
return sum * 0.5 + 0.5;
366-
}
367-
368-
float maskCircle(vec2 p, float cov){
369-
float r = sqrt(cov) * .25;
370-
float d = length(p - 0.5) - r;
371-
float aa = 0.5 * fwidth(d);
372-
return cov * (1.0 - smoothstep(-aa, aa, d * 2.0));
373-
}
374-
375-
float maskTriangle(vec2 p, vec2 id, float cov){
376-
bool flip = mod(id.x + id.y, 2.0) > 0.5;
377-
if (flip) p.x = 1.0 - p.x;
378-
float r = sqrt(cov);
379-
float d = p.y - r*(1.0 - p.x);
380-
float aa = fwidth(d);
381-
return cov * clamp(0.5 - d/aa, 0.0, 1.0);
382-
}
383-
384-
float maskDiamond(vec2 p, float cov){
385-
float r = sqrt(cov) * 0.564;
386-
return step(abs(p.x - 0.49) + abs(p.y - 0.49), r);
387-
}
388-
389-
void main(){
390-
float pixelSize = uPixelSize;
391-
vec2 fragCoord = gl_FragCoord.xy - uResolution * .5;
392-
float aspectRatio = uResolution.x / uResolution.y;
393-
394-
vec2 pixelId = floor(fragCoord / pixelSize);
395-
vec2 pixelUV = fract(fragCoord / pixelSize);
396-
397-
float cellPixelSize = 8.0 * pixelSize;
398-
vec2 cellId = floor(fragCoord / cellPixelSize);
399-
vec2 cellCoord = cellId * cellPixelSize;
400-
vec2 uv = cellCoord / uResolution * vec2(aspectRatio, 1.0);
401-
402-
float base = fbm2(uv, uTime * 0.05);
403-
base = base * 0.5 - 0.65;
404-
405-
float feed = base + (uDensity - 0.5) * 0.3;
406-
407-
float speed = uRippleSpeed;
408-
float thickness = uRippleThickness;
409-
const float dampT = 1.0;
410-
const float dampR = 10.0;
411-
412-
if (uEnableRipples == 1) {
413-
for (int i = 0; i < MAX_CLICKS; ++i){
414-
vec2 pos = uClickPos[i];
415-
if (pos.x < 0.0) continue;
416-
float cellPixelSize = 8.0 * pixelSize;
417-
vec2 cuv = (((pos - uResolution * .5 - cellPixelSize * .5) / (uResolution))) * vec2(aspectRatio, 1.0);
418-
float t = max(uTime - uClickTimes[i], 0.0);
419-
float r = distance(uv, cuv);
420-
float waveR = speed * t;
421-
float ring = exp(-pow((r - waveR) / thickness, 2.0));
422-
float atten = exp(-dampT * t) * exp(-dampR * r);
423-
feed = max(feed, ring * atten * uRippleIntensity);
424-
}
425-
}
426-
427-
float bayer = Bayer8(fragCoord / uPixelSize) - 0.5;
428-
float bw = step(0.5, feed + bayer);
429-
430-
float h = fract(sin(dot(floor(fragCoord / uPixelSize), vec2(127.1, 311.7))) * 43758.5453);
431-
float jitterScale = 1.0 + (h - 0.5) * uPixelJitter;
432-
float coverage = bw * jitterScale;
433-
float M;
434-
if (uShapeType == SHAPE_CIRCLE) M = maskCircle (pixelUV, coverage);
435-
else if (uShapeType == SHAPE_TRIANGLE) M = maskTriangle(pixelUV, pixelId, coverage);
436-
else if (uShapeType == SHAPE_DIAMOND) M = maskDiamond(pixelUV, coverage);
437-
else M = coverage;
438-
439-
if (uEdgeFade > 0.0) {
440-
vec2 norm = gl_FragCoord.xy / uResolution;
441-
float edge = min(min(norm.x, norm.y), min(1.0 - norm.x, 1.0 - norm.y));
442-
float fade = smoothstep(0.0, uEdgeFade, edge);
443-
M *= fade;
444-
}
445-
446-
vec3 color = uColor;
447-
gl_FragColor = vec4(color, M);
448-
}
449-
`;
450-
451293
const MAX_CLICKS = 10;
452294

453295
const PixelBlast = ({
@@ -541,15 +383,14 @@ const PixelBlast = ({
541383
};
542384
const scene = new THREE.Scene();
543385
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
544-
const isWebGL2 = renderer.capabilities.isWebGL2;
545386
const material = new THREE.ShaderMaterial({
546387
vertexShader: VERTEX_SRC,
547-
fragmentShader: isWebGL2 ? FRAGMENT_SRC : FRAGMENT_SRC_GLSL1,
388+
fragmentShader: FRAGMENT_SRC,
548389
uniforms,
549390
transparent: true,
550391
depthTest: false,
551392
depthWrite: false,
552-
glslVersion: isWebGL2 ? THREE.GLSL3 : undefined
393+
glslVersion: THREE.GLSL3
553394
});
554395
const quadGeom = new THREE.PlaneGeometry(2, 2);
555396
const quad = new THREE.Mesh(quadGeom, material);

0 commit comments

Comments
 (0)