Hello everyone. I've started to learn shader programming as a hobby since the start of this year and I'm finally up to the point where I think I can learn how to implement PBR in my shader. So I read and studied a lot of articles that talk about PBR and its calculations. With that, I decided it was time to start coding.
Firstly, I'm going for a metallic/roughness workflow for my PBR shader. I used the Oren-Nayar model for diffuse but I may change it to something more simple like Lambert as I've heard it's computationally more expensive. For the specular microfacet model I used GGX (normal distribution), Smith (geometry) and Schlick's approximation (fresnel). Because I'm still quite new with this, I got the calculations mainly from this site and this person's video.
Now for the code. As I'm using Unity, I'm writing it with the Cg language wrapped in ShaderLab code. After adding in all the calculations in my shader, I see the results and I wasn't sure if I had implemented this properly. I tweaked the roughness and metallic value around and at some given value, it look correct while at the same time, it doesn't look correct on other values. I'm not great at explaining this in words so here are the visual results and my comments regarding them.
The shader code can be found here. Again, as it's for Unity, the ShaderLab codes may be unfamiliar to you so just ignore those and find the Cg codes between the lines CGPROGRAM and ENDCG. I hope some of you understand what is happening here as it's very similar to HLSL and GLSL. If anyone know if I have implemented this correctly or not, please let me know. Thanks!