Re: Implementing a simple raytracer (The camera)



crooks_dwayne@xxxxxxxxx wrote:
> Hey guys i'm trying to implement a ray tracing program and i need help
> with my camera implementation. Actually its a ray caster since i really
> want to start simple.
>
> Here's the camera model: (coordinates is world coordinates)
> 1. center of projection (on the +ve z-axis)
> 2. view plane window (x-y plane)
> 3. view plane normal (along the -ve z-axis)
>
> The world coordinates is a right handed system and the view coordinates
> a left handed system. I suspect to convert from world coords to view
> coords i need to reverse the z-coords of the objects in the scene.
> (Correct me if i'm wrong). My problem is how to determine the pixels on
> the view plane window that i need to shoot my rays through.

No need to mess with view coordinates at all. In order to have viewing
parameters fully defined, you'll have to specify a window in x-y plane
(for example (x0,y0) is lower left corner point, (x1, y1) is upper
right corner) and image resolution WxH (W is width, H is height in
pixels). Then you could imagine a mesh in from (x0,y0) to (x1,y1) in
x-y plane, with WxH cells - for simplest ray casting, you could shoot
one ray trough the center of each cell and color determined by this ray
will be assigned to corresponding pixel. In order to determine center
(x,y,z) of cell corresponding to (i,j) pixel (note that here i is index
along image x-axis and j is index along y-axis) you could use following
snippet of C code:
float delta_x = (x1 - x0) / W;
float delta_y = (y1 - y0) / H;
float x = x0 + (i + 0.5) * delta_x;
float y = y0 + (j + 0.5) * delta_y;
float z = 0;
Of course, you could further optimize above code to calculate x and y
incrementally in loops and thus avoid multiplication.


> Implementation details (JAVA) or psuedocode would be of great help.
>
> Is the view plane window implemented as an array Color[][] vpw = new
> Color[height][width]?

Yes, it could be.


> Should the algo be like this?
> for each i,j do
> x,y = convert i,j to pixel coords
> compute ray r
> vpw[i][j] = raytrace(r)

Exactly. Note however that tracing each ray trough center of
corresponding cell in x-y plane will have bad aliasing effects, but
there are many techniques with more complicated ray direction selection
that will result in better looking images. Still, for the first
iteration, above will do fine.


> How do I set the resolution of the image?

If you are reading scene description, maybe corresponding file format
encompasses image resolution. Otherwise, it could be command line
argument, or you could simply hard code some default image resolution.


> What is the simplest output file format I can output my image too?

If you are on UNIX, probably PPM format will do. It's dead simple,
format starts with line with string "P6", then in next line you should
write width and height of your image in ASCII and separated by a space,
then in next line maximum color value (probably 255 if you are going to
convert your color component values to integers in [0,255] range) again
in ASCII and then starting from next line pixel values in binary from
upper row of image and in each row from left to right. If you decide
for [0,255] range, then you'll have to write 3 bytes for each pixel,
first red component, then green and blue. In order to convert to other
formats, number of small programs exist, for example ppmtopng for PNG,
ppmtojpeg for JPEG etc.


> If you have answers to any of these questions please help me?
>
> Thanx in advance :>

Hope above helps,
Alex

.



Relevant Pages

  • Dynamic Array
    ... a simple ray trace program. ... For each voxel of the object (i.e. ... that voxel for that pixel. ... with any pixels while some may interact with a few pixels. ...
    (comp.soft-sys.matlab)
  • Re: contour shading
    ... Determine the level at the current pixel, ... Locate two distance measures to the level below, ... to use a 2d pixel traversal algorithm which tested a "ray". ... If the ray hit a pixel with the desired level, ...
    (comp.graphics.algorithms)
  • Re: Raytracing HDR images
    ... I shoot multiple rays per pixel and average the results, but if a bright HDR sample forms part of the pixel, the whole pixel gets clamped to 1.0 when I form my output image, which leaves bright objects with jagged outlines. ... You need to low-pass filter the texture w.r.t. the current ray. ...
    (comp.graphics.algorithms)
  • Re: Raytracing HDR images
    ... multiple rays per pixel and average the results, but if a bright HDR ... texture w.r.t. the current ray. ...
    (comp.graphics.algorithms)
  • Re: To format or not to format??
    ... I personally format maybe once a year....maybe longer but the reason I do is because I install ad uninstall alot of stuff. ... ever seen a "clogged" registry. ... Ray again--> see above reply, ... You're applying plumbing terms to a database, and questioning my education? ...
    (microsoft.public.windowsxp.help_and_support)

Loading