diff options
author | David Robillard <d@drobilla.net> | 2019-12-07 21:42:52 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-11 23:18:51 +0100 |
commit | ad39159e3ada8086ad8385226c0361f4ff51f90d (patch) | |
tree | 1c483cac5f63e8dd2e90477992f77418654434c4 /shaders | |
parent | 47b8e416954e499247cc4bb002496c4d8aa1a808 (diff) | |
download | pugl-ad39159e3ada8086ad8385226c0361f4ff51f90d.tar.gz pugl-ad39159e3ada8086ad8385226c0361f4ff51f90d.tar.bz2 pugl-ad39159e3ada8086ad8385226c0361f4ff51f90d.zip |
GL3 Test: Use instancing
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/rect.frag | 13 | ||||
-rw-r--r-- | shaders/rect.vert | 24 |
2 files changed, 26 insertions, 11 deletions
diff --git a/shaders/rect.frag b/shaders/rect.frag index c5dedf9..5e3af9d 100644 --- a/shaders/rect.frag +++ b/shaders/rect.frag @@ -10,10 +10,9 @@ specified precisely in pixels to draw sharp lines. The border width is just hardcoded, but could be made a uniform or vertex attribute easily enough. */ -uniform vec2 u_size; -uniform vec4 u_fillColor; - noperspective in vec2 f_uv; +noperspective in vec2 f_size; +noperspective in vec4 f_fillColor; layout(location = 0) out vec4 FragColor; @@ -22,14 +21,14 @@ main() { const float borderWidth = 2.0; - vec4 borderColor = u_fillColor + vec4(0.0, 0.4, 0.4, 0.0); + vec4 borderColor = f_fillColor + vec4(0.0, 0.4, 0.4, 0.0); float t = step(borderWidth, f_uv[1]); - float r = step(borderWidth, u_size.x - f_uv[0]); - float b = step(borderWidth, u_size.y - f_uv[1]); + float r = step(borderWidth, f_size.x - f_uv[0]); + float b = step(borderWidth, f_size.y - f_uv[1]); float l = step(borderWidth, f_uv[0]); float fillMix = t * r * b * l; float borderMix = 1.0 - fillMix; - vec4 fill = fillMix * u_fillColor; + vec4 fill = fillMix * f_fillColor; vec4 border = borderMix * borderColor; FragColor = fill + border; diff --git a/shaders/rect.vert b/shaders/rect.vert index de74fa7..bf2e951 100644 --- a/shaders/rect.vert +++ b/shaders/rect.vert @@ -3,16 +3,32 @@ /* The vertex shader is trivial, but forwards scaled UV coordinates (in pixels) to the fragment shader for drawing the border. */ -uniform mat4 MVP; -uniform vec2 u_size; +uniform mat4 u_projection; -in vec2 v_position; +layout(location = 0) in vec2 v_position; +layout(location = 1) in vec2 v_origin; +layout(location = 2) in vec2 v_size; +layout(location = 3) in vec4 v_fillColor; noperspective out vec2 f_uv; +noperspective out vec2 f_size; +noperspective out vec4 f_fillColor; void main() { - f_uv = v_position * u_size; + // clang-format off + mat4 m = mat4(v_size[0], 0.0, 0.0, 0.0, + 0.0, v_size[1], 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + v_origin[0], v_origin[1], 0.0, 1.0); + // clang-format on + + mat4 MVP = u_projection * m; + + f_uv = v_position * v_size; + f_size = v_size; + f_fillColor = v_fillColor; + gl_Position = MVP * vec4(v_position, 0.0, 1.0); } |