Calculating Primary Rays
Calulating primary rays can be easily mapped to a fragment/pixel shader: for each pixel a ray is calculated. If the ray hits the axis aligned bounding box (AABB) of the scene then it will be used for further processing, otherwise the pixel is “rejected” from further processing using early Z-culling.
Uniform Variables
vec3 _upvec; // camera: up-vector
vec3 _right; // camera: vector to the right
vec3 _tl; // camera: vector to the "virtual screen" top left
float _pixelsize; // pixel size of the "virtual screen"
vec3 g1,g2; // Axis Aligned Bounding Box (AABB) of the scene
float psize; // Size of a pixel in texture coordinates (i.e. 1/256 for a 256x256 image)
vec3 camera_pos; // camera position |
vec3 raydir(vec2 pixelpos) { vec3 direction = _tl + _right*(_pixelsize/2.0) - _upvec*(_pixelsize/2.0); direction = direction + _right*(pixelpos.x*_pixelsize) - _upvec*(pixelpos.y*_pixelsize); return direction; } |
For every pixel calculate corresponding ray. There are 2 cases:
pixel2 create_primary_rays( PixelShaderInput IN ) |