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!
=== 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