Skip to content

Commit d49119d

Browse files
committed
Decoupled material reading and material initialization
1 parent 38459c9 commit d49119d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/Renderer/Shaders/pbr.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ vec3 pbrEmissive(vec2 texcoord)
116116
}
117117
}
118118
119+
PBRMaterial pbrInitMaterial(PBRMaterial mat);
120+
119121
PBRMaterial pbrMaterial(vec2 texcoord)
120122
{
121123
PBRMaterial mat;
@@ -130,6 +132,15 @@ PBRMaterial pbrMaterial(vec2 texcoord)
130132
mat.occlusion = pbrOcclusion(texcoord);
131133
mat.emissive = pbrEmissive(texcoord);
132134
135+
mat = pbrInitMaterial(mat);
136+
137+
return mat;
138+
}
139+
140+
#endif // READ_MATERIAL
141+
142+
PBRMaterial pbrInitMaterial(PBRMaterial mat)
143+
{
133144
// Taken directly from GLTF 2.0 specs
134145
// this can be precalculated instead of evaluating it in the BRDF for every light
135146
@@ -143,8 +154,6 @@ PBRMaterial pbrMaterial(vec2 texcoord)
143154
return mat;
144155
}
145156
146-
#endif
147-
148157
// gives a new value a (roughness^2)
149158
float specularAntiAliasing(vec3 N, float a)
150159
{
@@ -176,7 +185,7 @@ float specularAntiAliasing(vec3 N, float a)
176185
// and
177186
// https://learnopengl.com/PBR/Lighting
178187

179-
#define INV_PI 0.3183098861837906715377675267450
188+
#define INV_PI (0.3183098861837906715377675267450)
180189

181190
// Schlick approximation to Fresnel equation
182191
vec3 F_Schlick(float VoH, vec3 F0)

0 commit comments

Comments
 (0)