3 #pragma MSP stage(vertex)
4 layout(location=0) in vec4 vertex;
8 out vec2 texcoord = vertex.xy*0.5+0.5;
11 #pragma MSP stage(fragment)
12 layout(location=0) out vec2 frag_out;
15 vec3 normal = vec3(0.0, 0.0, 1.0);
16 vec3 look_dir = vec3(sqrt(1.0-texcoord.y*texcoord.y), 0.0, -texcoord.y);
17 float roughness = texcoord.x;
19 float geom_k = roughness*roughness/2.0;
20 float geom_look = -look_dir.z/(geom_k-look_dir.z*(1.0-geom_k));
23 for(int i=0; i<n_samples; ++i)
25 vec3 halfway = ndist_ggxtr_importance_sample(hammersley(i, n_samples), roughness);
26 vec3 light_dir = reflect(look_dir, halfway);
30 float geom_light = light_dir.z/(geom_k+light_dir.z*(1.0-geom_k));
31 float geom = geom_look*geom_light;
33 // Look_dir points towards the surface, so the dot product is negated
34 float half_dot_look = dot(halfway, look_dir);
35 float ng = geom*half_dot_look/(halfway.z*look_dir.z);
36 float a = pow(max(1+half_dot_look, 0.0), 5.0);
38 sum += vec2(ng*(1-a), ng*a);
42 frag_out = sum/n_samples;