View Full Version : Custom varying variables.

05-27-2004, 09:47 AM
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?


05-27-2004, 10:21 AM
Sure, pretty simple to do:


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

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

05-27-2004, 03:16 PM
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.