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

0 favourites
  • 2 posts
From the Asset Store
Ludo Local Multiplayer board game can be played by 2 to 4 players
  • 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:

    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:

    /////////////////////////////////////////////////////////
    // 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);
    }[/code:25tcptdj]
    
    Can that tex.x be replaced with a local space 0-1 coordinate?
  • Try Construct 3

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

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

    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?

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