another shader question re: texcoords

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Thu Jan 22, 2009 8:59 pm

hi again,

when putting the following pixelshader on a sprite:
[code:17zosu4h]float4 color = tex2D( foreground, Tex.xy + 0.1 );
return color;[/code:17zosu4h]the texture is not only displaced as expected, but even drawn outside of the sprite's bounds. it also produces strange artifacts when moving the sprite close to the layout's borders. this happens with and without any combination of #BORDERMODE and #CROSS-SAMPLING, with varying funniness.

the following pixel shader, on the other hand:
[code:17zosu4h]float4 color = float4( 0, 0, 0, 1 );
if( Tex.x <= 0.1 ){ color = 1; }
if( Tex.x >= 0.9 ){ color = 1; }
return color;[/code:17zosu4h]produces white stripes on the sprite only when its bounds are moved near the borders of the layout.

could you enlighten me with what's going on, aka what geometry & texture the shader is really working on? (it is confusing that the first is not a sprite-sized quad since it can sometimes render beyond its bounds, and the second is not the sprites' texture since a texture coordinate of (0,0) refers to the top left corner of the layout...)

thank you very much again!
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Thu Jan 22, 2009 11:08 pm

The effect is processed on the object's bounding box on a fullscreen texture, so the texture coordinates (0,0) refer to the top left of the screen, not the top left of the object. For the texture coordinates of the object's area, use the boxLeft, boxTop, boxRight and boxBottom variables.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Thu Jan 22, 2009 11:40 pm

[quote="Ashley":176f6euy]The effect is processed on the object's bounding box[/quote:176f6euy]
hm, so it's a bug that a sprite can shift his texture outside of its bounds?
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Fri Jan 23, 2009 12:02 am

No, the runtime can't force shaders not to draw outside the object's bounding box, but behavior if you do so is undefined. Pixels outside of the bounding box will be whatever is left over from previous rendering operations that need an intermediate stage. Also, if there is a second effect in the chain, the next shader only processes the bounding box, and the bounding box is the only area copied to the display, so in some cases it will be truncated anyway.

Basically, although you can, you should not write shaders that access outside the bounding box.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests