[Discussion] vTex Coordinates?

Share your Construct 2 effect files

Post » Mon Aug 04, 2014 12:28 pm

Hi all :)

I just started looking into making some GLSL shaders, and I have a few questions about the coordinate system.

1: What are the units for the vTex coordinate values? (e.g. pixels, sprite lengths, etc)

2: What is the origin for the vTex coordinates? (e.g. corner of layout, corner of sprite, etc)

3: Does the background need some kind of special coordinate conversion to ensure that it is sampled correctly? I ask because the "dodge" effect has the following line:

lowp vec4 back = texture2D( samplerBack , mix( destStart , destEnd , vTex ) );


It looks like "mix()" might be a lerp style function. It makes me wonder if vTex values run from 0 to 1 across a sprite, and so they are being used to lerp between the screen cords of the relevant patch of background, or something.

4: What are the "destStart" and "destEnd" variables, and what are their units and origin?

Just curious, thanks. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,156

Post » Mon Aug 04, 2014 1:02 pm

1. Texture co-ordinates. These always range from 0 to 1.
2. Always the top-left of the quad.
3. Yes: sometimes the effect will have been rendered to an intermediate window-sized texture if multiple effects are involved. Therefore the effect is processing the background on a sub-rectangle of the texture, not the entire texture. This leads on to 4: destStart and destEnd are vec2s marking the rectangle of the sub-texture being processed. Mix is indeed like lerp, and so mixing from destStart to destEnd by vTex gives you the correct texture co-ordinate of the background pixel to sample corresponding to the foreground.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Tue Aug 05, 2014 7:09 am

Wow, awesome. Thanks. :D

A few more questions just occurred to me, actually.

5: If you place an effect on a sprite, can you sample parts of a foreground sprite that are off-screen?
Just checking because I played around with a blur, and it looks like it ignores pixels that are outside the visible screen area. More specifically it looks like sample coords that refer to off-screen locations are clamped to the closest equivalent on-screen location.

6: Can the origin of the vTex coords ever be outside the visible screen area?
i.e. If a foreground sprite's top-left corner moves off-screen, does the origin of the vTex coords move off screen with it, or are the vTex coords squeezed to fit inside the edges of the visible screen area?
In Construct Classic, I vaguely recall the HLSL coords acting a little different as a sprite started moving off-screen.


7: Is there any place I should look to find out more about the details of the Construct 2's GLSL related stuff, or is the forum the best place to ask about this kind of thing?

Thanks again. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,156

Post » Tue Aug 05, 2014 9:56 am

5. No: nothing offscreen is actually rendered.
6. No: the origin is always clamped to the visible area.
7. You can ask C2 specific questions here, or browse through the other effects to see how they're written. For general GLSL questions though there's always the web :)
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Tue Aug 05, 2014 11:05 pm

Sounds good. Thanks again. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,156


Return to Effects

Who is online

Users browsing this forum: No registered users and 0 guests