• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Additional texture in shader not working

J

James Newnorth

Guest
Hi, I'm trying to use 2 textures in a shader, and it keeps rendering the same base texture even when I'm adressing the secondary texture.

This is in my Draw-event:
Code:
shader_set(sh_terrain);

var _uniform_id = shader_get_sampler_index(sh_terrain, "u_terrain_texture");

var _texture_id = sprite_get_texture(spr_terrain, 0);

texture_set_stage(_uniform_id, _texture_id);

draw_sprite_ext(spr_terrain_mask, 0, self.x, self.y, 4, 4, 0, c_white, 1);

shader_reset();
This is in my vsh:
Code:
//
// Simple passthrough vertex shader
//
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_texture_coordinate;
varying vec4 v_vColour;

void main() {
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vec4(in_Position.x, in_Position.y, in_Position.z, 1.0);
    
    v_texture_coordinate = in_TextureCoord;
    
    v_vColour = in_Colour;
}
This is in my fsh:
Code:
varying vec2 v_texture_coordinate;

varying vec4 v_vColour;

uniform sampler2D u_terrain_texture;

void main() {
    gl_FragColor = texture2D(u_terrain_texture, v_texture_coordinate);
}
 
J

James Newnorth

Guest
Solved it; it has to do with textures being grouped up. So the two textures are the same, and I can't use the texcoords like I do.
 
Top