Shaders Almost perfect texture overlay shader

Neverday

Member
I have a shader that simply draws a texture over top of the sprite that calls it. It works perfectly when the dimensions of the sprite are a multiple of two. 32x32, 64x128, etc. If they're not then the overlay texture gets stretched in a weird way.

I believe the problem lies solely in my shader fragment code, but I can post the shader_set code if the project file I posted below is inaccessible.

Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform sampler2D dissolve_texture; //spr_noise
uniform vec4 dissolve_uvs; //uvs of spr_noise
uniform vec4 sprite_uvs; //uvs of spr_block
uniform vec2 basetexture_size; //W and H of spr_block
uniform vec2 noisetexture_size; //W and H of spr_noise

void main()
{
    //Map the noise texture to the block texture
    vec2 remapped_uvs = (v_vTexcoord.xy - dissolve_uvs.xy) * dissolve_uvs.zw;
  
    gl_FragColor = texture2D( dissolve_texture, remapped_uvs*(basetexture_size.xy/noisetexture_size.xy));
}
I'm a bit of a novice concerning shaders and this is a problem I can't seem to wrap my head around.
Also, here is a small project file I created to demo the problem. https://filebin.net/uokf92bwbgwnyo4j
Press left and right to adjust the image_xscale. Press up to swap between a 64x64 sprite and a 96x64 one
 
Last edited:

Neverday

Member
I completely glossed over the fact that texture page sizes are always a multiple of two, now this weird behavior makes sense.
 
Top