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


glsl shader (continued) by taby
// Thank you to Keenan Crane for the basis of this GPU raytracer

// ray origin
// ray direction
varying vec3 eye, eye_dir;

uniform vec3 light;
uniform vec2 x_bounds;
uniform vec2 y_bounds;
uniform vec2 z_bounds;

void main()
{
    // limit the number of intensity levels per colour channel
    float shades_per_channel = 10.0;

    // construct color from ray direction
    // 3D Labs GLSL Validator complains about it because rD_origin may be read-only...
    eye_dir = normalize(eye_dir);
 
    float x = abs(dot(eye_dir, vec3(1.0, 0.0, 0.0)));
    float y = abs(dot(eye_dir, vec3(0.0, 1.0, 0.0)));
    float z = abs(dot(eye_dir, vec3(0.0, 0.0, 1.0)));
 
    // colour by previous calculations
    gl_FragColor.a = 1.0;
    gl_FragColor.b = 1.0 - floor(shades_per_channel * x) / shades_per_channel;
    gl_FragColor.g = 1.0 - floor(shades_per_channel * y) / shades_per_channel;
    gl_FragColor.r =       floor(shades_per_channel * z) / shades_per_channel;

    // colour control
    float sat_percent = 50.0;
    float bri_percent = 75.0;
    
    // any "* 0.01" were originally "/ 100"
    // not sure if the nvidia-bundled glsl compiler optimizes for this?

    // saturation
    gl_FragColor.r += ((1.0 - gl_FragColor.r) * 0.01) * (100.0 - sat_percent);
    gl_FragColor.g += ((1.0 - gl_FragColor.g) * 0.01) * (100.0 - sat_percent);
    gl_FragColor.b += ((1.0 - gl_FragColor.b) * 0.01) * (100.0 - sat_percent);

    // brightness
    gl_FragColor.r *= bri_percent * 0.01;
    gl_FragColor.g *= bri_percent * 0.01;
    gl_FragColor.b *= bri_percent * 0.01;
}