Issue with my PBR shader

Updated on April 11, 2017 in [A] Shaders
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
2 on April 9, 2017

Hey everyone. I’ve been learning how to write shaders using the Cg language and finally decided to tackle the concept of PBR. Using this video and some slight modifications, I was able to create one but there was an issue that I’m not able to fix yet.

In my shader, the material goes completely black if the roughness is at 1 while metallic is also at 1 even though that should only happen when the roughness is 0 (a perfect mirror essentially). However, this isn’t the case with mine and the material is black even though the roughness is at max value. Here’s a comparison with Unity’s standard shader:

Theirs uses a smoothness value which is basically the opposite to my roughness value. As you can see, when their smoothness value is 0 (rough material), the material is darkened rather than going completely black. Also, because of this, my material stays black when the metallic value is at 1 even though I lower my roughness value. The lower the roughness value, the intense the specular highlight should appear until it reaches 0 which would be black.

If anyone know how to solve this, let me know. Here’s the code.

  • Liked by
Reply
0 on April 9, 2017

No idea what your problem is. But I know that ‘roughness’ is used wrongly as smoothnes sometimes (so that roughness = 1 is totally smooth). You should test that that implementation is not secretly just smoothness.

  • Liked by
Reply
Cancel
0 on April 11, 2017

Pretty sure that’s not the problem. I decided to rewrite my code and the results look slightly better. It doesn’t go completely black when roughness is 1 but it still look too dark. I’m not sure if this actually the correct intended result so if anyone knows, let me know.

Here are the results.
And the updated code.

  • Liked by
Reply
Cancel