diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-31 12:26:22 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-31 12:26:22 +1000 |
commit | fa04ebc603a7bf742c64724ede23cfa010fb3c4c (patch) | |
tree | 59f000765e5528bda36194a91b21c187c9e988bd /assets/shaders/grid.vert | |
parent | c2fec36353c29d31ed95451e42413983808fd62e (diff) |
grid is not really working
Diffstat (limited to 'assets/shaders/grid.vert')
-rw-r--r-- | assets/shaders/grid.vert | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/assets/shaders/grid.vert b/assets/shaders/grid.vert index bdfa477..592cbfc 100644 --- a/assets/shaders/grid.vert +++ b/assets/shaders/grid.vert @@ -6,12 +6,37 @@ uniform Camera { vec4 viewPos; } cam; +out vec3 nearPoint; +out vec3 farPoint; +out float near; +out float far; +out mat4 fragView; +out mat4 fragProj; + // Grid position are in xy clipped space vec3 gridPlane[6] = vec3[]( vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0) ); -// normal vertice projection + +vec3 UnprojectPoint(float x, float y, float z, mat4 view, mat4 projection) { + mat4 viewInv = inverse(view); + mat4 projInv = inverse(projection); + vec4 unprojectedPoint = viewInv * projInv * vec4(x, y, z, 1.0); + return unprojectedPoint.xyz / unprojectedPoint.w; +} + +// normal vertex projection void main() { - gl_Position = cam.proj * cam.view * vec4(gridPlane[gl_VertexID].xyz, 1.0); + // gl_Position = cam.proj * cam.view * vec4(gridPlane[gl_VertexID].xyz, 1.0); + vec3 p = gridPlane[gl_VertexID].xyz; + nearPoint = UnprojectPoint(p.x, p.y, -1.0, cam.view, cam.proj).xyz; // unprojecting on the near plane + farPoint = UnprojectPoint(p.x, p.y, 1.0, cam.view, cam.proj).xyz; // unprojecting on the far plane + + fragView = cam.view; + fragProj = cam.proj; + near = 0.01; + far = 100.0; + + gl_Position = vec4(p, 1.0); // using directly the clipped coordinates }
\ No newline at end of file |