[question] How can i scale texture without offsset?

0 favourites
  • 5 posts
From the Asset Store
High quality sound effect pack, in the following categories: Dark, Mystical, Peaceful
  • 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 :/

  • 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?

    uniform mediump float pixelWidth;
    uniform mediump float pixelHeight;
    
    vec2 tex = vTex * (1.0-size);
    tex.x -= pixelWidth*10;
    tex.y -= pixelHeight*5; [/code:39h6zqw8]
  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)