summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-08-12 20:25:25 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-08-12 20:25:25 -0400
commit8925bd867e1a8791801698b1abaec4a46180656e (patch)
tree9a7a31445e86952a85b185969bfde2780cfdc5d0 /data
parentf82e5122c2feabb8d92e3d4d1789ee1490b96a90 (diff)
graphics: Always use normal/ambient/etc. maps.
If models don't specify their own textures, use noop textures as appropriate.
Diffstat (limited to 'data')
-rw-r--r--data/shaders/pbr-frag.glsl80
-rw-r--r--data/shaders/phong-frag.glsl62
2 files changed, 48 insertions, 94 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) {
diff --git a/data/shaders/phong-frag.glsl b/data/shaders/phong-frag.glsl
index 363c4e7..0beb75b 100644
--- a/data/shaders/phong-frag.glsl
+++ b/data/shaders/phong-frag.glsl
@@ -2,13 +2,9 @@
struct Material {
vec3 ambient;
- bool useAmbientMap;
vec3 diffuse;
- bool useDiffuseMap;
vec3 specular;
- bool useSpecularMap;
float shininess;
- bool useNormalMap;
};
struct Light {
@@ -100,53 +96,37 @@ vec3 lightRadiance(Light light, vec3 direction) {
}
vec3 materialAmbient() {
- if(material.useAmbientMap) {
- return texture(ambientMap, fragTex).rgb;
- } else {
- return material.ambient;
- }
+ return texture(ambientMap, fragTex).rgb * material.ambient;
}
vec3 materialDiffuse() {
- if(material.useDiffuseMap) {
- vec4 color = texture(diffuseMap, fragTex);
- // discard transparent fragments.
- if(color.a == 0.0) {
- discard;
- }
- return color.rgb;
- } else {
- return material.diffuse;
+ vec4 color = texture(diffuseMap, fragTex);
+ // discard transparent fragments.
+ if(color.a == 0.0) {
+ discard;
}
+ return color.rgb * material.diffuse;
}
vec3 materialSpecular() {
- if(material.useSpecularMap) {
- return texture(specularMap, fragTex).rgb;
- } else {
- return material.specular;
- }
+ return texture(specularMap, fragTex).rgb * material.specular;
}
vec3 materialNormal() {
- if(material.useNormalMap) {
- // Compute tangent space using fragment data rather than relying
- // on tangent attributes. See:
- // http://www.thetenthplanet.de/archives/1180
- vec3 tangentNormal = normalize(texture(normalMap, fragTex).xyz * 2.0 - 1.0);
- vec3 q1 = dFdx(fragWorldPos);
- vec3 q2 = dFdy(fragWorldPos);
- vec2 st1 = dFdx(fragTex);
- vec2 st2 = dFdy(fragTex);
- vec3 N = normalize(fragNorm);
- 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(fragNorm);
- }
+ // Compute tangent space using fragment data rather than relying
+ // on tangent attributes. See:
+ // http://www.thetenthplanet.de/archives/1180
+ vec3 tangentNormal = normalize(texture(normalMap, fragTex).xyz * 2.0 - 1.0);
+ vec3 q1 = dFdx(fragWorldPos);
+ vec3 q2 = dFdy(fragWorldPos);
+ vec2 st1 = dFdx(fragTex);
+ vec2 st2 = dFdy(fragTex);
+ vec3 N = normalize(fragNorm);
+ 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);
}
void main() {