Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement...

35
NON-EUCLIDEAN GEOMETRY RENDERING Diana Algma M.C. Escher – “Relativity”

Transcript of Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement...

Page 1: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

NON-EUCLIDEAN GEOMETRY RENDERINGDiana Algma

M.C. Escher –“Relativity”

Page 2: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

I WILL TALK ABOUT…

• MATH

• What is Euclidean Geometry?

• What is Non-Euclidean Geometry?

• Elliptic

• Hyperbolic

• COMPUTER GRAPHICS

• Hyperbolic planes

• Ray tracing – space warping

• Portals

M.C. Escher –“Balcony”

Page 3: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

EUCLIDEAN GEOMETRY

• The “normal” geometry

• Euclid’s 5 postulates (“The Elements” ~300 BC) (by Sir Thomas Heath):

1. "To draw a straight line from any point to any point."

2. "To produce [extend] a finite straight line continuously in a straight line."

3. "To describe a circle with any center and distance [radius]."

4. "That all right angles are equal to one another."

5. The parallel postulate: "That, if a straight line falling on two straight lines make the interior angles on the same side less than two right angles, the two straight lines, if produced indefinitely, meet on that side on which are the angles less than the two right angles."

Page 4: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

EUCLIDEAN GEOMETRY

• The “normal” geometry

• Euclid’s 5 postulates (“The Elements” ~300 BC) (by Sir Thomas Heath):

1. "To draw a straight line from any point to any point."

2. "To produce [extend] a finite straight line continuously in a straight line."

3. "To describe a circle with any center and distance [radius]."

4. "That all right angles are equal to one another."

5. The parallel postulate (Playfair): "In a plane, through a point not on a given straight line, at most one line can be drawn that never meets the given line."

Page 5: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

EUCLIDEAN GEOMETRY

• The “normal” geometry

• Euclid’s 5 postulates (“The Elements” ~300 BC) (by Sir Thomas Heath):

1. "To draw a straight line from any point to any point."

2. "To produce [extend] a finite straight line continuously in a straight line."

3. "To describe a circle with any center and distance [radius]."

4. "That all right angles are equal to one another."

5. The parallel postulate (Playfair): "In a plane, through a point not on a given straight line, one and only one line can be drawn that never meets the given line."

Page 6: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

NON-EUCLIDEAN GEOMETRY

• First ones discovered in early 19th century

• Hyperbolic & Elliptic (& Spherical)

“A hyperbolic "line" is an undefined term describing an abstract concept that resembles the concept of a Euclidean line except for its parallelism properties.” – Marvin Jay Greenberg

Page 9: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

ELLIPTIC GEOMETRY

• Simplest model is a sphere

• Line is a “great circle”

• “great circle” - divides the sphere in half

• Points opposite each other (antipodal points) are identified

• Elliptic Spherical

• Is it really Non-Euclidean?

Page 10: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

SPHERICAL GEOMETRY

• Simplest model is a sphere

• Line is a “great circle”

• “great circle” - divides the sphere in half

• Points opposite each other (antipodal points) are identified

• Elliptic Spherical

• Is it really Non-Euclidean?

Page 11: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

HYPERBOLIC GEOMETRY

Lines through a given point and parallel to a given line, illustrated in the Poincaré disk model

Poincaré disk model preserves angles but curves lines

Beltrami-Klein model has straight lines but the angles are not preserved

Triangles? Rectangles?

Page 12: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

UNIFORM TILINGS IN HYPERBOLIC PLANE

• Schläfli symbol: {p,q} (2D)p – nr of sidesq – nr of polygons around a vertex

{7,3} (regular)

M.C. Escher –“Circle Limit III”

Page 13: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

APEIROGONS IN HYPERBOLIC PLANE

• Apeirogon – generalized polygon with a countably infinite number of sides

• Horocycle – “circle of infinite radius”

{∞,3} (regular)

More on this

Page 14: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

COORDINATE SYSTEMS FOR HYPERBOLIC PLANE

• Polar coordinate system

• (r,) = (distance from reference point (the pole), angle from reference direction)

• 𝑑𝑖𝑠𝑡((𝑟1, 1), (𝑟2, 2)) = 𝑎𝑟𝑐𝑜𝑠ℎ (cosh 𝑟1 cosh 𝑟2 – sinh 𝑟1 sinh 𝑟2 cos(2 − 1))

• arcosh, cosh, sinh – hyperbolic functions

• Straight line: = 0 /2 ortanh r = tanh r0 sec( - 0)where (r0, 0) is the nearest point on the line to the pole

Page 15: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

COORDINATE SYSTEMS FOR HYPERBOLIC PLANE

• Poincaré coordinates

• Center is the origin, x-axis (-1,0) – (1,0), Euclidean coordinates

• Hyperbolic distance between p and q:

𝑑 𝑝, 𝑞 = ln𝑎𝑞 𝑝𝑏

𝑎𝑝 𝑞𝑏|ab| = Euclidean length of the line segment connecting a and b in the modelln = natural logarithmp and q are inside the diska are b are the ideal points where the line through p and q intersects the boundary

Page 16: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

MÖBIUS TRANSFORMATION

• Rational function

• 𝑓 𝑧 =𝑎𝑧+𝑏

𝑐𝑧+𝑑

• z is a complex variable

• a, b, c, d are complex numbers, 𝑎𝑑 − 𝑏𝑐 ≠ 0

• Can be obtained by:

1. Stereographic projection from the plane to the sphere

2. Rotating and moving the sphere

3. Stereographic projection from the sphere to the plane

Page 18: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

NON-EUCLIDEAN SPACE

• 3D - 8 models:• Euclidean, elliptic, hyperbolic

• Mixed geometries:• Partially Euclidean and partially elliptic or hyperbolic

• Twisted versions of the mixed geometries

• Anisotropic:• Every direction behaves differently

• Hyperbolic space:• Hyperbolic geometry in more than 2 dimensions

• Hyperbolic n-space: Hn

• H2 is hyperbolic plane

• Hyperbolic VR

Page 19: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RAY TRACING

Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one.

• Real-time non-Euclidean ray tracer:https://youtu.be/YvU-srHhQxw

• “No! Euclid!” GPU Ray Tracer:https://youtu.be/tl40xidKF-4?t=4m7s (github)

• Ray Tracing in Curved Space Time:http://locklessinc.com/articles/raytracing/

Page 20: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

SPACE WARPING

scripthelpers.cpp

Page 21: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

SPACE WARPING? - NAH

• https://www.youtube.com/watch?v=K7dKLUIHcrU

• More stuff in Minecraft:

• https://www.youtube.com/watch?v=B4xm26eA3dI

• https://www.youtube.com/watch?v=3xknsAakZnE

Page 23: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

PORTALS

• Connects two locations

• Physically

• When going into a portal, you get out of another.

• Visually

• When looking at the portal, it looks like the space in the portal is the space behind (or in front of) another portal.

• When done correctly it should look like a doorway or a continuous room.

Page 24: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

PORTALS

• Some problems to address:

• Showing

• the right angle through a portal when viewing it

• the scene through the portal with the right scaling

• just the right part of the scene through a portal

• Smooth transition when moving through a portal

• If your player has a character, it could also be seen through a portal

• Rendering portals recursively

• Objects that are “in” a portal – partially on one side and partially on another

• Crushed between two portals

Page 25: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

PORTALS HOW-TO

Rendering recursive portals with OpenGL (code)

• Render the scene twice:

• First the scene outside the portal’s frame

• Then the scene inside the portal’s frame

• The scene inside the portal’s frame:

• From the perspective of a virtual camera

• Take the transformation matrix from camera to the source portal

• Apply the inverse of that to the destination portal to get the virtual camera’s position and angle

• BUT: There can’t be an object between the destination portal and the virtual camera!

Page 26: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

PORTALS HOW-TO

• BUT: There can’t be an object between the destination portal and the virtual camera!

-> SOLUTION:

• Change the virtual camera’s view matrix so that its near plane starts at the plane of the destination portal – not always easy

• To make it possible, use oblique view frustum near-plane clipping (example)

Page 27: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS

1st method – rendering to a texture:

Using Framebuffer Objects (FBO)

1. Create FBO, set it as the current render target

2. Generate virtual camera’s view matrix

3. Render the scene from the viewpoint to the virtual camera (goes to FBO)

4. Render the scene normally from the regular camera and apply the FBO texture to the portal’s frame

• Problem: texture resolution

Page 28: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS

2nd method – stencil buffer:

1. Disable drawing to color and depth buffer, enable drawing to stencil buffer

2. Set stencil operation to GL_INCR on fail (stencil value will be incremented when the stencil test fails)

3. Set stencil function to GL_NEVER, so stencil test always fails on every pixel drawn

4. Draw the porta’s frame

5. Generate virtual camera’s view matrix

6. Disable drawing to stencil buffer, enable color and depth buffer

Page 29: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS

2nd method – stencil buffer, continued:

7. Set stencil function to GL_GEQUAL with reference value 1 (draws only where stencil value is 1)

8. Draw the scene using virtual camera (draws only inside the portal frame)

9. Disable stencil test, disable color buffer and enable depth buffer

10. Clear the depth buffer

11. Draw portal frame again with the cleared depth buffer

12. Enable color buffer

13. Draw the whole scene with the regular camera

Page 30: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS

To draw many portals (different pairs, not recursive):

• Steps 1-8 in a loop

Recursion:

• Increase stencil value for every depth level

• Start filling the stencil buffer recursively with portal frames on the current level

• Then increase stencil value by rendering the virtual portal(s) of next level

• When reaching the end start drawing the virtual scenes from the bottom up

But there’s a catch!

Page 31: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS

Overlapping portals!

“To obscure the part of the portal on level two, we have to enable the stencil test for the part where we render our portal to the stencil test.”

Page 32: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

RENDERING PORTALS -PERFORMANCE

• When rendering recursively

• Binary space partitioning (BSP)

• Or use stencil buffer for the first few levels of recursion and render to texture for the deeper levels

Code for recursive portals

Page 33: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

REFERENCES

• http://www.mcescher.com/gallery/

• The thirteen books of Euclid’s Elements translated by Thomas Heath (1908)

• “Euclidean and Non-Euclidean Geometries: Development and History” by Marvin Jay Greenberg

• http://pmrb.net/blog/tag/non-euclidean-geometry/

• Our Portals project in the making

• Hyperbolic maze (w/ code)

• HyperRogue

• Interactive Poincaré disk model

• Hyperbolic games (w/ code)

• Crocheting hyperbolic planes

Page 34: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

REFERENCES VOL 2

• Hyperbolic VR

• Real-time non-Euclidean ray tracer

• “No! Euclid!” GPU Ray Tracer (w/ code)

• Ray Tracing in Curved Space Time

• Minecraft:

• https://www.youtube.com/watch?v=K7dKLUIHcrU

• https://www.youtube.com/watch?v=B4xm26eA3dI

• https://www.youtube.com/watch?v=3xknsAakZnE

• Crushed between two portals

• Rendering recursive portals with OpenGL (code)

Page 35: Non-Euclidean geometry rendering...Non-Euclidean geometry arises when either the metric requirement is relaxed, or the parallel postulate is replaced with an alternative one. •Real-time

MORE COOL STUFF

• http://www.antichamber-game.com/

• http://www.monumentvalleygame.com/

• http://www.thinkwithportals.com/

• Non-Euclidean Level Design (Portal 2 Version)