Results 1 to 5 of 5

Thread: how to generate ray form pixel coords

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    how to generate ray form pixel coords

    In the ray tracing,it said that generate a ray of per pixel form pixel screen coord.
    but how to compute.I cann`t found anywhere introduction for this
    thanks!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: how to generate ray form pixel coords

    A ray , as far as i know, is defined as

    r = r0 + s*t

    where r0 is a origin vector and t a vector to the destination. I think you can use your camera position as r0 and a destination vector. So you can build a ray r, from r0 to t.

    r0 points to the "Point" in space where your ray starts. and t is a point along your ray.

    greetings,
    lobbel

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    Re: how to generate ray form pixel coords

    thanks,i know that and my means is how determinate the ray dir("s" in up equation of you wrote) through pixel screen coord.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: how to generate ray form pixel coords

    Hi, s is just a point in space. For instance, if you want to send a
    ray from your view along your viewing direction you can say that
    r0 is the position of your camera and s the point where your camera looks at. If you use glLookAt you can easy imagine.
    glLookAt uses 4 vectors (?). The camera position and 3 vectors
    that describe the camera's alignment. These are the up vector,
    the direction vector and the right vector. The direction vector is build from camera position and the point where you want to look at.
    In this case we can say it's also a ray that goes from your camera position to the point where you want to look at.

    For example you camera is at (0,5,0) and your point you want to look at is (2,0,2) then your view vector (resp. ray) is
    (2,0,2) - (0,5,0) = (2,-5,2)

    Btw. s is just a scalar. it can be 1.
    greetings,
    lobbel

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    Re: how to generate ray form pixel coords

    In the chapater <<Implementing Ray Tracing on GPU>>
    it calculate the primary ray form pixel coord as this:
    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;
    }
    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"
    float psize; // Size of a pixel in texture coordinates
    vec3 camera_pos; // camera position

    I not determinate what means of "_right" and "_tl",such as "binormal" and "tangent" in the tangent space?
    And why compute as this?
    My confused is there`s no pixel position information in your method for ray

Similar Threads

  1. Simple form with pixel manipulation
    By Mohsen Jamali in forum OpenGL: Linux
    Replies: 5
    Last Post: 02-18-2012, 12:46 PM
  2. polygon coords -> pixel coords
    By Bruno in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 05-30-2005, 07:28 PM
  3. Pixel Coords in Pixel Shader
    By Sandruzzo in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 07-08-2004, 06:45 AM
  4. Heightmaps -- generate from x,y,z, coords...
    By cutting_crew in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-06-2003, 01:02 PM
  5. Replies: 4
    Last Post: 07-09-2003, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean