#how can I make a shader not be affected by transformations?
1 messages · Page 1 of 1 (latest)
Shaders don't have access to transform information, so I think the typical pattern would be to add a vec2 scale uniform to the shader, which you then set via the inspector or script. Within the fragment portion of the shader, you can do something like vec2 uv = (UV - center) * scale + center to adjust your UV's prior to sampling the texture.
I have COLOR.a = distance(UV, (mousePosition - offset) / scale) / radius right now, and I'm not sure how to apply this.
You would plug the scaled uv variable into the UV spot that you have there.
Your center might need to be the mouse position, since I'm assuming you're scaling around that point.
yeah
so my scale variable is actually the size in pixels, (since I'm using panels), would that change anything?
Yes, you would probably need a separate scale variable for the transform modification. It should be based on the ratio of your vertical and horizontal sizes.
So you could have something like vec2(0.5, 1.0) potentially.
Whatever gets you back to 1 to 1 or square scaling.
how would I make the new variable?
Add uniform vec2 transform_scale = vec2(1.0, 1.0);, or something similarly named, to the shader.
This might get you close to what you want:
shader_type canvas_item;
uniform vec2 mouse_position = vec2(0.5);
uniform float radius = 0.25;
uniform vec2 transform_scale = vec2(1.77, 1.0);
uniform float offset = 0.1;
void fragment() {
vec2 uv = (UV - mouse_position) * transform_scale;
COLOR.a = (length(uv) - offset) / max(radius - offset, 1e-8);
}
ah ok I see