diff options
author | pryazha <pryadeiniv@mail.ru> | 2025-08-02 13:21:42 +0500 |
---|---|---|
committer | pryazha <pryadeiniv@mail.ru> | 2025-08-02 13:21:42 +0500 |
commit | 2e64d3c5d6eb1eb04168d39d5eb5f2d89af1a8b0 (patch) | |
tree | 85c8a586a1343469cdcdab5dccad023053571ecd /pbr/ibl_specular/convolution.frag | |
parent | 33d5f67044d104d69cb2d11e78e6a79bc20d4c4e (diff) |
Diffstat (limited to 'pbr/ibl_specular/convolution.frag')
-rw-r--r-- | pbr/ibl_specular/convolution.frag | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pbr/ibl_specular/convolution.frag b/pbr/ibl_specular/convolution.frag new file mode 100644 index 0000000..69ce8af --- /dev/null +++ b/pbr/ibl_specular/convolution.frag @@ -0,0 +1,33 @@ +#version 330 core + +in vert_t { + vec3 position; +} vert; + +out vec4 frag_color; + +uniform samplerCube cubemap; + +const float PI = 3.14159265359; + +void main(void) +{ + vec3 normal = normalize(vert.position); + vec3 up = vec3(0.0, 1.0, 0.0); + vec3 right = cross(up, normal); + up = cross(normal, right); + + vec3 irradiance = vec3(0.0); + float delta = 0.025; + int nsamples = 0; + for (float phi = 0.0; phi < 2.0 * PI; phi += delta) { + for (float theta = 0.0; theta < 0.5 * PI; theta += delta) { + vec3 tangent = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); + vec3 v = tangent.x * right + tangent.y * up + tangent.z * normal; + irradiance += texture(cubemap, v).rgb * cos(theta) * sin(theta); + nsamples++; + } + } + irradiance *= PI / nsamples; + frag_color = vec4(irradiance, 1.0); +} |