1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

[SOLVED] Shader issue

Discussion in 'Legacy GameMaker Community Tech Support' started by w0rm, Jan 17, 2019.

  1. w0rm

    w0rm Member

    Joined:
    Aug 20, 2016
    Posts:
    12
    I have a project where I have set a shader to draw a circle segment. I'm using a sprite with size of 1x1 pixel for this and scale it to proper size. Everything works fine but the whole thing gets nuts the minute I add a second sprite to the project. After that my shader code is still applied but all the calculations within shader code go crazy. By removing the additional sprite from the project everything goes back to normal.

    I don't get this problem. There's absolutely no reference to the second sprite anywhere in the object, code or anywhere.

    EDIT:
    Exactly same thing seem to happen with GMS2.
     
    Last edited: Jan 17, 2019
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,102
    Unfortunately, as you've not shown your shader code, it is close to impossible to tell what you might be doing wrong, but I'd guess that your texture coordinates are absolute rather than based on sprite UVs
     
    w0rm likes this.
  3. w0rm

    w0rm Member

    Joined:
    Aug 20, 2016
    Posts:
    12
    Actually after playing with this issue for several hours I was able to figure out a workaround. The problem is fixed if I add a separate texture group for the sprite used with the shader and keep all other sprites in default texture group. I think this must have something to do with internals on how GMS works.
     
  4. w0rm

    w0rm Member

    Joined:
    Aug 20, 2016
    Posts:
    12
    I guess you refer to the same topic which is mentioned here under section "Rainbow shader"? I think this actually might be the case here! I'll try to figure out. Thx for the tip!!
     
  5. w0rm

    w0rm Member

    Joined:
    Aug 20, 2016
    Posts:
    12
    Indeed this was the issue. Fix was to add the following in shader to normalize v_vTexcoord as explained in the tutorial linked earlier:

    Code:
        vec2 v_vTexcoordN = vec2( (v_vTexcoord.x - u_uv[0] ) / (u_uv[2] - u_uv[0]),
                                  (v_vTexcoord.y - u_uv[1] ) / (u_uv[3] - u_uv[1]) );
    Thanks @YellowAfterlife

    EDIT:
    And yes, there's probably more efficient way to normalize but I'm not shader expert :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice