summaryrefslogtreecommitdiff
path: root/intermediate
diff options
context:
space:
mode:
Diffstat (limited to 'intermediate')
-rw-r--r--intermediate/surface.glsl17
1 files changed, 12 insertions, 5 deletions
diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl
index 5feb09f..8ec24f0 100644
--- a/intermediate/surface.glsl
+++ b/intermediate/surface.glsl
@@ -87,6 +87,10 @@ dimension: 2
name: normal
stage: fragment
dimension: 2
+[texture]
+name: env_cube
+stage: fragment
+dimension: cube
[target]
name: colour
@@ -126,10 +130,9 @@ float specular_G1(float a, vec3 v, vec3 n) {
return ndv / (ndv * (1.0 - k) + k);
}
-float specular_brdf(vec2 uv, vec3 l, 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);
- vec3 ref = reflect(-l, n);
float a = texture(rough, uv).r * material.roughness;
float a2 = a * a;
float ndr = max(dot(n, ref), 0.0);
@@ -161,16 +164,20 @@ void main() {
vec3 view_dir = normalize(material.camera_pos - p);
float met = texture(metal, uv).r * material.metalness;
+ vec3 ref = reflect(-view_dir, nrm);
+ vec3 spec_col = texture(env_cube, ref).rgb;
+ vec3 amb_col = texture(env_cube, nrm).rgb;
+
vec3 diffuse =
diffuse_brdf(uv) *
(1.0 - met) *
cos_theta_i;
vec3 spec =
- mix(1.0.xxx, col, met) *
- specular_brdf(uv, light_dir, view_dir, nrm) *
+ mix(spec_col, col, met) *
+ specular_brdf(uv, ref, light_dir, view_dir, nrm) *
cos_theta_i;
vec3 ambient =
- min(col, 0.05) *
+ min(amb_col, 0.05) *
texture(ao, uv).r;
colour = vec4(ambient + diffuse + spec, 1.0);