<p>I have a projection calculation which maps points from 3D space to pixel (image) space, and I want to use it as instead of the standard MVP projections in a vertex shader.</p>
<p>In the image below the lower blue flow is how I understand the pipeline works in GLSL, and the upper green arc is what I want to use instead.
<a href="https://i.sstatic.net/fSPEK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fSPEK.png" alt="enter image description here" /></a></p>
<p>Since GLSL's projection matrix doesn't produce pixel coordinates, but a homogenous vec4 that allows to calculate pixel coords and depth estimation, I need to make some adjustments:</p>
<p>My idea is to take the vec2 pixel coordinates from my calculation, map them to clip space and let openGL finish the conversion to pixel space by itself</p>
<p><a href="https://i.sstatic.net/yP8GW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yP8GW.png" alt="enter image description here" /></a></p>
<p>Only problem is I'm not entirely sure how to pull this off, as you can see Im missing some essential data about what happens after Clip space</p>
<p>Any ideas?</p>
<p><strong>EDIT:</strong>
The GLSL implementation of the 3D to 2D projection function can be found here
<a href="https://www.shadertoy.com/view/fltfW2" rel="nofollow noreferrer">https://www.shadertoy.com/view/fltfW2</a></p>

CC BY-SA 4.0
2022-09-19T07:50:16.253Z
Can you add some information about the way you calculate the pixel position?
Thomas
CC BY-SA 4.0
2022-09-19T09:29:58.063Z
At the first "???" there the 4D vector will be divided by its "w" component. The geometry will be clipped to range [-1, 1] in all dimensions (z value range can be clipped on a different range depending on the graphics library you are using)....
Thomas
CC BY-SA 4.0
2022-09-19T09:41:15.037Z
Hi @Thomas, thanks for helping!

Unfortunately I cannot disclose the calculations or matrices but I can say its been tested to take a point in 3D space and return it's projected 2D pixel coordinate (image / screen size is taken into account of course).
it has been tested both in python and in GLSL (shadertoy)
Roman
CC BY-SA 4.0
2022-09-19T09:49:11.373Z
when having a triangle (3 vertices) is the surface spanning this triangle a triangle in your calculated space as well?
Thomas
CC BY-SA 4.0
2022-09-19T11:08:42.053Z
the relationship between the vertices doesn't change so a triangle will remain a triangle.
Roman
CC BY-SA 4.0
2022-09-20T12:41:24.867Z
Hi @Thomas, I edited the post and added a link to shadertoy where I have the GLSL implementation: https://www.shadertoy.com/view/fltfW2
Roman
<shader><projections><matrix>
Alternate projections in shader
Roman
# Alternate projections in shader

(Asked by: username_0 on 2022-09-18)

I have a projection calculation which maps points from 3D space to pixel (image) space, and I want to use it as instead of the standard MVP projections in a vertex shader.

In the image below the lower blue flow is how I understand the pipeline works in GLSL, and the upper green arc is what I want to use instead.
[![enter image description here](https://i.sstatic.net/fSPEK.png)](https://i.sstatic.net/fSPEK.png)

Since GLSL's projection matrix doesn't produce pixel coordinates, but a homogenous vec4 that allows to calculate pixel coords and depth estimation, I need to make some adjustments:

My idea is to take the vec2 pixel coordinates from my calculation, map them to clip space and let openGL finish the conversion to pixel space by itself

[![enter image description here](https://i.sstatic.net/yP8GW.png)](https://i.sstatic.net/yP8GW.png)

Only problem is I'm not entirely sure how to pull this off, as you can see Im missing some essential data about what happens after Clip space

Any ideas?

**EDIT:**
The GLSL implementation of the 3D to 2D projection function can be found here
<https://www.shadertoy.com/view/fltfW2>

**Tags:** shader, projections, matrix

> **Comments:**
> **username_1**: Can you add some information about the way you calculate the pixel position?  
> **username_1**: At the first "???" there the 4D vector will be divided by its "w" component. The geometry will be clipped to range [-1, 1] in all dimensions (z value range can be clipped on a different range depending on the graphics library you are using)....  
> **username_0**: Hi @username_1, thanks for helping!  Unfortunately I cannot disclose the calculations or matrices but I can say its been tested to take a point in 3D space and return it's projected 2D pixel coordinate (image / screen size is taken into account of course). it has been tested both in python and in GLSL (shadertoy)  
> **username_1**: when having a triangle (3 vertices) is the surface spanning this triangle a triangle in your calculated space as well?  
> **username_0**: the relationship between the vertices doesn't change so a triangle will remain a triangle.  
> **username_0**: Hi @username_1, I edited the post and added a link to shadertoy where I have the GLSL implementation: https://www.shadertoy.com/view/fltfW2  

---

## 0 answers

