-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up uniform buffer, and apply simple world-to-screen transformatio…
…n in vertex shader.
- Loading branch information
Showing
2 changed files
with
70 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
// Vertex shader for simple particle system | ||
#version 410 | ||
|
||
// Uniforms passed from main app: this matches struct uniform_data in the C++ code | ||
layout(std140) uniform uniform_data | ||
{ | ||
vec2 window_size; // window size in world space | ||
vec2 window_center; // window center in world space | ||
}; | ||
|
||
// Input data from vertex buffer | ||
layout(location = 0) in vec2 vertex_position; | ||
|
||
void main() | ||
{ | ||
// Set the output position in screen space | ||
gl_Position = vec4(vertex_position, 0.0, 1.0); | ||
// Use the window size to scale the vertex position from world space to [-1, 1] screen space | ||
vec2 screen_space_pos = (vertex_position - window_center) / (0.5 * window_size); | ||
gl_Position = vec4(screen_space_pos, 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