-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
39 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
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 |
---|---|---|
@@ -1,32 +1,26 @@ | ||
// https://dev.to/javiersalcedopuyo/simple-infinite-grid-shader-5fah | ||
#extension GL_ARB_shading_language_420pack : enable | ||
|
||
layout(std140, binding = 0) uniform u_uniformblock { | ||
layout(std140) uniform u_uniformblock { | ||
vec3 camera_pos; | ||
mat4 view; | ||
mat4 proj; | ||
}; | ||
|
||
#include "planeconstant.glsl" | ||
|
||
// Vertex input and output | ||
layout(location = 0) in uint a_vertex_id; | ||
|
||
out VertexOut { | ||
vec4 position; | ||
vec3 camera_pos; | ||
vec2 coords; | ||
} v_out; | ||
$out vec4 v_position; | ||
flat $out vec3 v_camera_pos; | ||
$out vec2 v_coords; | ||
|
||
// Vertex shader | ||
void main() { | ||
vec4 world_pos = positions[a_vertex_id]; | ||
vec4 world_pos = positions[gl_VertexID]; | ||
world_pos.xyz *= grid_size; | ||
world_pos.xz += camera_pos.xz; // Make the quad follows the camera for "infinity" | ||
|
||
v_out.position = proj * view * world_pos; | ||
v_out.camera_pos = camera_pos; | ||
v_out.coords = world_pos.xz; | ||
v_position = proj * view * world_pos; | ||
v_camera_pos = camera_pos; | ||
v_coords = world_pos.xz; | ||
|
||
gl_Position = v_out.position; | ||
gl_Position = v_position; | ||
} |