Lesson 13 Parallax Occlusion Mapping PV227 – GPU Rendering Jiˇrí Chmelík, Jan ˇCejka Fakulta informatiky Masarykovy univerzity 12. 12. 2016 PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 1 / 15 Parallax Occlusion Mapping Nothing Normal mapping Parallax Occlusion Mapping PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 2 / 15 Basic principle Basic principle PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 3 / 15 Parallax direction We work in the tangent space (ts) (on the surface of the object) parallax dir (ts) = ray dir.xy (ts) PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 4 / 15 Maximal parallax ray (ts) depth scale = ray dir (ts) −ray dir.z (ts) ray (ws) depth scale = ray dir (ws) −ray dir.z (ts) parallax (ts) = ray.xy (ts) PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 5 / 15 Texture space Our space with texture coordinates is a little different from the tangent space Directions of tangents and bitangents are the same as directions of s and t coordinates The sizes are different parallax (texs) = ts_to_texs · parallax (ts) PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 6 / 15 Sampling Sample the height texture to find the first intersectoion PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 7 / 15 Algorithm for sample i do percentage ← i/#samples sample_tex_coord ← tex_coord0 + parallax_texs · percentage tex_depth ← one_minus_sample(height_tex, sample_tex_coord) ray_depth ← percentage if ray_depth > tex_depth then break end end Use last percentage to compute the final texture coordinate and position. PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 8 / 15 Task: Implement POM Task 1: Implement this algorithm PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 9 / 15 Task: Improve POM Task 2: Compute the intersection more precisely Result: Better result with less samples PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 10 / 15 Interaction with other objects PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 11 / 15 Task: Improve interaction with other objects Task 3: Adjust fragment’s depth Transform offseted position into clip space (transform in with view and projection matrices) Transform it into normalized device coordinates (divide it with its w) Transform it from [−1, 1] to [0, 1] Store its z into gl_FragDepth PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 12 / 15 Task: Improve interaction with other objects Without depth adjustment With depth adjustment PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 13 / 15 Task: Self-shadowing Task 4: Implement self-shadowing Cast another ray from the offseted position to the light Check whether there is an obstacle in the height map PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 14 / 15 Task: Self-shadowing Without self-shadows With self-shadows PV227 – GPU Rendering (FI MUNI) Lesson 13 – POM 12. 12. 2016 15 / 15