rework text shader, add basic and rect shaders
This commit is contained in:
parent
7623a85e4e
commit
c5de5ae479
6
runtime/shaders/basic.f.glsl
Normal file
6
runtime/shaders/basic.f.glsl
Normal file
@ -0,0 +1,6 @@
|
||||
uniform vec4 color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = color;
|
||||
}
|
21
runtime/shaders/basic.v.glsl
Normal file
21
runtime/shaders/basic.v.glsl
Normal file
@ -0,0 +1,21 @@
|
||||
/* Viewport width and height */
|
||||
uniform ivec2 viewport_size;
|
||||
/* Position of lower left corner of glyph */
|
||||
uniform ivec2 position;
|
||||
|
||||
/* Vertex coordinates: x, y */
|
||||
attribute vec2 coords;
|
||||
|
||||
/**
|
||||
* Map coordinates such that:
|
||||
* (0 .. viewport_size.[xy]) => (-1.0 .. 1.0)
|
||||
*/
|
||||
vec2 map_to_screen(vec2 position)
|
||||
{
|
||||
return 2.0 * position / viewport_size - 1.0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = vec4(map_to_screen((vec2)position + coords), 0, 1);
|
||||
}
|
23
runtime/shaders/rect.v.glsl
Normal file
23
runtime/shaders/rect.v.glsl
Normal file
@ -0,0 +1,23 @@
|
||||
/* Viewport width and height */
|
||||
uniform ivec2 viewport_size;
|
||||
/* Position of lower left corner of rectangle */
|
||||
uniform ivec2 position;
|
||||
/* Size of the rectangle */
|
||||
uniform ivec2 size;
|
||||
|
||||
/* Vertex coordinates: x, y (0 or 1) */
|
||||
attribute ivec2 coords;
|
||||
|
||||
/**
|
||||
* Map coordinates such that:
|
||||
* (0 .. viewport_size.[xy]) => (-1.0 .. 1.0)
|
||||
*/
|
||||
vec2 map_to_screen(vec2 position)
|
||||
{
|
||||
return 2.0 * position / viewport_size - 1.0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = vec4(map_to_screen((vec2)(position + coords * size)), 0, 1);
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
/* Texture coordinate: s, t */
|
||||
varying vec2 texture_coord_v;
|
||||
|
||||
/* Texture unit */
|
||||
uniform sampler2D texture;
|
||||
uniform vec4 color;
|
||||
|
||||
|
@ -1,16 +1,25 @@
|
||||
uniform vec2 screen_size;
|
||||
uniform vec2 position;
|
||||
/* Viewport width and height */
|
||||
uniform ivec2 viewport_size;
|
||||
/* Position of lower left corner of glyph */
|
||||
uniform ivec2 position;
|
||||
|
||||
/* Vertex coordinates: x, y, s, t */
|
||||
attribute vec4 coords;
|
||||
|
||||
/* Output texture coordinate: s, t */
|
||||
varying vec2 texture_coord_v;
|
||||
|
||||
/**
|
||||
* Map coordinates such that:
|
||||
* (0 .. viewport_size.[xy]) => (-1.0 .. 1.0)
|
||||
*/
|
||||
vec2 map_to_screen(vec2 position)
|
||||
{
|
||||
return 2.0 * position / viewport_size - 1.0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Map coordinates such that:
|
||||
// (0 .. screen_size.x) => (-1.0 .. 1.0)
|
||||
gl_Position = vec4(2.0 * (position.x + coords.x) / screen_size.x - 1.0,
|
||||
2.0 * (position.y + coords.y) / screen_size.y - 1.0,
|
||||
0, 1);
|
||||
gl_Position = vec4(map_to_screen((vec2)position + coords.xy), 0, 1);
|
||||
texture_coord_v = coords.zw;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user