# Physically based rendering library for Processing SimplePBR

**URL:** https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152
**Category:** Gallery
**Created:** [February 6, 2019, 12:09pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152 "2019-02-06T12:09:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)
#### Post date: [February 6, 2019, 12:09pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/1 "2019-02-06T12:09:15Z")

</div>

I have created a library for Physically based rendering (PBR) in Processing. PBR is a rendering method for more accurate (and nicer) lighting of surfaces, [here’s a demo video](https://vimeo.com/315540699).

 ![vlcsnap-2019-02-06-11h13m51s589%20(2)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dbee0052b0429c5a5c99a2a91b691f2015c14757.png)

There is [more information on my website](http://www.nachocossio.com/simplepbr-processing-library/) and the source is hosted at [this Github repo](https://github.com/kosowski/SimplePBR/).

At the moment it has been tested on Windows and Linux with nVidia graphics. The shader fails to compile on Intel integrated graphics and osX, as I don’t usually work with any of them I don’t plan to look into it in the near future. If you find the solution, please tell me 🙂

Would love knowing if you find it useful.

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [February 6, 2019, 12:43pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/2 "2019-02-06T12:43:23Z")

</div>

Can’t test it on my old Mac desktop but this looks awesome ! Thank you for sharing this as a library.

---

<div class="post-metadata">

### Author: ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)
#### Post date: [February 6, 2019, 6:05pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/3 "2019-02-06T18:05:43Z")

</div>

You’re welcome!

It should run on Mac by changing whatever functions or operations the shader compiler is not liking, but unfortunately the error message is not very clear.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [February 13, 2019, 5:36am UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/4 "2019-02-13T05:36:30Z")

</div>

Thank you! Very nice! And it works fine on Linux with nVidia 🙂

 ![Screenshot%20from%202019-02-13%2006-34-02](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3120f05af2f0245d9b16d06e00ca68577e993f75.jpeg)

---

<div class="post-metadata">

### Author: ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)
#### Post date: [February 13, 2019, 9:55am UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/5 "2019-02-13T09:55:20Z")

</div>

Thanks, great to know it works on Linux. I tried Linux with Intel integrated graphics with no luck, I guess Intel and Apple drivers are more strict than nVidia’s.

Thanks for the pull request, will look later into them! Keep them coming 😉 I have some changes in mind to simplify the library, will try to update it this week and add normal maps support.

---

<div class="post-metadata">

### Author: ![Stephcraft](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stephcraft/32/22024_2.png) [@Stephcraft](https://discourse.processing.org/u/Stephcraft)
#### Post date: [February 17, 2019, 8:32pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/6 "2019-02-17T20:32:03Z")

</div>

This looks awesome! But I cannot compile it. I tried on Windows and Mac. I get this error on the mat.bind() function:

```nohighlight
The sketch has been automatically resized to fit the screen resolution
Cannot validate shader program:Validation Error: Samplers of different types point to the same texture unitValidation Error: Samplers of different types point to the same texture unit

```

You could make your own loadShader that adds a definition depending on your os:

```auto
public PShader loadShader(String vertsrc, String fragsrc) {
	String os = System.getProperty("os.name");

	// Load shader files
	String vert = join(loadStrings(vertsrc), "\n");
	String frag = join(loadStrings(fragsrc), "\n");

	// Windows
	if(os.contains("Windows")) {
		vert = "#define WINDOWS\n" + vert;
		frag = "#define WINDOWS\n" + frag;
	}

	// Mac OS
	else if(os.contains("Mac")) {
		vert = "#define MAC\n" + vert;
		frag = "#define MAC\n" + frag;
	}

	// Linux
	else if(os.contains("Linux")) {
		vert = "#define LINUX\n" + vert;
		frag = "#define LINUX\n" + frag;
	}

	// Other...
	else {
		vert = "#define UNKNOWNOS\n" + vert;
		frag = "#define UNKNOWNOS\n" + frag;
	}

	// Build shader from strings
	return new PShader(this, vert.split("\n"), frag.split("\n"));
}

```

And then use `#ifdef OSNAME` with `#endif` in your shader to mask blocks of code depending on the user os, for exemple:

```auto
#ifdef WINDOWS
	vec4 coolcolor = texture2D(texture, uv);
#endif

#ifdef MAC
	vec4 coolcolor = texture(texture, uv);
#endif

```

---

<div class="post-metadata">

### Author: ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)
#### Post date: [February 18, 2019, 12:32pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/7 "2019-02-18T12:32:24Z")

</div>

Thanks! Nice tip for adding preprocessing definitions, I will be using it 🙌. Unfortunately, this is related to the graphics driver, rather than the OS, and I don’t know what takes for an Intel o Apple driver to compile the shader, neither have the time or easy acces to any of them to try.  
If anyone finds why it fails to compile, I would be happy to change it…

---

<div class="post-metadata">

### Author: ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)
#### Post date: [August 3, 2020, 4:29pm UTC](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/8 "2020-08-03T16:29:34Z")

</div>

Updated so it now it runs on all desktop platforms!

On osx and integrated graphics cards there is an [known issue](https://github.com/processing/processing/issues/5507) with samplerCube, in these cases I moved to a equirectangular texture for the environment map instead of a cubemap.
