summaryrefslogtreecommitdiff
path: root/intermediate/surface.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'intermediate/surface.glsl')
-rw-r--r--intermediate/surface.glsl51
1 files changed, 43 insertions, 8 deletions
diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl
index ce80259..cc287e4 100644
--- a/intermediate/surface.glsl
+++ b/intermediate/surface.glsl
@@ -9,6 +9,22 @@ fragment: main
#ifdef DESC
+[option]
+name: albedomap
+stage: fragment
+[option]
+name: aomap
+stage: fragment
+[option]
+name: metalmap
+stage: fragment
+[option]
+name: roughmap
+stage: fragment
+[option]
+name: normalmap
+stage: fragment
+
[binding]
name: mesh
rate: vertex
@@ -142,8 +158,8 @@ void main() {
#define pi 3.14159265358979323846
-vec3 diffuse_brdf(vec2 uv) {
- vec3 a = material.albedo * texture(albedo, uv).rgb;
+vec3 diffuse_brdf(vec2 uv, vec3 base) {
+ vec3 a = base;
return a / pi;
}
@@ -157,7 +173,11 @@ float specular_G1(float a, vec3 v, vec3 n) {
float specular_brdf(vec2 uv, vec3 ref, vec3 l, vec3 v, vec3 n) {
float ndl = max(dot(n, l), 0.0);
float ndv = max(dot(n, v), 0.0);
+#if OPT_roughmap
float a = texture(rough, uv).r * material.roughness;
+#else
+ float a = material.roughness;
+#endif
float a2 = a * a;
float ndr = max(dot(n, ref), 0.0);
float b = ((ndr * ndr) * (a2 - 1) + 1);
@@ -244,26 +264,41 @@ void main() {
vec2 uv = interpolator.uv;
vec3 p = interpolator.position.xyz;
+#if OPT_normalmap
vec3 nrmsample = texture(normal, uv).rgb;
vec2 nrmxy = nrmsample.xy * 2.0 - 1.0;
vec3 nrm = normalize(vec3(nrmxy, 1.0));
- if (nrmsample.b == 1.0) /* default texture */
- nrm = normalize(interpolator.tbn[2]);
- else
- nrm = normalize(interpolator.tbn * nrm);
+ nrm = normalize(interpolator.tbn * nrm);
+#else
+ vec3 nrm = normalize(interpolator.tbn[2]);
+#endif
+#if OPT_albedomap
vec3 col = texture(albedo, uv).rgb * material.albedo;
- vec3 view_dir = normalize(globals.camera_pos - p);
+#else
+ vec3 col = material.albedo;
+#endif
+
+#if OPT_metalmap
float met = texture(metal, uv).r * material.metalness;
+#else
+ float met = material.metalness;
+#endif
+
+ vec3 view_dir = normalize(globals.camera_pos - p);
vec3 ref = reflect(-view_dir, nrm);
vec3 ref_col = texture(env_cube, ref, material.roughness * 8.0).rgb;
vec3 spec_col = mix(ref_col, ref_col * col, met);
vec3 amb_col = min(textureLod(env_cube, nrm, 8.0).rgb, 0.05);
+#if OPT_aomap
vec3 ambient =
amb_col *
texture(ao, uv).r * material.ao;
+#else
+ vec3 ambient = amb_col * material.ao;
+#endif
- vec3 base_diffuse = diffuse_brdf(uv) * (1.0 - met);
+ vec3 base_diffuse = diffuse_brdf(uv, col) * (1.0 - met);
vec3 light = 0.0.xxx;
e = globals.sun_irange.y;