Custom varying variables

Howdy! I’m attempting to minimize the amount of data that’s sent to my fragment program. Essencially what I want to do is pass in the distance from a vertex to a light, and have it automaticially interpolate, rather than having to compute the distance per pixel.

Is it possible to do these custom varying vars? Or am I still going to have to do everything per fragment?

thanks
~Main

Sure, pretty simple to do:

Vertex:

varying vec3 dist;
void main()
{
    gl_Position = ftransform();
    dist = someCalc();
}

Fragment:

varying vec3 dist;
void main()
{
    gl_FragColor = vec4(dist, 1.0);
}

Note: jra101s’ above code will only give you the distance in each x,y and z direction per fragment. To get the absolute distance per fragment you will have to do someting like Length(dist); (in the fragment shader) to get the single float distance.

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