Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Custom varying variables.

  1. #1

    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

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: Custom varying variables.

    Sure, pretty simple to do:

    Vertex:
    Code :
    varying vec3 dist;
    void main()
    {
        gl_Position = ftransform();
        dist = someCalc();
    }
    Fragment:
    Code :
    varying vec3 dist;
    void main()
    {
        gl_FragColor = vec4(dist, 1.0);
    }

  3. #3
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,000

    Re: Custom varying variables.

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •