From fa04ebc603a7bf742c64724ede23cfa010fb3c4c Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:26:22 +1000 Subject: grid is not really working --- assets/shaders/grid.vert | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'assets/shaders/grid.vert') 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 -- cgit v1.2.3-70-g09d2