All Questions

Community

Daniel Queiroz Porto

Still kind of hard to wrap my head around the displacement_uv line

So I do get that this is the line that is reponsible for the distortion effect, and tried to play around with it to get a hang of it, and I think for pratical purposes this was enough, and I'm getting a "feeling" of what I want now.

But I still can't wrap my head around it:

vec2 displacement_uv = UV + mask * displacement_amount;

So I tried to remove the displacement_amount from this line (or set it to 1) and it seems like it tries to Fit the whole texture into the donut mask?

We are actually adding a float to a Vector2 so in the background is it doing something like vec2(UV.x + mask * displacement, UV.y + mask * displacement)?

I think writing it down helped me understand it a bit more, but are this assumption correct? Or am I missing something in how this works?

  • Razoric replied
    Solution

    Yes, GLSL is converting the float into a vec2 automatically. Your assumption is almost correct: order of operations occurs, so mask * displacement is calculated first, then the equivalent of vec2(UV) + vec2(mask * displacement) happens (which, yes, is a straight addition of the X and Y components.)

  • Daniel Queiroz Porto replied

    Thanks!