Hi there. I'm sure this one's simple to those experienced with shaders and buffers.
The goal itself IS simple to explain.
I need to apply a fade shader I have (or create a new one to perform the same function) to a plain colour/alpha un-textured vertex buffer.
I'm not that great with either and my current stuff doesn't seem to work together.
I have a vertex format:
And I'm creating a buffer with that format with a bunch of triangles, and I set the colour and alpha as I go through the points, naturally. It looks like this for each triangle:
When I apply any shader that tries to add a colour fade, the vertex buffer seems to become invisible, but draws perfectly fine when no shader is applied. If I try to do the same thing to a primitive it doesn't become invisible but it has no effect. The most basic version of the shader (which works with sprites, I haven't changed this one for any other purpose) is as follows:
I also have a shader which DOES work for textured vertex buffers (but doesn't work for the above), the details of that system are below:
And the shader that works with it looks like:
Before submitting the buffer etc I'd set the fade shaders:
Hopefully that's enough info, I'm sure its either an issue with the format I'm using for the plain colour buffer or the shaders aren't compatible in some way. Any help appreciated, thanks!
The goal itself IS simple to explain.
I need to apply a fade shader I have (or create a new one to perform the same function) to a plain colour/alpha un-textured vertex buffer.
I'm not that great with either and my current stuff doesn't seem to work together.
I have a vertex format:
Code:
//plain colour shape format
vertex_format_begin();
vertex_format_add_position(); //position of vertex
vertex_format_add_color();
global.VFPlainColour = vertex_format_end();
Code:
//pos 1
vertex_position(vertex_buffer, sx1, sy1);
vertex_colour(vertex_buffer, colour, alpha);
//pos 2
vertex_position(vertex_buffer, sx2, sy2);
vertex_colour(vertex_buffer, colour, alpha);
//pos 3
vertex_position(vertex_buffer, sx3, sy3);
vertex_colour(vertex_buffer, colour, alpha);
Code:
//
// Vertex: apply colour fade
//
attribute vec3 in_Position; // (x,y,z)
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
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_TextureCoord;
}
Code:
//
// Fragment: apply colour fade
//
uniform vec4 f_colour;
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord );
col.rgb = mix(col.rgb, f_colour.rgb, f_colour.a);
gl_FragColor = v_vColour * col;
}
Code:
//global vertex format
vertex_format_begin();
vertex_format_add_position(); //position of vertex
vertex_format_add_textcoord(); //texture coordinate of vertex
vertex_format_add_custom(vertex_type_float4, vertex_usage_textcoord); //used to wrap texture coordinates around the region defined below
vertex_format_add_color();
global.VFMainColour = vertex_format_end();
Code:
//
// Vertex: textured vertex buffer with colour fade
//
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:
//
// Fragment: textured vertex buffer with colour fade
//
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;
}
Before submitting the buffer etc I'd set the fade shaders:
Code:
shader_set(sh_fade);
shader_set_uniform_f(ItemFadeColour, 1, 1, 1, 0.5); // 1,1,1 for white