summaryrefslogtreecommitdiffstats
path: root/pbr.cginc
blob: b297a0fe166cb76c22af880d7c339fe834cc8942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef __PBR_INC
#define __PBR_INC

#include "filamented.cginc"
#include "globals.cginc"
#include "interpolators.cginc"

struct Pbr {
  float4 albedo;
  float3 normal;
  float smoothness;
  float roughness_perceptual;
  float roughness;
  float metallic;
};

// TODO consider normal filtering like filamented
void propagateSmoothness(inout Pbr pbr) {
  pbr.roughness_perceptual = max(MIN_PERCEPTUAL_ROUGHNESS, 1.0f - pbr.smoothness);
  pbr.roughness = max(MIN_ROUGHNESS, pbr.roughness_perceptual * pbr.roughness_perceptual);
}

Pbr getPbr(v2f i) {
  Pbr pbr = (Pbr) 0;
  pbr.normal = normalize(i.normal);
  pbr.albedo = _Color;
  pbr.smoothness = _Smoothness;
  propagateSmoothness(pbr);

  pbr.metallic = _Metallic;
  return pbr;
}

#endif  // __PBR_INC