r/love2d•
sealg

Is there any way to get information back out of a shader?

I'm using a vertex shader to render a 3d star field. To do this, I'm building a mesh with the coordinates & colors for each star, adding an attribute for a z coordinate to each vertex, and projecting the 3d points onto the 2d screen with the vertex shader. The problem is, I want to know which star gets rendered closest to the center of the screen, but I don't have any way to figure out which pixel is from which star specifically. Is there any way to, for example, calculate the drawn distance from center and put that back on a readable attribute on the mesh, or otherwise get some piece of data (other than the pixel coordinates and colors) back out of the shader that'll help me figure out which star the player is pointing at?

(My code is all up here if that helps: https://github.com/sealgair/Jolly-Xanthar )

Posted May 15, 2016, 7:41 PM UTC

98
Loading comments…