So, in OpenGLES-2 the fragment shader has access to gl_PointCoord to see where the fragment is located on a point primitive.
There is also gl_FragCoord to see where a fragment is located on the frame buffer.
However, where is gl_LineCoord? It does not exist, so how can my fragment shader know the location of a fragment on a line primitive?
The reason I want to know this, is that I want to do a dashed line, with the dashes in screen space, not world space.
The only way to do this that I can currently think of is taking a sqrt of fragCoord.x^2 + fragCoord.y^2 but that sounds costly and unnecessary if there only was a gl_LineCoord available.
gl_PointCoord is a fragment language input variable that contains the two-dimensional coordinates indicating where within a point primitive the current fragment is located. If the current primitive is not a point, then values read from gl_PointCoord are undefined.
The actual result is: gl_FragCoord. xy is in the range [0.5, 1023.5], not [0.0, 1023.0]. From the spec: "By default, gl_FragCoord assumes a lower-left origin for window coordinates and assumes pixel centers are located at half-pixel coordinates.
Yes, gl_FragColor is deprecated. You should use the following syntax: layout(location = 0) out vec4 diffuseColor; It is included in the GLSL 4.60 spec under the section 7.1.
The built-in gl_VertexIndex variable contains the index of the current vertex. This is usually an index into the vertex buffer, but in our case it will be an index into a hardcoded array of vertex data.
There is no equivalent to what you want. But really, this isn't difficult. Just pass the value 0 at one end of the line, and 1 at the other. Let the interpolation tell you how far along the line you are. That will give you the equivalent of what you want.
Granted, it's not going to help you that much in drawing dashed lines in screen space, but then gl_PointCoord
wouldn't help you with that either (since it only goes from [0, 1] just like this value).
But you asked for the line equivalent of gl_PointCoord
, and I gave you that.
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