Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Ray tracing (graphics)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Algorithm overview== [[File:Ray trace diagram.svg|right|thumb|300px|The ray-tracing algorithm builds an image by extending rays into a scene and bouncing them off surfaces and towards sources of light to approximate the color value of pixels.]] [[File:Ray Tracing Illustration First Bounce.png|left|thumb|300px|Illustration of the ray-tracing algorithm for one pixel (up to the first bounce)]] Optical ray tracing describes a method for producing visual images constructed in [[3-D computer graphics]] environments, with more photorealism than either [[ray casting]] or [[scanline rendering]] techniques. It works by tracing a path from an imaginary eye through each [[pixel]] in a virtual screen, and calculating the color of the object visible through it. Scenes in ray tracing are described mathematically by a programmer or by a visual artist (normally using intermediary tools). Scenes may also incorporate data from images and models captured by means such as digital photography. Typically, each ray must be tested for [[intersection (Euclidean geometry)|intersection]] with some subset of all the objects in the scene. Once the nearest object has been identified, the algorithm will estimate the incoming [[Computer graphics lighting|light]] at the point of intersection, examine the material properties of the object, and combine this information to calculate the final color of the pixel. Certain illumination algorithms and reflective or translucent materials may require more rays to be re-cast into the scene. It may at first seem counterintuitive or "backward" to send rays ''away'' from the camera, rather than ''into'' it (as actual light does in reality), but doing so is many orders of magnitude more efficient. Since the overwhelming majority of light rays from a given light source do not make it directly into the viewer's eye, a "forward" simulation could potentially waste a tremendous amount of computation on light paths that are never recorded. Therefore, the shortcut taken in ray tracing is to presuppose that a given ray intersects the view frame. After either a maximum number of reflections or a ray traveling a certain distance without intersection, the ray ceases to travel and the pixel's value is updated. {{Clear}} === Calculate rays for rectangular viewport === On input we have (in calculation we use vector [[Euclidean vector#Length|normalization]] and [[cross product]]): * <math>E \in \mathbb{R^3}</math> eye position * <math>T \in \mathbb{R^3}</math> target position * <math>\theta \in [0,\pi] </math> [[field of view]] - for humans, we can assume <math>\approx \pi/2 \text{ rad}= 90^\circ</math> * <math>m,k \in \mathbb{N}</math> numbers of square pixels on viewport vertical and horizontal direction * <math>i,j \in \mathbb{N}, 1\leq i\leq k \land 1\leq j\leq m </math> numbers of actual pixel * <math>\vec v \in \mathbb{R^3}</math> vertical vector which indicates where is up and down, usually <math>\vec v = [0,1,0]</math> - [[:simple:Pitch, yaw, and roll|roll]] component which determine viewport rotation around point C (where the axis of rotation is the ET section) [[File:RaysViewportSchema.png|708px|Viewport schema with pixels, eye E and target T, viewport center C]] The idea is to find the position of each viewport pixel center <math>P_{ij}</math> which allows us to find the line going from eye <math>E</math> through that pixel and finally get the ray described by point <math>E</math> and vector <math>\vec R_{ij} = P_{ij} -E </math> (or its normalisation <math>\vec r_{ij}</math>). First we need to find the coordinates of the bottom left viewport pixel <math>P_{1m}</math> and find the next pixel by making a shift along directions parallel to viewport (vectors <math>\vec b_n</math> , <math>\vec v_n</math>) multiplied by the size of the pixel. Below we introduce formulas which include distance <math>d</math> between the eye and the viewport. However, this value will be reduced during ray normalization <math>\vec r_{ij}</math> (so you might as well accept that <math>d=1</math> and remove it from calculations). Pre-calculations: let's find and normalise vector <math>\vec t</math> and vectors <math>\vec b, \vec v</math> which are parallel to the viewport (all depicted on above picture) :<math> \vec t = T-E, \qquad \vec b = \vec t\times \vec v </math> :<math> \vec t_n = \frac{\vec t}{||\vec t||}, \qquad \vec b_n = \frac{\vec b}{||\vec b||}, \qquad \vec v_n = \vec t_n\times \vec b_n </math> note that viewport center <math>C=E+\vec t_nd</math>, next we calculate viewport sizes <math>h_x, h_y</math> divided by 2 including inverse [[aspect ratio]] <math>\frac{m-1}{k-1}</math> :<math> g_x=\frac{h_x}{2} =d \tan \frac{\theta}{2}, \qquad g_y =\frac{h_y}{2} = g_x \frac{m-1}{k-1} </math> and then we calculate next-pixel shifting vectors <math>q_x, q_y</math> along directions parallel to viewport (<math>\vec b,\vec v</math>), and left bottom pixel center <math>p_{1m}</math> :<math> \vec q_x = \frac{2g_x}{k-1}\vec b_n, \qquad \vec q_y = \frac{2g_y}{m-1}\vec v_n, \qquad \vec p_{1m} = \vec t_n d - g_x\vec b_n - g_y\vec v_n </math> Calculations: note <math>P_{ij} = E + \vec p_{ij}</math> and ray <math>\vec R_{ij} = P_{ij} -E = \vec p_{ij}</math> so :<math> \vec p_{ij} = \vec p_{1m} + \vec q_x(i-1) + \vec q_y(j-1) </math> :<math> \vec r_{ij} = \frac{\vec R_{ij}}{||\vec R_{ij}||} = \frac{\vec p_{ij}}{||\vec p_{ij}||} </math>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Ray tracing (graphics)
(section)
Add topic