sparklemotion icon indicating copy to clipboard operation
sparklemotion copied to clipboard

๐Ÿ› Patch mod applied to filtered shader content shouldn't flow downstream

Open xian opened this issue 2 years ago โ€ข 0 comments

If a patch's output content type matches the content type of one of its inputs, it's considered a filter, and will automatically be inserted upstream of other patches that use the same content type.

For example, 'Ripple' is a filter, because it takes a U/V coordinate as input, and returns a U/V coordinate:

uniform float time;
uniform float rippleAmount; // @type float

// @return uv-coordinate
// @param uvIn uv-coordinate
vec2 main(vec2 uvIn) {
    vec2 p = -1.0 + 2.0 * uvIn;
    float len = length(p);
    return uvIn + (p/len)*sin(len*12.0-time*4.0)*0.1 * rippleAmount;
}

It's possible to offset the coordinate system of Ripple using the Position and Scale patch mod on the uv input port, which will cause the center of the ripple effect to move. But, since the output U/V includes that offset, every downstream patch will also move along with the ripple's center.

To fix: the output's offset should be reversed, comme รงa:

vec2 rippleOut = undoPositionShift(ripple_main(applyPositionShift(uv));

xian avatar Sep 26 '22 22:09 xian