4 #pragma MSP stage(fragment)
5 layout(location=0) out vec3 frag_color;
8 vec3 normal = normalize(texcoord);
9 vec3 tangent = normalize(abs(normal.x)>abs(normal.y) ? vec3(-normal.z, 0.0, normal.x) : vec3(0.0, -normal.z, normal.y));
10 mat3 orientation = mat3(tangent, cross(normal, tangent), normal);
14 for(int i=0; i<n_samples; ++i)
16 vec3 halfway = orientation*ndist_ggxtr_importance_sample(hammersley(i, n_samples), roughness);
17 vec3 light_dir = reflect(-normal, halfway);
19 float n_dot_light = dot(normal, light_dir);
23 sum += textureLod(environment_map, light_dir, 0).rgb*n_dot_light;
24 weight += n_dot_light;
28 frag_color = sum/weight;