Shaders Doing it wrong? [Solved]

DesArts

Member
I am combining two shaders to create one that can draw a repeating textured vertex buffer with a colour fade. It seems that it's currently not drawing anything.

Shader:
Code:
//
// Simple passthrough vertex shader
//
    attribute vec3 in_Position;
 
    attribute vec4 in_Colour;                    // (r,g,b,a)
    attribute vec2 in_Textcoord0;
    attribute vec4 in_Textcoord1;
 
    varying vec2 v_vTexcoord;
    varying vec4 v_vRepeat;
    varying vec4 v_vColour;
 
    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;
  
        v_vColour = in_Colour;
  
        v_vTexcoord = in_Textcoord0;
        v_vRepeat = in_Textcoord1;
    }
Code:
//
// Simple passthrough fragment shader
//
    uniform vec4 f_colour;
    varying vec2 v_vTexcoord;
    varying vec4 v_vRepeat;
    varying vec4 v_vColour;
 
    void main()
    {
        vec2 UV = v_vTexcoord - floor( v_vTexcoord / v_vRepeat.xy - v_vRepeat.zw ) * v_vRepeat.xy;
        vec4 col = texture2D( gm_BaseTexture, UV );
        col.rgb = mix(col.rgb, f_colour.rgb, f_colour.a);
        gl_FragColor = v_vColour * col;
    }
Use:
Code:
//create
 
    FadeColour = shader_get_uniform(sh_repeat_textures_fade, "f_colour");
Code:
//just before drawin the shape

    Colour = c_white;
    fade_amount = 1; //these can be anything and it's still invisible

    shader_set(sh_repeat_textures_fade);
    shader_set_uniform_f(FadeColour, color_get_red(Colour)/225, color_get_green(Colour)/225, color_get_blue(Colour)/225, fade_amount); // 1,1,1 for white

//then I submit the vertex buffer and reset the shader
Doing this causes the shape drawn to be invisible. Not using the shader or using other shaders works as always.
I'm no good at shaders so I'm sure someone can spot something I'm messing up.
 
Last edited:

DesArts

Member
Fade amount doesn't change for the purposes of this example (any amount tested doesn't change anything), and shader_reset is called after submitting the vertex buffer.

For context here's the shader that DOES work but has none of the colour fade code:
Code:
//
// Simple passthrough vertex shader
//
    attribute vec3 in_Position;
    attribute vec2 in_Textcoord0;
    attribute vec4 in_Textcoord1;
    varying vec2 v_vTexcoord;
    varying vec4 v_vRepeat;
    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;
        v_vTexcoord = in_Textcoord0;
        v_vRepeat = in_Textcoord1;
    }
Code:
//
// Simple passthrough fragment shader
//
    varying vec2 v_vTexcoord;
    varying vec4 v_vRepeat;
    void main()
    {
        vec2 UV = v_vTexcoord - floor( v_vTexcoord / v_vRepeat.xy - v_vRepeat.zw ) * v_vRepeat.xy;
        gl_FragColor = texture2D( gm_BaseTexture, UV );
    }
 

DesArts

Member
I don't need to. The shader I just posted (which works fine) allows for any texture to be repeated in a vertex buffer regardless of it's settings/page.

But in the first shader posted in OP I've attempted to add colour fading (from another separate shader) to it, and thus it is invisible which is the focus of the issue. It's the same shader just with the added colour fading parts I've attempted.

I very highly doubt its anything other than the shader contents (or it's direct use) which is incorrect.
 
D

dannyjenn

Guest
I doubt this is the problem, but you should be dividing by 255. Not 225.
 
Top