[question] How can i scale texture without offsset?

Share your Construct 2 effect files

Post » Sat Oct 25, 2014 8:46 pm

I've been trying to figure it out and nothing comes to my mind...

I'm stuck on:
vec2 tex = vTex * (1.0-size); - size is a percentage float
vec4 front = texture2D(samplerFront, tex);
etc...

and so far this works great however, only when "<extend-box-horizontal>" and "<extend-box-vertical>" are both set to 0. Setting it to something greater then 0 introduces this strange offset I can't compensate or get rid of.

I'm not a shader programmer and it's quite hard to learn that kind of stuff :/
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Tue Oct 28, 2014 9:31 pm

Describe the offset. If you set extend-box-horizontal to say 10 is it offset right 10 pixels? Maybe the vTex positions have an origin at the top left? So The points clockwise are (0,0), (1,0),(1,1),(0,1) perhaps?

At any rate maybe you could offset it back using the built in pixelWidth var? So with a extend-box-horizontal of 10 and a extend-box-vertical of 5 maybe this would work?
Code: Select all
uniform mediump float pixelWidth;
uniform mediump float pixelHeight;

vec2 tex = vTex * (1.0-size);
tex.x -= pixelWidth*10;
tex.y -= pixelHeight*5;
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 28, 2014 9:56 pm

@R0J0hound Not sure how to describe it, but I can show it.

Openup a capx file, and change "Size offset" for the bottom sprite on the layout.
What I'm trying to do is more less drop shadow effects, and Size offset should scale the effect while preserving sprites original position. It scales it correctly but also adds an offset to the effect and moving it around moves effect on layout coordinate (0,1)? not sure if this term is correct.
You do not have the required permissions to view the files attached to this post.
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Wed Oct 29, 2014 7:15 pm

It appears that when extend-box-horizontal or extend-box-vertical are both 0 the vTex coordinates are on the sprite, where the origin is the bottom-left corner of the sprite. But when either is non-zero then the coordinates are on the screen, where the origin is the bottom-left corner of the screen.

The issue is if we wanted to scale from the center of the sprite we'd need to find the vTex coordinate of the center of the sprite, and I haven't seen any example of this in the plugins. Looking at some of the radial effects you can use the center of of either the object or screen, depending on what the vTex's are on, but it's not helpful if we want the center of the object when the vTex is on the screen.

Trying to see what we have to work with, here are some of the variables that C2 provides for shaders (from glwrap.js):
pixelWidth;
pixelHeight;
destStartX;
destStartY;
destEndX;
destEndY;
layerScale;
layerAngle;
viewOriginLeft
viewOriginTop

Poking around glwarp.js there seem to a couple more, like samplerFront, vTex...
Also built in to glsl you have these:
https://www.opengl.org/wiki/Built-in_Va ... der_inputs

The bottom-left is always (0,0) and the top-right is always (1,1).
You can calculate the width in pixels with 1.0/pixelWidth, the height can be calculated in a similar way.

Interesting, but nothing really helpful. The only solution I can think of would be to add two more parameters for the center x and y and set them every tick. Then the math would be something like (x-center)*scale+center.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Wed Oct 29, 2014 8:21 pm

Yeah, I though about using parameters to control the "shadow" position. But my idea was to make this effects without any need of using events at all :/
I'll keep looking and experimenting.

Thanks you so much for help and all the time you spend looking into this!
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825


Return to Effects

Who is online

Users browsing this forum: No registered users and 1 guest