Returns a random direction for sampling a GGX distribution. Does everything in world space.
| 119 | // Returns a random direction for sampling a GGX distribution. |
| 120 | // Does everything in world space. |
| 121 | inline Float3 SampleDirectionGGX(const Float3& v, const Float3& n, float roughness, |
| 122 | const Float3x3& tangentToWorld, float u1, float u2) |
| 123 | { |
| 124 | float theta = std::atan2(roughness * std::sqrt(u1), std::sqrt(1 - u1)); |
| 125 | float phi = 2 * Pi * u2; |
| 126 | |
| 127 | Float3 h; |
| 128 | h.x = std::sin(theta) * std::cos(phi); |
| 129 | h.y = std::sin(theta) * std::sin(phi); |
| 130 | h.z = std::cos(theta); |
| 131 | |
| 132 | h = Float3::Normalize(Float3::Transform(h, tangentToWorld)); |
| 133 | |
| 134 | float hDotV = std::abs(Float3::Dot(h, v)); |
| 135 | Float3 sampleDir = 2.0f * hDotV * h - v; |
| 136 | return Float3::Normalize(sampleDir); |
| 137 | } |
| 138 | |
| 139 | // Returns the PDF for a particular GGX sample |
| 140 | inline float GGX_PDF(const Float3& n, const Float3& h, const Float3& v, float roughness) |