]> git.tdb.fi Git - libs/gl.git/blob - builtin_data/_envmap_irradiance.glsl
Consider expressions in array sizes when comparing types for equality
[libs/gl.git] / builtin_data / _envmap_irradiance.glsl
1 import cubemap_effect;
2 import _pbr_prefilter;
3
4 #pragma MSP stage(fragment)
5 layout(location=0) out vec3 frag_color;
6 void main()
7 {
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);
11
12         vec3 sum = vec3(0.0);
13         for(int i=0; i<n_samples; ++i)
14         {
15                 vec2 uv = hammersley(i, n_samples);
16                 vec3 dir = orientation*uv_to_hemisphere(uv.x, sqrt(1.0-uv.y));
17                 sum += textureLod(environment_map, dir, 0).rgb;
18         }
19
20         frag_color = sum/n_samples;
21 }