PBR shader

Physically based shader written in HLSL.



This shader was created to get a deeper understanding for how physically based rendering works.


  • Written in HLSL
  • Directional lights utilizing GGX distribution
  • Ambient light and reflections from cubemap
  • Metallic/roughness workflow
  • Calculates tangent basis per pixel to enable overlapping and mirrored normal maps
  • Lerps between normal-mapped normal and vertex normal based on angle to surface to remove overly reflective surfaces at grazing angles

Character model created by Joachim Häggström.

Problems encountered

I used ShaderTool to pipe all the data into the shader. While this allowed me to create the shader in a short time span, it also came with a few drawbacks, such as no support for HDR cubemaps and the fact that mipmaps are recomputed for DDS textures when they are loaded. This stopped me from using HDR cubemaps and pre-convolved GGX cubemaps that are synced between the authoring program (Knald Lys) and the shader.