gl_PointCoord
returns the 2D vector representing the UV mapping coordinates at that pixel. But it appears to be only available in the fragment shader. I know that you can send values from the vertex shader to the fragment shader with varying
, but can you send it the other way? Can I get the UV coordinates for the current vertex?
Is it possible access gl_PointCoord
in a vertex shader?
"UV mapping coordinates at that pixel" - Indeed, but in the vertex shader you don't have any pixels. You're missing how point sprites actually work. A single vertex shader invocation putting out a gl_PointSize
larger than 1 pixel results in multiple fragment shader invocations for this point (because the point, well, covers multiple pixels). And those fragments get their gl_PointCoord
based on their position inside this larger point sprite. But each point sprite covering multiple fragments always results from a single vertex. So conceptually this single per-vertex gl_PointCoord
would just be (0.5, 0.5)
for each vertex, but in the end even this doesn't make sense because there really is no notion of any pixels let alone per-pixel UV-coordinates inside a vertex shader.
"but can you send it the other way" - And I'm sure this was meant rather informally, since of course you cannot send any data from a fragment shader to the vertex shader, as the graphics pipeline only works in a single direction.
EDIT: Regarding your comment, if not using point sprites, the gl_PointCoord
variable doesn't have any meaning at all. You cannot use it as a general UV-coordinate (how should the fragment shader come up with a reasonable value). For that you have to put out a valid texture coordinate youself from your vertex shader (as a varying
) that then gets interpolated over the fragments to be accessed in the fragment shader, maybe ultimately passed into the vertex shader as an additional attribute
, as is usual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With