summaryrefslogtreecommitdiffstats
path: root/glitter.slang
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-03-29 15:44:01 -0700
committeryum <yum.food.vr@gmail.com>2026-03-29 15:44:01 -0700
commita9217eb6c67282ac2451f1eafcedca04a8c5e564 (patch)
tree32eab99906bb3e929163b86c0e451d38ca8d8959 /glitter.slang
parent146a9a0f1aee3b69b7a37e3a67b84be1887b2594 (diff)
Continue work on glitter
Diffstat (limited to 'glitter.slang')
-rw-r--r--glitter.slang74
1 files changed, 0 insertions, 74 deletions
diff --git a/glitter.slang b/glitter.slang
deleted file mode 100644
index 5442a0f..0000000
--- a/glitter.slang
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef __GLITTER_INC
-#define __GLITTER_INC
-
-#define PI 3.1415926535897932384626433832795028841971
-
-float gaussian(float3 x, float3 mu, float sigma) {
- float3 x_minus_mu = x - mu;
- return exp(-dot(x_minus_mu, x_minus_mu) / (2 * sigma * sigma)) / (sigma * sqrt(2 * PI));
-}
-
-float det(float2x2 m) {
- return m[0][0] * m[1][1] - m[0][1] * m[1][0];
-}
-
-float dirac(float3 x) {
- // Ternary operator short-circuits in slang >:(
- return any(abs(x) < 1e-4) ? 1e4 : 0;
-}
-
-// Maps a point on the unit hemisphere to an inscribed circle.
-float2 hemisphere_to_inscribed_circle(float3 p) {
- // TODO
- return 0;
-}
-
-float3 rand3_hash(float3 p)
-{
- // Improved Murmurhash3 by Squirrel Eiserloh (GDC 2017)
- p = float3(dot(p, float3(127.1, 311.7, 74.7)),
- dot(p, float3(269.5, 183.3, 246.1)),
- dot(p, float3(113.5, 271.9, 124.6)));
- return -1.0 + 2.0 * frac(sin(p) * 43758.5453123);
-}
-
-public float D_Kemppinen(
- float3 worldPos,
- float3 H_tan, // halfway vector in tangent space
- float amount,
- float roughness)
-{
- float2x2 J_T__omega_h = 0; // TODO
- float det_J_T__omega_h = det(J_T__omega_h);
-
- float sum = 0;
- // x is the current world space position.
- float3 x = worldPos;
- // omega_h is the halfway vector *in TBN coordinates.*
- float3 omega_h = H_tan;
- float3 T_omega_h = float3(
- hemisphere_to_inscribed_circle(omega_h),
- 0);
- uint K_p = 1; // TODO
- for (uint i = 0; i < K_p; ++i) {
- // x_i is the position of the facet.
- float3 x_i = worldPos; // TODO randomize position
- // mu_i is the orientation of the facet.
- float3 mu_i = abs(rand3_hash(x_i));
-
- float a_star = roughness;
-
- float cur_gauss = gaussian(
- T_omega_h,
- mu_i,
- a_star * sqrt(det_J_T__omega_h));
-
- sum += cur_gauss * dirac(x_i - x);
- }
-
- float scale = det_J_T__omega_h / K_p;
- return sum * scale;
-}
-
-#endif // __GLITTER_INC
-