Skip to content

Commit

Permalink
add distortion
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwenl committed Dec 31, 2023
1 parent 3185a82 commit e6dbdac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion experiments/whiteParticles/dist/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions experiments/whiteParticles/src/SceneApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class SceneApp extends Scene {
.bindTexture("uAOMap", this._textureAO, 2)
.bindTexture("uLookupMap", this._textureLookup, 3)
.uniform("uColorAO", Config.colorAO.map(toGlsl))
.uniform("uRatio", GL.aspectRatio)
.draw();
// this._dCopy.draw(this._textureNormal);

Expand Down
2 changes: 1 addition & 1 deletion experiments/whiteParticles/src/shaders/blocks.vert
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void main(void) {
float g = mix(0.95, 1.0, aExtra.x);
vec3 color = vec3(g);
float t = fract(aExtra.x + aExtra.y + aExtra.z);
float colMul = mix(.8, 1.2, t);
float colMul = mix(.6, .9, t);
float threshold = mix(0.1, 0.25, t);
t = smoothstep(threshold * .9, threshold, speed);
color *= mix(vec3(1.0), vec3(colMul, 0.1, 0.0), t);
Expand Down
57 changes: 48 additions & 9 deletions experiments/whiteParticles/src/shaders/chroma.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ uniform sampler2D uMap;
uniform sampler2D uNormalMap;
uniform sampler2D uAOMap;
uniform vec3 uColorAO;
uniform float uRatio;

out vec4 oColor;

Expand All @@ -23,30 +24,68 @@ vec3 greyscale(vec3 color) {
return greyscale(color, 1.0);
}


vec2 getStretchedUV(vec2 uv, float scale, float front) {
float d;
float t;
vec2 stretchedUV;
vec2 _uv = uv - 0.5;

if(uRatio < 1.0) {
_uv.x *= uRatio;
} else {
_uv.y /= uRatio;
}
d = length(_uv);
d = abs(d - front);
t = smoothstep(0.1, 0.0, d) * scale * .75;
stretchedUV = 0.5 + (uv - 0.5) * ( 1.0 + t);
return stretchedUV;
}

void main(void) {
vec3 n = texture(uNormalMap, vTextureCoord).rgb * 2.0 - 1.0;
vec2 uv = vTextureCoord;

float d;
float ao = texture(uAOMap, vTextureCoord).r;
vec3 colorAO = mix(uColorAO, vec3(1.0), ao);

vec2 off = n.rb * 0.0025;
off *= 2.0;

vec3 color0 = texture(uMap, uv-off).rgb * colorAO * vec3(1.0, 0.0, 0.0);
vec3 color1 = texture(uMap, uv+off).rgb * colorAO * vec3(0.0, 1.0, 0.0);
vec3 color2 = texture(uMap, uv).rgb * colorAO * vec3(0.0, 0.0, 1.0);
float front = 0.15;
float scale = 0.25;

uv = getStretchedUV(vTextureCoord, scale, front);
vec3 color = texture(uMap, uv).rgb;

front = 0.2;
scale = 0.025;

float t = 0.1;
vec3 color0 = vec3(1.0 - t * 2.0, t, t);
vec3 color1 = vec3(t, 1.0 - t * 2.0, t);
vec3 color2 = vec3(t, t, 1.0 - t * 2.0);

vec2 uv2 = getStretchedUV(uv, scale, front);
vec3 r = texture(uMap, uv2).rgb * color0;
vec3 g = texture(uMap, uv).rgb * color1;
uv2 = getStretchedUV(uv, -scale, front);
vec3 b = texture(uMap, uv2).rgb * color2;
color = r + g + b;

vec3 color = greyscale(color0 + color1 + color2, .6);

color *= mix(colorAO, vec3(1.0), .85);



// dark bottom right
uv = vTextureCoord;
uv.y = 1.0 - uv.y;
float d = length(uv);
d = length(uv);
d = smoothstep(0.25, 1.2, d);
// vec3 colorAdj = mix(vec3(1.0), vec3(1.0, .97, .94) * 0.85, d);
vec3 colorAdj = mix(vec3(1.0), vec3(.5), d);
// color *= colorAdj;
color -= d * 0.4;
color -= d * 0.5;

oColor = vec4(color, 1.0);
}

0 comments on commit e6dbdac

Please sign in to comment.