GM:S 1.4 [Solved] Not passing the correct subimage UVs?

Discussion in 'Advanced Programming Discussion' started by Ampersand, Feb 26, 2018.

  1. Ampersand

    Ampersand Member

    Joined:
    Jan 30, 2017
    Posts:
    216
    Hey there!

    Trying to get this masking shader to work with multiple mask subimages. Could anyone explain to me as to why this script will only pass the UVs of the first subimage no matter what I plug in for argument1 (the mask sub image)?

    Code:
    ///shader_set_uniforms(source, image, sprite, image_index)
    source = argument0; //the source sprite
    image = argument1; //image index to use
    shader_set(sha_maskover); //We won't call this again
    var u_Mask = shader_get_sampler_index(sha_maskover, "u_Mask");
    var u_MaskUV = shader_get_uniform(sha_maskover, "u_MaskUV");
    var u_SpriteUV = shader_get_uniform(sha_maskover, "u_SpriteUV");
    var u_StatSlide = shader_get_uniform(sha_maskover, "u_StatSlide") ;
    var u_StatFactor = shader_get_uniform(sha_maskover, "u_StatFactor") ;
    
    var maskTex = sprite_get_texture(source, image);
    var maskUVs = sprite_get_uvs(source, image);
    texture_set_stage(u_Mask, maskTex);
    shader_set_uniform_f(u_MaskUV, maskUVs[0] / 4, maskUVs[1] / 4, maskUVs[2] / 4, (maskUVs[3] / 4));
    
    var spriteUVs = sprite_get_uvs(argument2, argument3);
    shader_set_uniform_f(u_SpriteUV, spriteUVs[0], spriteUVs[1], spriteUVs[2], spriteUVs[3]);
    shader_set_uniform_f(u_StatSlide, 0, stat_slide / 4) ;
    shader_set_uniform_f(u_StatFactor, stat_factor) ;
    

    Pulling my hair out a bit on this one, as it only wants to mask using the first subimage of the mask sprite.

    The fragment shader for sha_maskover:
    Code:
    varying vec2 v_vTexcoord;
    varying vec4 v_vColour;
    uniform sampler2D u_Mask;
    uniform vec4      u_MaskUV;
    uniform vec4      u_SpriteUV;
    uniform vec2      u_StatSlide;
    uniform float      u_StatFactor;
    
    void main() {
      gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
      vec2 pos = (v_vTexcoord - u_SpriteUV.xy) / (u_SpriteUV.zw - u_SpriteUV.xy);
      vec2 maskCoord = mix(u_MaskUV.xy + u_StatSlide, u_MaskUV.zw + u_StatSlide, pos);
      vec4 maskColor = texture2D( u_Mask, maskCoord ) ;
      //float final = max(maskColor.a, 1.0 - u_StatFactor) ;
      gl_FragColor.rgb *= (1.0 - maskColor.a * u_StatFactor);
      gl_FragColor.rgb += maskColor.rgb * maskColor.a * u_StatFactor;
    }
    

    Thanks in advance!

    Edit: Solved. I didn't have the mask texture marked for 3D use which has been causing all kinds of funny things to happen. If I'd known that from the start, this whole thing would've been a little easier :p
     
    Last edited: Feb 26, 2018

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