summaryrefslogtreecommitdiff
path: root/data/shaders/pbr-frag.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'data/shaders/pbr-frag.glsl')
-rw-r--r--data/shaders/pbr-frag.glsl80
1 files changed, 27 insertions, 53 deletions
diff --git a/data/shaders/pbr-frag.glsl b/data/shaders/pbr-frag.glsl
index 478c40a..c474981 100644
--- a/data/shaders/pbr-frag.glsl
+++ b/data/shaders/pbr-frag.glsl
@@ -2,19 +2,13 @@
struct Material {
vec3 baseColorFactor;
- bool baseColorTextureEnabled;
int baseColorTexcoord;
float metallicFactor;
float roughnessFactor;
- bool metallicRoughnessTextureEnabled;
int metallicRoughnessTexcoord;
- vec3 normalFactor;
- bool normalTextureEnabled;
int normalTexcoord;
- bool occlusionTextureEnabled;
int occlusionTexcoord;
vec3 emissiveFactor;
- bool emissiveTextureEnabled;
int emissiveTexcoord;
int alphaMode;
float alphaCutoff;
@@ -142,34 +136,25 @@ vec3 toneMap(vec3 color) {
float materialMetallic() {
float m = material.metallicFactor;
-
- if(material.metallicRoughnessTextureEnabled) {
- m *= texture(metallicRoughnessTexture,
- texcoord(material.metallicRoughnessTexcoord)).b;
- }
-
+ m *= texture(metallicRoughnessTexture,
+ texcoord(material.metallicRoughnessTexcoord)).b;
return m;
}
float materialRoughness() {
float r = material.roughnessFactor;
- if(material.metallicRoughnessTextureEnabled) {
- r *= texture(metallicRoughnessTexture,
- texcoord(material.metallicRoughnessTexcoord)).g;
- }
+ r *= texture(metallicRoughnessTexture,
+ texcoord(material.metallicRoughnessTexcoord)).g;
return r;
}
vec4 materialAlbedo() {
- vec4 color = vec4(0.0, 0.0, 1.0, 1.0);
-
- if(material.baseColorTextureEnabled) {
- vec4 texColor = texture(baseColorTexture,
- texcoord(material.baseColorTexcoord));
- color = sRGBtoLinear(texColor);
- }
+ vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
+ vec4 texColor = texture(baseColorTexture,
+ texcoord(material.baseColorTexcoord));
+ color = sRGBtoLinear(texColor);
color *= vec4(material.baseColorFactor, 1.0);
@@ -183,44 +168,33 @@ vec4 materialAlbedo() {
vec3 materialEmissive() {
vec3 color = vec3(0.0);
- if(material.emissiveTextureEnabled) {
- vec4 texColor = texture(emissiveTexture,
- texcoord(material.emissiveTexcoord));
- color = sRGBtoLinear(texColor).rgb;
- }
+ vec4 texColor = texture(emissiveTexture,
+ texcoord(material.emissiveTexcoord));
+ color = sRGBtoLinear(texColor).rgb;
return color * material.emissiveFactor;
}
vec3 materialOcclusion() {
- if(material.occlusionTextureEnabled) {
- return vec3(texture(occlusionTexture,
- texcoord(material.occlusionTexcoord)).r);
- } else {
- return vec3(1.0);
- }
+ return vec3(texture(occlusionTexture,
+ texcoord(material.occlusionTexcoord)).r);
}
vec3 materialNormal() {
- if(material.normalTextureEnabled) {
- // See: http://www.thetenthplanet.de/archives/1180
- vec2 t = texcoord(material.normalTexcoord);
- vec3 tangentNormal = texture(normalTexture, t).xyz * 2.0 - 1.0;
-
- vec3 q1 = dFdx(fragWorldPos);
- vec3 q2 = dFdy(fragWorldPos);
- vec2 st1 = dFdx(fragTexcoord0);
- vec2 st2 = dFdy(fragTexcoord0);
-
- vec3 N = normalize(fragNormal);
- vec3 T = normalize(q1 * st2.t - q2 * st1.t);
- vec3 B = -normalize(cross(N, T));
- mat3 TBN = mat3(T, B, N);
-
- return normalize(TBN * tangentNormal);
- } else {
- return normalize(fragNormal);
- }
+ // See: https://github.com/SaschaWillems/Vulkan-glTF-PBR/blob/master/data/shaders/pbr_khr.frag
+ // See: http://www.thetenthplanet.de/archives/1180
+ vec2 uv = texcoord(material.normalTexcoord);
+ vec3 tangentNormal = texture(normalTexture, uv).xyz * 2.0 - 1.0;
+ vec3 q1 = dFdx(fragWorldPos);
+ vec3 q2 = dFdy(fragWorldPos);
+ vec2 st1 = dFdx(uv);
+ vec2 st2 = dFdy(uv);
+ vec3 N = normalize(fragNormal);
+ vec3 T = normalize(q1 * st2.t - q2 * st1.t);
+ vec3 B = -normalize(cross(N, T));
+ mat3 TBN = mat3(T, B, N);
+
+ return normalize(TBN * tangentNormal);
}
vec3 lightDirection(Light light) {