-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Line Stipple Shader #68
base: develop
Are you sure you want to change the base?
Changes from 4 commits
f7450bb
d430343
d5472f2
dd73a16
2341f19
7caca73
1c130b9
2cc01b1
23cdd81
613f0b5
975aad0
ee619c0
c460193
b810d3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec3 position; | ||
out vec4 color; | ||
|
||
uniform float line_width; | ||
uniform float line_stipple_factor; | ||
uniform float line_stipple_pattern; | ||
|
||
|
||
void main() { | ||
float step = 1.0 / line_stipple_factor; | ||
float pattern = mod(position.x * step, line_stipple_pattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relying on the x-coordinate alone will surely break things for completely vertical lines, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I see! I can add a second There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I don't think even that will be enough! We have to think in terms of stippling along the vector of the line we're drawing, rather than a cardinal (screen) direction, otherwise our results won't be consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I’ve come up with a good way to do this using dot products, and by letting the shader take vertex position and texture coordinates as inputs, while outputting the fragment texture coordinates. I'll send you my idea as a commit once I run some tests. |
||
if (pattern > 0.5) { | ||
discard; | ||
} | ||
gl_Position = vec4(position, 1.0); | ||
color = vec4(1.0, 0.0, 0.0, 1.0); | ||
} | ||
|
||
// Compile the shader | ||
GLuint shader = glCreateShader(GL_VERTEX_SHADER); | ||
glShaderSource(shader,1, &shader_source, NULL); | ||
glCompileShader(shader); | ||
|
||
// Bind the shader to the current OpenGl context | ||
glUseProgram(shader); | ||
|
||
// Set the uniforms | ||
glUniform1f(glGetUniformLocation(shader, "line_width"), 1.0f); | ||
glUniform1i(glGetUniformLocation(shader, "line_stipple_factor"), 1); | ||
glUniform1ui(glGetUniformLocation(shader, "line_stipple_pattern"), 0xFFFF); | ||
|
||
// Draw the line | ||
glDrawArrays(GL_LINE_STRIP, 0, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the line stipple is to be a fragment shader then we would have to have a version for each type of colouring (e.g. Phong) we want to be "stipplable". Do we think this is the best approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yes! I think I can implement a similar approach to the line stippling code, but using a geometry shader instead. Then we would only need one geometry shader, regardless of how the lines are coloured. I'll add the updated commit here;