[DISCUSSION] Can I use local coordinates in a frag shader?

Share your Construct 2 effect files

Post » Mon Jan 26, 2015 9:15 am

Hi, all!

I would like to make a shader that takes into account the local coordinates of a given object, not the entire drawable area. Here's an example:

Image

As you can see the effect is supposed to be weaker the closer it is to the left edge of an object - but the 2nd "flag" already starts with the stronger movement because it itself is positioned in the middle.

My code looks like this:
Code: Select all
/////////////////////////////////////////////////////////
// Flag effect
varying mediump vec2 vTex;
uniform lowp sampler2D samplerFront;
uniform mediump float seconds;

uniform lowp float pixelWidth;
uniform lowp float pixelHeight;
uniform mediump float xshift;
uniform mediump float yshift;
uniform mediump float time;

void main(void)
{   
   mediump vec2 tex = vTex;
   
   tex.y += sin(seconds/time+tex.x/xshift) * tex.x * yshift*pixelHeight;
      
   gl_FragColor = texture2D(samplerFront,tex);
}


Can that tex.x be replaced with a local space 0-1 coordinate?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Tue Jan 27, 2015 8:23 am

Well, R0J0 has provided a solution - for some reason if the <extend-box-horizontal> or <extend-box-vertical> settings in the xml are beyond zero we suddenly work with screen/layer coordinates, if they are 0 we work with local coordinates.

Image

Perhaps @Ashley could clarify why that is the way it is and if there is a way to use local coordinates, but expand the drawing area?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146


Return to Effects

Who is online

Users browsing this forum: No registered users and 0 guests