# ANN: Examples for Physically Based Rendering

**URL:** https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981
**Category:** Announcements
**Created:** [October 26, 2019, 5:39am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981 "2019-10-26T05:39:29Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 26, 2019, 5:39am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/1 "2019-10-26T05:39:30Z")

</div>

After reading this impressive article: [Introducing Physically Based Rendering with VTK](https://blog.kitware.com/vtk-pbr/). I created a couple of examples (both in C++ and Python) that (I hope) capture most of what has been written in the articles.

In the examples you can select different surfaces to visualise: Boy’s Surface (default), Mobius Strip, Torus, Sphere and Cube. The non-orientable surfaces are interesting e.g. in the case of Boy’s Surface on the left side you see reflections of the sky even though the surface is angled to the ground at that point.

You can also select different skyboxes, the images are found in `VTKExamples/Testing/Data/skyboxes/`. Try different skyboxes! For texturing the images are found in `VTKExamples/Testing/Data/`

Here are the C++ examples, links to the corresponding Python examples can be found on these pages:

1. [Skybox\_PBR](https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/Skybox_PBR/)  
 ![TestSkybox_PBR](https://discourse.vtk.org/uploads/default/original/2X/3/3e05cb31e8cc56abd0ddc7b5b002ecd52ac49969.jpeg)  
These sliders set metallicity and roughness of the object:

2. [PhysicallyBasedRendering](https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/PhysicallyBasedRendering/) ![TestPhysicallyBasedRendering](https://discourse.vtk.org/uploads/default/original/2X/6/6339ca5fd66ffdb76234ed927d20dcc2c87b5d47.jpeg)

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jhlegarreta/32/27_2.png) [@jhlegarreta](https://discourse.vtk.org/u/jhlegarreta)
#### Post date: [October 26, 2019, 12:24pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/2 "2019-10-26T12:24:35Z")

</div>

Impressive work, impressive examples. Thanks for doing this @amaclean !

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [October 28, 2019, 12:50pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/3 "2019-10-28T12:50:30Z")

</div>

Awesome, thank you @amaclean !  
I would be very happy to have your feedback regarding PBR. Did you have difficulty using it? Is the documentation sufficient? Is everything clear in the blog article?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 28, 2019, 9:32pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/4 "2019-10-28T21:32:37Z")

</div>

@Michael, in relation to the first example, the documentation was pretty clear and straightforward. I must admit, I was pretty pleased when it all worked and the results looked so beautiful.

In relation to the texturing example I had to feel my way a bit, I searched the VTK repository to find the textures used in the picture in the article. I was also unfamiliar with the terminology. My biggest problem was finding an emissive texture so I used Photoshop to modify the VTK logo and convert it to a black background. You will see I kept the bars around the letters as they gave me an indication of the lighting colour when setting the emissive factor.

With respect to the sources used, it was interesting to do uv-texturing on the parametric surfaces. Once I figured this out, the texturing of these surfaces was easy! For debugging texturing I found your files: tex\_debug.jpg and vtk\_Base\_Color.png useful.

I learned a lot from your well written article.

One other big bonus from the work you guys have done is that it was really simple to convert the C++ code to Python as you can see in the examples.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 29, 2019, 11:45pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/5 "2019-10-29T23:45:35Z")

</div>

@Michael it goes without saying that if the examples can be enhanced/improved please submit merge requests.

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [October 30, 2019, 8:25am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/6 "2019-10-30T08:25:37Z")

</div>

Thank you for the feedback and I will definitely have a look at your examples code when I find the time.

---

<div class="post-metadata">

### Author: ![ben](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://discourse.vtk.org/u/ben)
#### Post date: [May 26, 2020, 10:48am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/7 "2020-05-26T10:48:58Z")

</div>

Thank you for this example!  
Is it possible to use data arrays to steer the PBR parameters similar to the ActiveScalars for pointsets?  
This could then be another helpful example for data that does not come with texture coordinates but has per vertex attributes.

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [May 26, 2020, 12:15pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/8 "2020-05-26T12:15:49Z")

</div>

Absolutely, you can add scalar coloring with PBR. Here is a simple wavelet isosurface having an elevation field (top dielectric, bottom metallic).

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9543504414b9995181c5c4a7fd2c86dd5379d14a.jpeg)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/292079c625f6692a0d2734c864523ef5482a42ca.jpeg)

---

<div class="post-metadata">

### Author: ![ben](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://discourse.vtk.org/u/ben)
#### Post date: [May 26, 2020, 1:06pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/9 "2020-05-26T13:06:49Z")

</div>

@Michael Thanks for the quick response. What I meant was to assign per vertex values for the metallic and roughness parameters as well. I want to avoid the textures but still have spatially varying PBR parameters.

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [May 26, 2020, 1:10pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/10 "2020-05-26T13:10:06Z")

</div>

This is something we have considered and I think this would be something very useful but we have no funding yet for this feature.

---

<div class="post-metadata">

### Author: ![ben](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://discourse.vtk.org/u/ben)
#### Post date: [May 26, 2020, 1:21pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/11 "2020-05-26T13:21:00Z")

</div>

Thanks for your answer. Do you think it is worth trying to find a workaround? (something like trying to map the data array manually to the shader inputs in the PolyDataMapper)

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [May 26, 2020, 1:26pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/12 "2020-05-26T13:26:21Z")

</div>

Yes, you can hack something easily if you have enough shader development skill.  
Send your arrays to the shader inputs and modify the fragment shader code to get interpolated value from your custom vertex attributes to set roughness/metallic. You will need to modify the vertex shader as well to transfer your attribute to the fragment shader.

---

<div class="post-metadata">

### Author: ![ben](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://discourse.vtk.org/u/ben)
#### Post date: [May 26, 2020, 4:16pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/13 "2020-05-26T16:16:46Z")

</div>

Thanks for these hints! (Still hoping to see this feature sometime in vtk 9.x 😉 )

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [August 7, 2021, 10:42pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/14 "2021-08-07T22:42:14Z")

</div>

# Update:

I have renamed the examples:

- Skybox-PBR → [PBR\_Skybox](https://kitware.github.io/vtk-examples/site/Cxx/Rendering/PBR_Skybox/)
- PhysicallyBasedRendering → [PBR\_Skybox\_Texturing](https://kitware.github.io/vtk-examples/site/Cxx/Rendering/PBR_Skybox_Texturing/)

It makes more sense logically and also for testing. Also you can now read in HDR skyboxes to produce nice hi-res images. There are some nice ones here [Poly Haven](https://polyhaven.com/all).

I hope to have an anisotropic texturing example done real soon, it wil be called … wait for it … `PBR_Skybox_Anisotropy`, thanks to @Lfx_Paul for the anisotropic textures.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 9, 2021, 10:11am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/15 "2021-08-09T10:11:37Z")

</div>

Sweet !!

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [August 10, 2021, 12:04pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/16 "2021-08-10T12:04:58Z")

</div>

Looks cool, how do you zoom-out the cubemap? In the rendering it appears zoomed-in and low resolution compared to the [original](https://polyhaven.com/a/kloppenheim_06). Colors also look a bit different.

![Screenshot from 2021-08-10 13-51-47](https://discourse.vtk.org/uploads/default/original/2X/7/7c8f2dceb8250c6d30ec1b403488c4073d150b8c.png)

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [August 10, 2021, 10:55pm UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/17 "2021-08-10T22:55:50Z")

</div>

1. You can only zoom in/out of objects that you place in the scene. The skybox is essentially at infinity.
2. That 4k image is quite blurry, this is not a VTK issue, try other ones. I also verified this using ParaView.
3. I will be updating these examples later today, introducing tone mapping into them, among other things. With tone mapping you will be able to control exposure and contrast.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [August 11, 2021, 7:14am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/18 "2021-08-11T07:14:41Z")

</div>

I have reworked the PBR examples, thanks to @Lfx_Paul for the anisttropic textures and to @Timothee_Chabat for some insightful comments.

Please look at:

- [PBR\_Skybox](https://kitware.github.io/vtk-examples/site/Cxx/Rendering/PBR_Skybox/)
- [PBR\_Skybox\_Texturing](https://kitware.github.io/vtk-examples/site/Cxx/Rendering/PBR_Skybox_Texturing/)
- [PBR\_Skybox\_Anisotropy](https://kitware.github.io/vtk-examples/site/Cxx/Rendering/PBR_Skybox_Anisotropy/)

There are also corresponding Python examples.

The major changes are:

- A hi-res skybox is now used.
- The default VTK lighting is now switched off and the objects are just illuminated by the skybox.
- You can now vary the exposure, thanks to `vtkToneMappingPass`.
- A gamma correction is now applied to the skybox.
- The vtkCameraOrientationWidget has also been added.

Enjoy a day at the beach with some “interesting” objects:

 ![TestPBR_Skybox](https://discourse.vtk.org/uploads/default/original/2X/0/087cbab08c7efb2b7516636d718068151437c66f.jpeg)

 ![TestPBR_Skybox_Texturing](https://discourse.vtk.org/uploads/default/original/2X/1/15d802e02df7397e47bceea00076ebfb243e2900.png)

 ![TestPBR_Skybox_Anisotropy](https://discourse.vtk.org/uploads/default/original/2X/7/7a76323c67312d277261fe3ca7d4f4c551b632ba.png)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 11, 2021, 8:12am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/19 "2021-08-11T08:12:13Z")

</div>

😍

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicolas.vuaille/32/5363_2.png) [@nicolas.vuaille](https://discourse.vtk.org/u/nicolas.vuaille)
#### Post date: [August 11, 2021, 8:14am UTC](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981/20 "2021-08-11T08:14:53Z")

</div>

Great work @amaclean !

[Next page](https://discourse.vtk.org/t/ann-examples-for-physically-based-rendering/1981.md?page=2)
