GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


basic glsl v/f shaders by taby
// VERTEX.GLSL

// ray origin
// ray direction

varying vec3 rO_origin, rD_origin;

void main()
{
    gl_Position = ftransform();

    // see C# code for explanation on what these hold - sjh jan 18, 2006
    rO_origin = gl_MultiTexCoord0;
    rD_origin = gl_Color;
}





// FRAGMENT.GLSL

// ray origin
// ray direction

varying vec3 rO_origin, rD_origin;


void main()
{
    vec4 frag_colour;
    
    // for quantizing the fragment colour
    float palette_size = 32.0;

    // perform dot product operation on the fragment ray vector,
    // in order to visualize its direction
    frag_colour.a = 1.0;
    frag_colour.b = floor((palette_size + 1.0) * dot(normalize(rD_origin), vec3(0.0, 0.0, -1.0))) / (palette_size + 1.0);
    frag_colour.g = frag_colour.b;
    frag_colour.r = 1.0;

    gl_FragColor = frag_colour;
}