Solution

Files changed (1) hide show
  1. lab4-shading/shading.frag +18 -0
lab4-shading/shading.frag CHANGED
@@ -123,6 +123,24 @@ vec3 calculateIndirectIllumination(vec3 wo, vec3 n, vec3 base_color)
123
123
  // Task 6 - Look up in the reflection map from the perfect specular
124
124
  // direction and calculate the dielectric and metal terms.
125
125
  ///////////////////////////////////////////////////////////////////////////
126
+ vec3 wi = normalize(reflect(-wo, n));
127
+ vec3 wr = normalize(vec3(viewInverse * vec4(wi, 0.0)));
128
+ theta = acos(max(-1.0f, min(1.0f, wr.y)));
129
+ phi = atan(wr.z, wr.x);
130
+ if(phi < 0.0f)
131
+ phi = phi + 2.0f * PI;
132
+ lookup = vec2(phi / (2.0 * PI), 1 - theta / PI);
133
+ float roughness = sqrt(sqrt(2.0 / (material_shininess + 2.0)));
134
+ Li = environment_multiplier * textureLod(reflectionMap, lookup, roughness * 7.0).rgb;
135
+ vec3 wh = normalize(wi + wo);
136
+ float wodotwh = max(0.0, dot(wo, wh));
137
+ float F = material_fresnel + (1.0 - material_fresnel) * pow(1.0 - wodotwh, 5.0);
138
+ vec3 dielectric_term = F * Li + (1.0 - F) * diffuse_term;
139
+ vec3 metal_term = F * base_color * Li;
140
+
141
+ vec3 microfacet_term = material_metalness * metal_term + (1.0 - material_metalness) * dielectric_term;
142
+
143
+ indirect_illum = microfacet_term;
126
144
 
127
145
  return indirect_illum;
128
146
  }