another shader question re: texcoords

This forum is currently in read-only mode.
  • hi again,

    when putting the following pixelshader on a sprite:

    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 [i]sometimes[/i] 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!
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The effect is processed on the object's bounding box

    hm, so it's a bug that a sprite can shift his texture outside of its bounds?

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

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