Seems you are right. I have found that I can make colors transparent, they just lie on opaque mesh.
Thats what I have for now
name: "grid"
tags: "model"
vertex_program: "/materials/grid/grid.vp"
fragment_program: "/materials/grid/grid.fp"
vertex_space: VERTEX_SPACE_LOCAL
vertex_constants {
name: "mtx_worldview"
type: CONSTANT_TYPE_WORLDVIEW
}
vertex_constants {
name: "mtx_proj"
type: CONSTANT_TYPE_PROJECTION
}
fragment_constants {
name: "grid_color"
type: CONSTANT_TYPE_USER
value {
}
}
fragment_constants {
name: "cell_size"
type: CONSTANT_TYPE_USER
value {
}
}
fragment_constants {
name: "cell_border"
type: CONSTANT_TYPE_USER
value {
}
}
#version 330
in vec4 position;
in vec2 texcoord0;
uniform vertex_constants {
mat4 mtx_worldview;
mat4 mtx_proj;
};
out vec4 var_position;
out vec2 var_texcoord0;
void main()
{
vec4 p = mtx_worldview * vec4(position.xyz, 1.0);
var_position = p;
var_texcoord0 = texcoord0;
gl_Position = mtx_proj * p;
}
#version 330
in vec4 var_position;
in vec2 var_texcoord0;
uniform fragment_constants {
vec4 cell_border;
vec4 cell_size;
vec4 grid_color;
};
out vec4 out_color;
void main()
{
vec4 color = vec4(0, 0, 0, 0);
if(mod(var_texcoord0.x, cell_size.x) < cell_border.x
|| mod(var_texcoord0.y, cell_size.y) < cell_border.y) {
color = grid_color;
}
out_color = vec4(color.rgb * color.a, color.a);
}
function init()
local border = 2
local size = 100
local scale = go.get_scale() + vmath.vector3(border, border, 0)
local cell_border = vmath.vector4(border / scale.x, border / scale.y, 0, 0)
local cell_size = vmath.vector4()
cell_size.x = size / scale.x
cell_size.y = size / scale.y
go.set("#model", "cell_border", cell_border)
go.set("#model", "grid_color", vmath.vector4(0, 1, 0, 0.5))
go.set("#model", "cell_size", cell_size)
end