Shaders Mode 7 Shader Issue

I was making a shader to simulate the super Nintendo's Mode 7, and it more or less worked, but whenever I squished the image, another sprite would appear along side it as if it was part of that image. The two images are not part of the same sprite and I don't currently call the other sprite anywhere else.

Here is my code for the VSH:

Code:
attribute vec3 in_Position;                  // (x,y,z)
//attribute vec3 in_Normal;                  // (x,y,z)     unused in this shader.
attribute vec4 in_Colour;                    // (r,g,b,a)
attribute vec2 in_TextureCoord;              // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform vec4 ModeSev;                         // (H, V, X0, Y0)
uniform vec4 ModeSevTwo;                     // (A, B, C, D)

void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    
    float CoordAfterX = (in_TextureCoord[0] + ModeSev[0] - ModeSev[2]);
    float CoordAfterY = (in_TextureCoord[1] + ModeSev[1] - ModeSev[3]);
    
    float xPos = ((ModeSevTwo[0] * CoordAfterX) + (ModeSevTwo[1] * CoordAfterY));
    float yPos = ((ModeSevTwo[2] * CoordAfterX) + (ModeSevTwo[3] * CoordAfterY));
    
    v_vColour = in_Colour;
    v_vTexcoord[0] = xPos;
    v_vTexcoord[1] = yPos;
}
And here is my code for the FSH:
Code:
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
    
    vec4 texColor = texture2D(gm_BaseTexture, v_vTexcoord);
    
    gl_FragColor = v_vColour * vec4(texColor.r, texColor.g, texColor.b, texColor.a);

}
 
in general, if wrong things are appearing in your textures, it is because those things actually are included in the same texture automatically. An easy fix is to put a sprite on its own texture page... in gms1.4 that can be done in the sprite editor by checking "used for 3d", something similar exists for GMS2. An alternative is to get the uvs for your image, and to convert your xpos,ypos from the range 0 to 1 (assuming it has that range), into the same range as your uvs.
 
in general, if wrong things are appearing in your textures, it is because those things actually are included in the same texture automatically. An easy fix is to put a sprite on its own texture page... in gms1.4 that can be done in the sprite editor by checking "used for 3d", something similar exists for GMS2. An alternative is to get the uvs for your image, and to convert your xpos,ypos from the range 0 to 1 (assuming it has that range), into the same range as your uvs.
Yes! All I had to do was check "Separate Texture Page" in the sprite editor. Thank you!
 
R

Rydon_Star

Guest
Arise Arise! Sorry to revive this thread, but I was looking for a Mode 7 type of code / shader for an overworld map I have (much like Final Fantasy on SNES days). Can you give a little more info on this shader? I am assuming I can apply it to a background, or multiple background layers, but I am not very knowledable on shaders right now so any insight would be appreciated for how to get this to scale for backgrounds, etc.
 
Top