Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Shader coordinate fails — Gideros Forum

Shader coordinate fails

YanYan Member
edited February 2017 in Bugs and issues
void main()
{
	vec2 coord = fTexCoord.xy;
 
	vec4 solidRed = vec4(0,0,0,0.2);
 
	if (fTexCoord.x > 0.5) { -- here I tried >= instead >, no sense
		solidRed.r = 0.5;
	}
 
    gl_FragColor = solidRed;
}
This simple shader should provide a HALF of screen in red color, and HALF in a gray, but it misses on some coeffcient, if I setup my project width not 960, but 1000px, so it works FINE, but if I set . This is very strange to me and make me sick.

Notice I use LandskapeLeft. You can see this issue in small demo project.
zip
zip
WrongShaderCenter.zip
4K
Снимок.JPG
1001 x 620 - 38K
vk.com/yan_alex

Comments

  • hgy29hgy29 Maintainer
    Accepted Answer
    Hi @Yan,

    This happens because texture coordinates are not necessarily spanning from 0 to 1, depending on your texture size. Gideros internally ensures that textures are power of two sized, that is your texture if not power of two sized, gideros will allocate the nearest power of two size and adjust texture coordinates passed to the shader to account for this.

    Since in your shader you use 'Shader.SYS_TEXTUREINFO', you can extract actual texture bounds from fTexSize uniform: fTexSize.x will be texture width (between 0 and 1) and fTexSize.y will be the height.

    So your test should be:
    if (fTexCoord.x > (0.5*fTexSize.x))
  • Hi @Yan,

    This happens because texture coordinates are not necessarily spanning from 0 to 1, depending on your texture size. Gideros internally ensures that textures are power of two sized, that is your texture if not power of two sized, gideros will allocate the nearest power of two size and adjust texture coordinates passed to the shader to account for this.

    Since in your shader you use 'Shader.SYS_TEXTUREINFO', you can extract actual texture bounds from fTexSize uniform: fTexSize.x will be texture width (between 0 and 1) and fTexSize.y will be the height.

    So your test should be:
    if (fTexCoord.x > (0.5*fTexSize.x))
    Thanks, Bro. You helped me so much again !

    Gosh, It works. Same thing on Bitmap from RenderTexture. I still didnt get how you find out this fix, because im floating in math, but still this works, I need to think about.
    vk.com/yan_alex
  • I want to make edge pixels alphablended, so Im passing light pos to shader, but all my coordinates are tighten to screen, I cant get coordinate according my Texture to fing length between source of light and current pixel.
    Скриншот 2017-02-06 11.53.59.png
    441 x 393 - 179K
    vk.com/yan_alex
Sign In or Register to comment.