Skip to content

Instantly share code, notes, and snippets.

View skitaoka's full-sized avatar

Shinya Kitaoka skitaoka

View GitHub Profile
@skitaoka
skitaoka / SampleVndf_GGX.cpp
Created July 30, 2023 10:50 — forked from jdupuy/SampleVndf_GGX.cpp
Sampling Visible GGX Normals with Spherical Caps
// Helper function: sample the visible hemisphere from a spherical cap
vec3 SampleVndf_Hemisphere(vec2 u, vec3 wi)
{
// sample a spherical cap in (-wi.z, 1]
float phi = 2.0f * M_PI * u.x;
float z = fma((1.0f - u.y), (1.0f + wi.z), -wi.z);
float sinTheta = sqrt(clamp(1.0f - z * z, 0.0f, 1.0f));
float x = sinTheta * cos(phi);
float y = sinTheta * sin(phi);
vec3 c = vec3(x, y, z);