Nikolaus Mayer
Sommercampus 2019
Technische Fakultät
Universität Freiburg
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
P3 WIDTH HEIGHT MAXIMUM
P3 512 512 255
P3
means "ASCII-PPM" → human readable \Ü/
P3 512 512 255 255 0 0 255 0 0 255 0 0 [...]
P6 512 512 255 ÿ^@^@ÿ^@^@ÿ^@^@[...]
(binary PPM) std::ofstream outfile("img.ppm");
outfile << "P3 512 512 255";
for(int y = 0; y < 512; ++y) { /// Rows
for(int x = 0; x < 512; ++x) { /// Columns
outfile << " " << 255
<< " " << 0
<< " " << 0;
}
}
<< " 255 0 0"
instead) $ du --bytes img.ppm
P3 512 512 255
" = 14 bytes header 255 0 0
" = 8 bytes per pixel (ASCII: 1 byte/character) $ head -c 100 img.ppm
P3 512 512 255 255 0 0 255 0 0 255 0 0 ...
for(int y = 0; y < 512; ++y) { /// Rows
for(int x = 0; x < 512; ++x) { /// Columns
...
for(int y = 256; y >= -255; --y) { /// Rows
for(int x = -255; x <= 256; ++x) { /// Columns
...
...(x - 0.5)...
...(y - 0.5)...
...
Vector::operator+
, Vector::operator*
[color] * std::pow(1-ray_direction.y,2)
Y = 0 = camera.y + distance · ray.y
distance := -camera.y / ray.y
distance := -camera.y / ray.y
X := camera.x + distance · ray.x
Z := camera.z + distance · ray.z
std::abs
on negative numbers! (int)std::abs(std::floor(...))%2
ray.y < 0
SymPy
can do symbolic math
from sympy import var, solve
pox,poy,poz,ux,uy,uz,vx,vy,vz,ox,oy,oz,rx,ry,rz,u,v,d =
var('pox poy poz ux uy uz vx vy vz ox oy oz rx ry rz u v d')
E1 = pox + u*ux + v*vx - ox - d*rx
E2 = poy + u*uy + v*vy - oy - d*ry
E3 = poz + u*uz + v*vz - oz - d*rz
solutions = solve([E1,E2,E3],[u,v,d])
print(solutions)
{u: [...], v: [...], d: [...]}
not pretty but correct¯\_(ツ)_/¯
Object
class for traceable objects Object
does its own intersection test std::vector<Object*>
max_hit_bounces
limits visibility
![]() |
![]() |
![]() |
![]() |
ambient | + diffuse | + specular | = Phong |
![]() |
![]() |
![]() |
![]() |
ambient | + diffuse | + specular | = Phong |
![]() |
![]() |
![]() |
![]() |
ambient | + diffuse | + specular | = Phong |
![]() |
![]() |
![]() |
![]() |
ambient | + diffuse | + specular | = Phong |
![]() |
![]() |
![]() |
![]() |
ambient | + diffuse | + specular | = Phong |
RIGHT
/UP
vectors texture.ppm
found in this repository)
$ vim texture.ppm
P6
600 400
255
f± jÕËyÙÕ<99>äßI<93><8e> [...]
P6
binary PPM (1 byte per color channel, 3 bytes per pixel) 600 400
→ resolution 600x400 P6 600 400 255
" → 15 bytes $ du -b texture.ppm
: 720016 bytes! $ xxd texture.ppm | head -n3
0000000: 5036 0a36 3030 2034 3030 0a32 3535 0a66 P6.600 400.255.f
0000010: b1a0 6ad5 cb79 d9d5 99e4 df49 938e 75d7 ..j..y.....I..u.
0000020: d36d d2cc 85db d697 e2dd 6dd4 cc55 c9bf .m........m..U..
0a
is a newline 20
is a whitespace $ xxd texture.ppm | tail -n3
00afc60: bfad 20cc bb11 b1a0 03b3 9d02 a991 0452 .. ............R
00afc70: 430a 0a09 212e 2818 9c88 16af a241 cac2 C...!.(......A..
00afc80: 3cd3 cb33 d3cd 3fd5 d016 d1ca 30d4 ce0a <..3..?.....0...
get_ground_color(..)
:
static unsigned char* texture_data{nullptr};
const int tex_w{600};
const int tex_h{400};
if (not texture_data) {
std::ifstream texture("texture.ppm");
texture_data = new unsigned char[tex_w*tex_h*3];
texture.read(reinterpret_cast(texture_data), 15); /* dummy read */
texture.read(reinterpret_cast(texture_data), tex_w*tex_h*3);
}
![]() |
![]() |
![]() |
![]() |
diffuse color | specularity | normal | roughness |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
|