Sphere Raytracing 1
|
Date Added: |
May 24, 2012 07:01 AM |
Publisher's Description: |
Ignoring comment lines, the first line of the definition is just a name for the definition. The second line lists the dimensions of the image (400 x 160) and the number of spheres (6). Then for each sphere, a line follows listing the radius, location (x, y, z coordinates), and color. Each color may be specified either by RGB values (red, green, blue) 0-255 (ex. 200 180 120), a standard HTML color name (ex. lightgreen), or a hex string (ex. #0055aa). An x coordinate of 0 indicates the left edge of the image. A y coordinate of 0 indicates the top edge of the image. A z coordinate of 0 indicates that a sphere is very close to you. A z coordinate of greater than 0 means that a sphere is farther way. So, if one sphere has z coordinate of 0 and another has a z coordinate of 100, then the first sphere will be in front of the second, and possibly block the second if it is bigger. The last line of the definition is the location (x, y, z) of the lightsource. A location of 100, 100, -100 means that the light source will shine at a 45 degree angle from the lower left hand part of each sphere.
To use the program, click on the "Start Spheres" button. A window will pop up. To start, copy the sample image definition from above into the text area in this window. The hit the "Draw image" button. Another window will pop up, and after a few seconds you should see the same image as displayed above. Now you can experiment by making up your own image definitions.
To have the program randomly generate an image definition for you, click on the "Generate random sphere definition" button. This will fill the text area with a new image definition (and erase anything was was in the text area before). Then you can click "Draw image" to see what this definition looks like.
You can control the random definition generation to some degree by specifying basic parameters such as the size of the image, the number of spheres, and which edges of the image the spheres are allowed to cross.
About saving images: From the display window for an image you can hit the "Save As" button to save the generated image. Images are saved in PNG format. You may get a SecurityException and not be able to save your image if you did not accept my security certificate when the program first loaded.
Basic Sphere Raytracing Algorithm (for those interested)
Suppose you have the following defined:
A set of one or mores spheres, each having a radius, and a location in 3D coordinates x, y, z.
A lightsource 3D vector having x, y, z components.
Here is some Java-like code to calculate the light intensity value (8-bit grayscale) at a particular 2D point of the image you want to generate to represent the 3D data: (This assumes the "color" of each sphere is pure white, or 255 in 8-bit grayscale.) (Extending this to color simply requires one to assign each sphere an RGB color instead of pure white, and do calcuations for R, G, B color intensity values.)
|
Screenshot: |
|
Documentation: |
http://www.mindtrace.net/spheres/spheres.html |
Last Download: |
Apr 19, 2024 04:08 PM
|
Downloads: |
284 |
OS: |
Windows |
Rating: |
|
|
|