--- /dev/null
+import cubemap_effect;
+import _pbr_prefilter;
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec3 frag_color;
+void main()
+{
+ vec3 normal = normalize(texcoord);
+ vec3 tangent = normalize(abs(normal.x)>abs(normal.y) ? vec3(-normal.z, 0.0, normal.x) : vec3(0.0, -normal.z, normal.y));
+ mat3 orientation = mat3(tangent, cross(normal, tangent), normal);
+
+ vec3 sum = vec3(0.0);
+ float weight = 0.0;
+ for(int i=0; i<n_samples; ++i)
+ {
+ vec3 halfway = orientation*ndist_ggxtr_importance_sample(hammersley(i, n_samples), roughness);
+ vec3 light_dir = reflect(-normal, halfway);
+
+ float n_dot_light = dot(normal, light_dir);
+
+ if(n_dot_light>0)
+ {
+ sum += textureLod(environment_map, light_dir, 0).rgb*n_dot_light;
+ weight += n_dot_light;
+ }
+ }
+
+ frag_color = sum/weight;
+}