3D Coords as Varying in Fragment Shader

I was wondering if it’s possible to this in GLSL since I don’t think it’s possible with HLSL. Is it possible to get an interpolated 3D coordinates in the pixel shader, as a variant, like we do with texture coordinates? Though I don’t find any reason why it’s not possible.


gl_PointCoord gives the interpolated window coords, not the original point in 3D space.

Define your own varying and write to it the position (in whatever space you need) in the vertex shader.

Okkkkay that’s really interesting. But does it have to be supported by a specific shader model or it’s a basic feature in only GLSL?


If it supports GLSL it must support at least some varying variables. The specifications say the minimum is 32 floats (say eight vec4’s), however really old cards such as the Geforce 2 GTS only supports 8 floats (two vec4’s). However anything newer than that seems to support the minimum of 32.

and is that possible with HLSL? Just curious.

Of course, this is the most basic shader functionality. It’s no different from passing texture coordinates from the vertex shader to the fragment shader.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.