forked from pythonarcade/arcade
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make line drawing twice as fast by making separate shaders for buffer…
…ed and unbuffered
- Loading branch information
Showing
10 changed files
with
104 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Line Shaders | ||
|
||
## Unbuffered | ||
|
||
Unbuffered lines have a single color even when drawing | ||
multiple lines. `draw_line` and `draw_lines`. | ||
This shader is simpler just taking a color as a uniform | ||
in the fragment shader. | ||
|
||
## Buffered | ||
|
||
Buffered lines need color passed in as a vertex attribute | ||
because we are concatenating several different line | ||
draw calls with different color configurations. |
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
arcade/resources/shaders/shapes/line_vs.glsl → ...rces/shaders/shapes/line_buffered_vs.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#version 330 | ||
|
||
|
||
in vec2 in_vert; | ||
in vec4 in_color; | ||
out vec4 vs_color; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 330 | ||
|
||
uniform vec4 color; | ||
|
||
out vec4 f_color; | ||
|
||
void main() { | ||
f_color = color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#version 330 | ||
|
||
layout (lines) in; | ||
layout (triangle_strip, max_vertices = 4) out; | ||
|
||
uniform mat4 Projection; | ||
uniform float line_width; | ||
|
||
vec2 lineNormal2D(vec2 start, vec2 end) { | ||
vec2 n = end - start; | ||
return normalize(vec2(-n.y, n.x)); | ||
} | ||
|
||
void main() { | ||
// Get the line segment | ||
vec2 line_start = gl_in[0].gl_Position.xy; | ||
vec2 line_end = gl_in[1].gl_Position.xy; | ||
|
||
// Calculate normal | ||
vec2 normal = lineNormal2D(line_start, line_end) * line_width / 2.0; | ||
|
||
// Emit a quad using a line strip with the correct line width | ||
gl_Position = Projection * vec4(line_start + normal, 0.0, 1.0); | ||
EmitVertex(); | ||
gl_Position = Projection * vec4(line_start - normal, 0.0, 1.0); | ||
EmitVertex(); | ||
gl_Position = Projection * vec4(line_end + normal, 0.0, 1.0); | ||
EmitVertex(); | ||
gl_Position = Projection * vec4(line_end - normal, 0.0, 1.0); | ||
EmitVertex(); | ||
|
||
EndPrimitive(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#version 330 | ||
|
||
in vec2 in_vert; | ||
|
||
void main() { | ||
gl_Position = vec4(in_vert, 0.0, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters