0

I have a curtain.js component. I have a mousemove event that determines planeDeformation.

My issue is that I want the coordinates in my shader to track the cursor, but currently the coordinates only displace as per the shader. Thinking about it with my JS head I want to pass an argument to this shader depending on where the cursor is located. It would achieve this:

vec4 red = texture2D(uRenderTexture, vec2(textureCoords.x + uDisplacement * 0.005, textureCoords.y - uDisplacement * 0.005));

or this:

vec4 red = texture2D(uRenderTexture, vec2(textureCoords.x + uDisplacement * 0.005, textureCoords.y + uDisplacement * 0.005));

So simply subtracting uDisplacement * 0.005 rather than adding

Full shader code is here:

precision mediump float;
  
  varying vec3 vVertexPosition;
  varying vec2 vTextureCoord;
  
  uniform sampler2D uRenderTexture;
  uniform float uDisplacement;
  
  void main(void) {
    vec2 textureCoords = vTextureCoord;
    vec4 originalColor = texture2D(uRenderTexture, vTextureCoord);
    vec4 outputColor = originalColor;
  
  // Chromatic abberation along y axis
    vec4 red = texture2D(uRenderTexture, vec2(textureCoords.x + uDisplacement * 0.005, textureCoords.y + uDisplacement * 0.005));
    vec4 green = texture2D(uRenderTexture, vec2(textureCoords.x + uDisplacement * 0.01, textureCoords.y + uDisplacement * 0.01));
    vec4 blue = texture2D(uRenderTexture, vec2(textureCoords.x + uDisplacement * 0.015, textureCoords.y + uDisplacement * 0.015));
    
    outputColor = vec4(red.r,  green.g,  blue.b, originalColor.a);
    
    gl_FragColor = outputColor;
  }

I've tried making another instance and another onRender method.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Jeremiah
  • 1
  • 2
  • You could try to create another `Vec2` uniform called `uDirection` and assign -1 or 1 values based on your mouse coords, and multiply those with `uDisplacement` in your fragment shader. – Martin Laxenaire Feb 21 '23 at 13:34

0 Answers0