|
@@ -3,6 +3,8 @@
|
|
|
// Code licensed under the BSD License.
|
|
// Code licensed under the BSD License.
|
|
|
// http://www.anki3d.org/LICENSE
|
|
// http://www.anki3d.org/LICENSE
|
|
|
|
|
|
|
|
|
|
+// NOTE: To visualize some of these functions go to https://www.shadertoy.com/view/wsBBzV
|
|
|
|
|
+
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <shaders/Common.glsl>
|
|
#include <shaders/Common.glsl>
|
|
@@ -38,7 +40,7 @@ UVec3 rand3DPCG16(UVec3 v)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Stolen from Unreal
|
|
// Stolen from Unreal
|
|
|
-// It will return a uniform 2D point inside a circle. For random use rand3DPCG16()
|
|
|
|
|
|
|
+// It will return a uniform 2D point inside [0.0, 1.0]. For random use rand3DPCG16()
|
|
|
Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
|
|
Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
|
|
|
{
|
|
{
|
|
|
const F32 e1 = fract(F32(sampleIdx) / sampleCount + F32(random.x) * (1.0 / 65536.0));
|
|
const F32 e1 = fract(F32(sampleIdx) / sampleCount + F32(random.x) * (1.0 / 65536.0));
|
|
@@ -47,11 +49,21 @@ Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
|
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
|
|
-// From a uniform 2D point inside a circle get a 3D point in a hemisphere. It's oriented in the z axis
|
|
|
|
|
|
|
+// From a uniform 2D point inside a circle get a 3D point in the surface of a hemisphere. It's oriented in the z axis
|
|
|
Vec3 hemisphereSampleUniform(Vec2 uv)
|
|
Vec3 hemisphereSampleUniform(Vec2 uv)
|
|
|
{
|
|
{
|
|
|
const F32 phi = uv.y * 2.0 * PI;
|
|
const F32 phi = uv.y * 2.0 * PI;
|
|
|
const F32 cosTheta = 1.0 - uv.x;
|
|
const F32 cosTheta = 1.0 - uv.x;
|
|
|
const F32 sinTheta = sqrt(1.0 - cosTheta * cosTheta);
|
|
const F32 sinTheta = sqrt(1.0 - cosTheta * cosTheta);
|
|
|
- return Vec3(cos(phi) * sinTheta, cosTheta, sin(phi) * sinTheta);
|
|
|
|
|
|
|
+ return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
|
|
|
|
|
+// Same as hemisphereSampleUniform but it distributes points closer to the z axis
|
|
|
|
|
+Vec3 hemisphereSampleCos(Vec2 uv)
|
|
|
|
|
+{
|
|
|
|
|
+ const F32 phi = uv.y * 2.0 * PI;
|
|
|
|
|
+ const F32 cosTheta = sqrt(1.0 - uv.x);
|
|
|
|
|
+ const F32 sinTheta = sqrt(1.0 - cosTheta * cosTheta);
|
|
|
|
|
+ return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
|
|
|
}
|
|
}
|