Settings

Theme

Tell HN: Essence of Rendering

1 points by EternalCarnage 2 years ago · 0 comments · 3 min read


Dedicated to those who also care, not only the subset of thread viewers from https://news.ycombinator.com/item?id=36664044#36669331

From my original comment to laurieg, titled "Getting the signal from the noise - A demonstration attempt": https://news.ycombinator.com/item?id=36664044#36669331

---

Rendering:

How to turn a virtual 3D scene into a (2D) image? Answer: (affine and perspective) geometry, usually in the form of vectors and points and some physics. (Matrices, multivectors, are structures for convenience.)

The core concepts you need are:

1. Perspective projection (perspective geometry):

X* = H * (X / Z)

Y* = H * (Y / Z)

2. Coordinate mapping (affine geometry):

MapRange(Value, Source, Target) := Value' = Scale * (Value - Source.Min) + Target.Min

Scale := (Target.Max - Target.Min) / (Source.Max - Source.Min)

Where Source is your "old" 2D coordinate system interval (e.g., [-1; 1] x [-1; 1]) and Target is your new coordinate system interval (e.g., [0; Width] x [0; Height]).

Although, we usually have to deal with flipped y-coordinates, so:

[0; Width] x [Height; 0] or for rasterization:

X' = MapRange(X, Source=(-1, 1), Target=(0, Width))

Y' = MapRange(X, Source=(-1, 1), Target=(Height, 0))

... and coordinate mapping for ray tracing:

X' = MapRange(X, Source=(0, Width), Target=(-1, 1))

Y' = MapRange(Y, Source=(Height, 0), Target=(-1, 1))

3. Containment (affine; rasterization):

w := (1 - u - v), A, B, C from R2.

OP = uAB + vAC + OA <=> AP = uAB + vAC <=> OP = uOB + vOC + (1 - u - v)OA <=> P = uB + vC + (1 - u - v)A = uB + vC + wA

If you solve AP = uAB + vAC for u and v via Cramer's rule or by hand, you may get:

A := Det(AB, AC)

u := Det(AB, AP) / A

v := Det(BC, BP) / A

w := 1 - u - v = Det(CA, CP) / A

P is inside triangle ABC, if u, v, w >= 0 and u + v + w = 1.

4. Intersection + Containment (affine):

<.,.> - the dot product.

t = <PlanePoint - RayOrigin, PlaneNormal> / <RayDirection, PlaneNormal>

If t > 0, the line or ray intersects with the triangle's plane.

X = Ray(t) = RayOrigin + t RayDirection

Now, you can reuse the 2D point containment check (3), to see whether the ray intersects also the triangle (lying on that plane).

---

Filtering the "noise" (overhead/information overload), getting to the "gist", for me, is not easy, but you can get there, if you care enough.

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection