Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(cursor): recut the Prism Glow 3D hand as a gem after the new sheet

Claudec19671168b92
diff --git a/crates/compositor/src/sculpt.rs b/crates/compositor/src/sculpt.rs
index 8687b1db7..653347323 100644
--- a/crates/compositor/src/sculpt.rs
+++ b/crates/compositor/src/sculpt.rs
@@ -30,11 +30,12 @@ const Z_HIGH_ARROW: f32 = 0.31;
const Z_HIGH_HAND: f32 = 0.4;
/// Boîtes des modèles dans le prototype (x0, x1, haut). Leur hauteur est celle du sprite,
/// 1 / SCULPT_SCALE : le mode 15 tient le plus grand côté de la boîte pour 1 (`sprite_size`).
-/// Celles du cristal et des voxels ; puis les thèmes cerclés, que leur trait élargit et que
-/// débordent l'étoile et les feuilles (Star Sprout), les tirets du clic et le calque jaune (Pop
-/// Coral), le pouce.
+/// Celles de la flèche taillée et des voxels, puis de la main taillée, dont le pouce déborde ;
+/// puis les thèmes cerclés, que leur trait élargit et que débordent l'étoile et les feuilles (Star
+/// Sprout), les tirets du clic et le calque jaune (Pop Coral), le pouce.
const BOX_ARROW: [f32; 3] = [-0.1, 0.75, 0.09];
const BOX_HAND: [f32; 3] = [-0.27, 0.73, 0.07];
+const BOX_GEM_HAND: [f32; 3] = [-0.39, 0.61, 0.03];
const BOX_INK_ARROW: [f32; 3] = [-0.08, 0.6, 0.03];
const BOX_INK_HAND: [f32; 3] = [-0.36, 0.6, 0.03];
const BOX_CORAL_ARROW: [f32; 3] = [-0.35, 0.6, 0.06];
@@ -61,6 +62,7 @@ fn silhouette_top(theme: usize, arrow: bool) -> f32 {
/// La boîte du modèle (x0, x1, haut) dans le prototype.
fn model_box(theme: usize, arrow: bool) -> [f32; 3] {
match (THEMES[theme], arrow) {
+ ("prism-glow", false) => BOX_GEM_HAND,
("studio-ink", true) => BOX_INK_ARROW,
("studio-ink", false) => BOX_INK_HAND,
("pop-coral", true) => BOX_CORAL_ARROW,
@@ -170,4 +172,43 @@ mod tests {
}
}
}
+
+ /// Les plans taillés de Prism Glow, que `scripts/generate-prism-glow-gem.mjs` écrit dans les
+ /// trois shaders, y sont les mêmes ; chaque pièce a ses plans et leurs normales sont unitaires.
+ #[test]
+ fn the_gem_tables_match_in_the_three_shaders() {
+ let tables = [
+ include_str!("shaders.hlsl"),
+ include_str!("shaders.metal"),
+ include_str!("vk_shaders/layer.wgsl"),
+ ]
+ .map(|src| {
+ let a = src.find("// <prism-glow-gem>").expect("marqueur d'ouverture");
+ let b = src.find("// </prism-glow-gem>").expect("marqueur de fermeture");
+ let block = &src[a..b];
+ let decimals: Vec<f32> = block
+ .split(|c: char| !(c.is_ascii_digit() || c == '.' || c == '-'))
+ .filter(|t| t.contains('.'))
+ .map(|t| t.parse().unwrap())
+ .collect();
+ let line = block.lines().find(|l| l.contains("GEM_PIECE")).unwrap();
+ let list = &line[line.rfind(['(', '{']).unwrap() + 1..];
+ let starts: Vec<usize> = list
+ .split(|c: char| !c.is_ascii_digit())
+ .filter(|t| !t.is_empty())
+ .map(|t| t.parse().unwrap())
+ .collect();
+ (decimals, starts)
+ });
+ let (decimals, starts) = &tables[0];
+ assert!(tables.iter().all(|t| t == &tables[0]), "tables différentes d'un shader à l'autre");
+ assert_eq!(starts.len(), 9, "2 pièces de flèche, 6 de main");
+ assert!(starts.windows(2).all(|w| w[1] >= w[0] + 4), "une pièce sans volume");
+ let planes = starts[8];
+ assert_eq!(decimals.len(), planes * 4 + 4 * 3, "plans puis boîtes");
+ for p in decimals[..planes * 4].chunks(4) {
+ let len = (p[0] * p[0] + p[1] * p[1] + p[2] * p[2]).sqrt();
+ assert!((len - 1.0).abs() < 1e-3, "normale non unitaire : {p:?}");
+ }
+ }
}
diff --git a/crates/compositor/src/shaders.hlsl b/crates/compositor/src/shaders.hlsl
index 9c6d1cd2d..ff5e13fc9 100644
--- a/crates/compositor/src/shaders.hlsl
+++ b/crates/compositor/src/shaders.hlsl
@@ -593,7 +593,6 @@ static const float MODEL_CONTACT_ALPHA = 0.5;
static const float SCULPT_SCALE = 0.85;
static const float SCULPT_HOVER = 0.05;
static const float SCULPT_VOX = 0.0625;
-static const float SCULPT_HAND_ZC = 0.185;
// Hauteur, dans le prototype, du z = 0 du modèle : le dessus de la pointe de la flèche, l'axe du
// bout de l'index.
static const float SCULPT_ZREF_ARROW = 0.2;
@@ -1021,92 +1020,176 @@ float s_pixel_hand_dist(float2 p)
return d;
}
-// Prism Glow est taillé, pas peint : chaque pièce est un polyèdre convexe (le max de ses plans),
-// les facettes sont planes et la silhouette polygonale.
-
-// Une arête d'un contour convexe de gemme (a -> b, sens trigonométrique) : sa paroi, une facette
-// de rondiste raide, et deux facettes de couronne qui se rejoignent au milieu de l'arête. Les
-// couronnes de toutes les arêtes se rejoignent en arêtes vives au-dessus du centre.
-float s_gem_edge(float3 p, float2 a, float2 b, float z0)
-{
- float2 e = b - a;
- float len = length(e);
- float2 d = e / len;
- float2 q = p.xy - a;
- float dist = dot(q, float2(-d.y, d.x));
- float along = abs(dot(q, d) - 0.5 * len);
- float z = p.z - z0;
- float girdle = (z - 0.035 - 2.2 * dist) * 0.4138;
- float crown = (z - 0.07 - 0.6 * dist + 0.18 * along) * 0.8438;
- return max(-dist, max(girdle, crown));
-}
-
-float s_gem_arrow(float3 p)
-{
- float z0 = SCULPT_HOVER + 0.03;
- float slab = max(p.z - z0 - 0.2, z0 - 0.03 - p.z);
- float head = max(slab, max(s_gem_edge(p, float2(-0.02, 0.03), float2(-0.02, -0.88), z0),
- max(s_gem_edge(p, float2(-0.02, -0.88), float2(0.66, -0.61), z0),
- s_gem_edge(p, float2(0.66, -0.61), float2(-0.02, 0.03), z0))));
- float tail = max(slab, max(max(s_gem_edge(p, float2(0.215, -0.665), float2(0.37, -1.0), z0),
- s_gem_edge(p, float2(0.37, -1.0), float2(0.53, -0.93), z0)),
- max(s_gem_edge(p, float2(0.53, -0.93), float2(0.38, -0.60), z0),
- s_gem_edge(p, float2(0.38, -0.60), float2(0.215, -0.665), z0))));
- return min(head, tail);
-}
-
-// Capsule taillée a -> b : un prisme hexagonal coiffé en b de deux couronnes de facettes
-// décalées et d'une facette sommitale, tous les plans tangents à la sphère du bout.
-float s_facet_capsule(float3 p, float3 a, float3 b, float r, float spin)
-{
- float3 u = normalize(b - a);
- float3 v = normalize(cross(u, float3(0.0, 0.0, 1.0)));
- float3 w = cross(u, v);
- float3 q = p - b;
- float h = dot(q, u);
- float2 rad = float2(dot(q, v), dot(q, w));
- float d = max(h - r, -dot(p - a, u) - r);
- [loop] for (int k = 0; k < 6; k++)
- {
- float an = spin + k * 1.0471976;
- float s = dot(rad, float2(cos(an), sin(an)));
- d = max(d, s - r);
- d = max(d, dot(rad, float2(cos(an + 0.5236), sin(an + 0.5236))) * 0.8660 + h * 0.5 - r);
- d = max(d, s * 0.5 + h * 0.8660 - r);
- }
- return d;
-}
-
-// Ellipsoïde taillé : les plans tangents dans dix directions du premier octant, reportées dans
-// les huit. Une pierre aux facettes de taille égale.
-static const float3 SCULPT_FACETS[10] = {
- float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), float3(0.0, 0.0, 1.0),
- float3(0.7071, 0.7071, 0.0), float3(0.7071, 0.0, 0.7071), float3(0.0, 0.7071, 0.7071),
- float3(0.5774, 0.5774, 0.5774), float3(0.4472, 0.0, 0.8944), float3(0.0, 0.4472, 0.8944),
- float3(0.3015, 0.3015, 0.9045)
+// Prism Glow est taillé, pas peint : chaque pièce est un polyèdre convexe, le max des plans de
+// ses faces (normale unitaire vers l'extérieur, décalage), et le modèle l'union de ses pièces. La
+// flèche en a deux (tête, queue) ; la main six (index, majeur, annulaire, auriculaire, pouce,
+// paume) posées sur une même dalle, les doigts plus hauts que la paume là où ils la chevauchent :
+// leur pli avec elle fait les jointures. `GEM_PIECE` borne les plans de chaque pièce, `GEM_BOX`
+// (centre, demi-côtés) la boîte de chaque forme. Tables générées par
+// scripts/generate-prism-glow-gem.mjs, qui réécrit les trois shaders : c'est là qu'on change une
+// pièce.
+// <prism-glow-gem>
+static const float4 GEM_PLANES[182] = {
+ float4(0.0000, 0.0000, 1.0000, 0.2800), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-1.0000, 0.0000, 0.0000, 0.0200), float4(-0.9104, 0.0000, 0.4138, 0.0658),
+ float4(-0.5085, -0.1525, 0.8475, 0.2021), float4(-0.5085, 0.1525, 0.8475, 0.0725),
+ float4(0.3690, -0.9294, 0.0000, 0.8105), float4(0.3360, -0.8461, 0.4138, 0.7854),
+ float4(0.3294, -0.4163, 0.8475, 0.5427), float4(0.0459, -0.5289, 0.8475, 0.5358),
+ float4(0.6854, 0.7282, 0.0000, 0.0081), float4(0.6239, 0.6629, 0.4138, 0.0550),
+ float4(0.2374, 0.4748, 0.8475, 0.0654), float4(0.4596, 0.2657, 0.8475, 0.1971),
+ float4(0.0000, 0.0000, 1.0000, 0.2800), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-0.9076, -0.4199, 0.0000, 0.0841), float4(-0.8262, -0.3823, 0.4138, 0.1242),
+ float4(-0.3974, -0.3520, 0.8475, 0.3039), float4(-0.5255, -0.0751, 0.8475, 0.0359),
+ float4(0.4008, -0.9162, 0.0000, 1.0645), float4(0.3649, -0.8340, 0.4138, 1.0166),
+ float4(0.3436, -0.4047, 0.8475, 0.6723), float4(0.0641, -0.5270, 0.8475, 0.6645),
+ float4(0.9104, 0.4138, 0.0000, 0.0977), float4(0.8288, 0.3767, 0.4138, 0.1365),
+ float4(0.3998, 0.3493, 0.8475, 0.0418), float4(0.5260, 0.0715, 0.8475, 0.3117),
+ float4(-0.3665, 0.9304, 0.0000, -0.6975), float4(-0.3337, 0.8470, 0.4138, -0.5874),
+ float4(-0.3283, 0.4172, 0.8475, -0.2344), float4(-0.0444, 0.5290, 0.8475, -0.2207),
+ float4(0.0000, 0.0000, -1.0000, -0.0500), float4(0.0000, -1.0000, 0.0000, 0.7200),
+ float4(-1.0000, 0.0000, 0.0000, 0.1400), float4(1.0000, 0.0000, 0.0000, 0.1400),
+ float4(0.7682, 0.6402, 0.0000, 0.0499), float4(0.0000, 1.0000, 0.0000, 0.0000),
+ float4(-0.7682, 0.6402, 0.0000, 0.0499), float4(0.0000, -0.8575, 0.5145, 0.6946),
+ float4(-0.8575, 0.0000, 0.5145, 0.1972), float4(0.8575, 0.0000, 0.5145, 0.1972),
+ float4(0.6820, 0.5683, 0.4603, 0.1134), float4(0.7050, 0.4755, 0.5263, 0.1348),
+ float4(0.0000, 0.9119, 0.4104, 0.0616), float4(-0.6820, 0.5683, 0.4603, 0.1134),
+ float4(-0.7050, 0.4755, 0.5263, 0.1348), float4(0.0000, -0.4657, 0.8849, 0.4983),
+ float4(-0.6727, 0.0000, 0.7399, 0.2220), float4(0.6727, 0.0000, 0.7399, 0.2220),
+ float4(0.5772, 0.0452, 0.8153, 0.2220), float4(-0.5772, 0.0452, 0.8153, 0.2220),
+ float4(0.0000, 0.1092, 0.9940, 0.2436), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.6800), float4(-1.0000, 0.0000, 0.0000, -0.1200),
+ float4(1.0000, 0.0000, 0.0000, 0.2900), float4(0.7809, 0.6247, 0.0000, 0.0141),
+ float4(0.0000, 1.0000, 0.0000, -0.2900), float4(-0.7071, 0.7071, 0.0000, -0.3182),
+ float4(0.0000, -0.8137, 0.5812, 0.6405), float4(-0.8269, 0.0000, 0.5623, -0.0149),
+ float4(-0.7483, -0.1548, 0.6451, 0.1122), float4(0.8269, 0.0000, 0.5623, 0.3242),
+ float4(0.7483, -0.1548, 0.6451, 0.4190), float4(0.6354, 0.5083, 0.5812, 0.0986),
+ float4(0.8115, 0.0175, 0.5840, 0.3170), float4(0.0000, 0.8240, 0.5665, -0.1540),
+ float4(0.0970, 0.7938, 0.6003, -0.1159), float4(-0.5754, 0.5754, 0.5812, -0.1717),
+ float4(-0.0803, 0.7997, 0.5950, -0.1555), float4(-0.8112, 0.0171, 0.5845, -0.0153),
+ float4(0.0000, -0.7270, 0.6866, 0.6032), float4(0.5553, 0.4442, 0.7031, 0.1223),
+ float4(0.5988, 0.1571, 0.7853, 0.2492), float4(-0.4961, 0.4961, 0.7126, -0.1089),
+ float4(-0.5844, 0.1591, 0.7957, 0.0083), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.6800), float4(-1.0000, 0.0000, 0.0000, -0.2700),
+ float4(1.0000, 0.0000, 0.0000, 0.4400), float4(0.7809, 0.6247, 0.0000, 0.0968),
+ float4(0.0000, 1.0000, 0.0000, -0.3450), float4(-0.7071, 0.7071, 0.0000, -0.4632),
+ float4(0.0000, -0.8137, 0.5812, 0.6405), float4(-0.8160, 0.0000, 0.5780, -0.1336),
+ float4(-0.7620, -0.1270, 0.6350, -0.0241), float4(0.8160, 0.0000, 0.5780, 0.4458),
+ float4(0.7620, -0.1270, 0.6350, 0.5169), float4(0.6354, 0.5083, 0.5812, 0.1660),
+ float4(0.8133, 0.0035, 0.5818, 0.4437), float4(0.0000, 0.8240, 0.5665, -0.1993),
+ float4(0.0970, 0.7938, 0.6003, -0.1450), float4(-0.5754, 0.5754, 0.5812, -0.2897),
+ float4(-0.0803, 0.7997, 0.5950, -0.2116), float4(-0.8132, 0.0034, 0.5819, -0.1336),
+ float4(0.0000, -0.7944, 0.6075, 0.6327), float4(0.5553, 0.4442, 0.7031, 0.1812),
+ float4(0.5984, 0.1651, 0.7840, 0.3267), float4(-0.4961, 0.4961, 0.7126, -0.2106),
+ float4(-0.5832, 0.1673, 0.7949, -0.0912), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.7000), float4(-1.0000, 0.0000, 0.0000, -0.4200),
+ float4(1.0000, 0.0000, 0.0000, 0.5850), float4(0.7809, 0.6247, 0.0000, 0.1757),
+ float4(0.0000, 1.0000, 0.0000, -0.4000), float4(-0.7071, 0.7071, 0.0000, -0.6081),
+ float4(0.0000, -0.8137, 0.5812, 0.6568), float4(-0.8209, 0.0000, 0.5711, -0.2591),
+ float4(-0.7253, -0.1978, 0.6594, -0.0673), float4(0.8137, 0.0000, 0.5812, 0.5632),
+ float4(0.6354, 0.5083, 0.5812, 0.2302), float4(0.0000, 0.8240, 0.5665, -0.2446),
+ float4(0.0970, 0.7938, 0.6003, -0.1746), float4(-0.5754, 0.5754, 0.5812, -0.4077),
+ float4(-0.1042, 0.7945, 0.5983, -0.2760), float4(-0.8119, 0.0128, 0.5837, -0.2591),
+ float4(0.0000, -0.7761, 0.6306, 0.6405), float4(0.8000, 0.0000, 0.6000, 0.5590),
+ float4(0.5553, 0.4442, 0.7031, 0.2372), float4(0.5976, 0.1766, 0.7821, 0.3983),
+ float4(-0.5159, 0.5159, 0.6838, -0.3354), float4(-0.6148, 0.1737, 0.7693, -0.2095),
+ float4(0.0000, 0.0000, -1.0000, -0.0500), float4(-0.6163, -0.7875, 0.0000, 0.7101),
+ float4(-0.9985, -0.0555, 0.0000, 0.3938), float4(0.9950, -0.0995, 0.0000, -0.0498),
+ float4(0.7926, 0.6097, 0.0000, -0.3841), float4(0.0000, 1.0000, 0.0000, -0.3700),
+ float4(-0.7593, 0.6508, 0.0000, -0.0054), float4(-0.4930, -0.6300, 0.6000, 0.6581),
+ float4(-0.8418, -0.0468, 0.5378, 0.4127), float4(-0.7161, -0.2919, 0.6340, 0.5339),
+ float4(0.8194, -0.0819, 0.5673, 0.0441), float4(0.5064, -0.3383, 0.7932, 0.3238),
+ float4(0.6341, 0.4878, 0.6000, -0.2173), float4(0.7890, 0.0096, 0.6143, 0.0085),
+ float4(0.0000, 0.8000, 0.6000, -0.2060), float4(-0.6074, 0.5206, 0.6000, 0.0857),
+ float4(-0.7848, 0.0612, 0.6167, 0.3560), float4(-0.4497, -0.5746, 0.6839, 0.6262),
+ float4(-0.4725, -0.5166, 0.7140, 0.6044), float4(0.5943, 0.4571, 0.6617, -0.1848),
+ float4(0.5974, 0.2873, 0.7487, -0.0822), float4(0.0000, 0.7526, 0.6585, -0.1759),
+ float4(-0.5348, 0.4584, 0.7099, 0.1099), float4(-0.6276, 0.2044, 0.7513, 0.2637),
+ float4(-0.3077, -0.0453, 0.9504, 0.3548), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-0.8384, -0.5450, 0.0000, 0.6121), float4(-0.4138, 0.9104, 0.0000, -0.4055),
+ float4(0.0000, -1.0000, 0.0000, 1.0000), float4(0.7853, -0.6192, 0.0000, 0.9176),
+ float4(1.0000, 0.0000, 0.0000, 0.5850), float4(0.0566, 0.9984, 0.0000, -0.5060),
+ float4(-0.6937, -0.4509, 0.5616, 0.5907), float4(-0.2912, 0.6406, 0.7105, -0.1788),
+ float4(-0.3872, 0.3638, 0.8472, 0.0404), float4(-0.4241, 0.2711, 0.8641, 0.1111),
+ float4(0.0000, -0.6690, 0.7433, 0.7805), float4(-0.0595, -0.6308, 0.7736, 0.7516),
+ float4(-0.4384, -0.4359, 0.7860, 0.5888), float4(0.6422, -0.5064, 0.5754, 0.8368),
+ float4(0.0108, -0.6477, 0.7618, 0.7661), float4(0.3229, -0.5208, 0.7903, 0.7620),
+ float4(0.6912, 0.0000, 0.7226, 0.5128), float4(0.5899, -0.2666, 0.7622, 0.6567),
+ float4(0.0435, 0.7663, 0.6410, -0.2922), float4(0.1017, 0.6072, 0.7880, -0.1502),
+ float4(0.4339, 0.3087, 0.8464, 0.2141), float4(-0.4000, 0.3006, 0.8658, 0.0864),
+ float4(-0.2957, -0.3907, 0.8717, 0.5519), float4(0.0239, -0.6091, 0.7927, 0.7392),
+ float4(0.1686, -0.4712, 0.8657, 0.6718), float4(0.1055, 0.5915, 0.7994, -0.1370),
+ float4(0.1450, 0.5209, 0.8412, -0.0674), float4(0.0152, -0.1336, 0.9909, 0.3808),
+ float4(-0.0779, -0.2355, 0.9688, 0.4421), float4(-0.1668, -0.2549, 0.9525, 0.4530),
+ float4(0.1324, -0.1566, 0.9787, 0.4232), float4(0.1566, -0.1906, 0.9691, 0.4552)
+};
+static const int GEM_PIECE[9] = { 0, 14, 32, 53, 77, 101, 124, 149, 182 };
+static const float3 GEM_BOX[4] = {
+ float3(0.320, -0.485, 0.165),
+ float3(0.350, 0.525, 0.125),
+ float3(0.107, -0.500, 0.175),
+ float3(0.487, 0.510, 0.135)
};
+// </prism-glow-gem>
-float s_facet_ellipsoid(float3 p, float3 r)
+// Hors de sa boîte, la distance à la boîte : une borne sûre, et les plans ne sont lus que près du
+// modèle.
+float s_gem_cut(float3 p, int shape)
{
- float3 q = abs(p);
- float d = -1e9;
- [loop] for (int i = 0; i < 10; i++)
+ float far = length(max(abs(p - GEM_BOX[2 * shape]) - GEM_BOX[2 * shape + 1], 0.0));
+ if (far > 0.05)
{
- d = max(d, dot(q, SCULPT_FACETS[i]) - length(r * SCULPT_FACETS[i]));
+ return far;
+ }
+ float d = 1e9;
+ [loop] for (int k = shape == 0 ? 0 : 2; k < (shape == 0 ? 2 : 8); k++)
+ {
+ float e = -1e9;
+ [loop] for (int i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++)
+ {
+ e = max(e, dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w);
+ }
+ d = min(d, e);
}
return d;
}
-// Le gant des autres thèmes, mêmes os, taillé en facettes.
-float s_crystal_hand(float3 p)
+// L'éclat des arêtes vives, 1 dessus. Dans la pièce touchée (la plus basse des distances), les
+// deux plans les plus hauts : sur la facette, l'arête est à (e1 - e2) / sin de leur angle. Les
+// arêtes presque plates, entre deux facettes de la couronne, n'en ont pas.
+float s_gem_glint(float3 p, int shape)
{
- float zc = SCULPT_HAND_ZC;
- float d = s_facet_ellipsoid(p - float3(0.185, -0.70, zc), float3(0.3, 0.235, 0.125));
- d = min(d, s_facet_capsule(p, float3(0.0, -0.52, zc), float3(0.0, -0.10, zc), 0.098, 0.3));
- d = min(d, s_facet_capsule(p, float3(0.17, -0.57, zc + 0.012), float3(0.17, -0.41, zc + 0.045), 0.086, 0.1));
- d = min(d, s_facet_capsule(p, float3(0.31, -0.59, zc + 0.01), float3(0.31, -0.45, zc + 0.04), 0.08, 0.5));
- d = min(d, s_facet_capsule(p, float3(0.435, -0.625, zc + 0.005), float3(0.435, -0.52, zc + 0.03), 0.07, 0.2));
- return min(d, s_facet_capsule(p, float3(0.03, -0.77, zc + 0.03), float3(-0.165, -0.60, zc + 0.065), 0.082, 0.7));
+ float best = 1e9;
+ float g = 1.0;
+ [loop] for (int k = shape == 0 ? 0 : 2; k < (shape == 0 ? 2 : 8); k++)
+ {
+ float e1 = -1e9;
+ float e2 = -1e9;
+ float3 n1 = 0.0;
+ float3 n2 = 0.0;
+ [loop] for (int i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++)
+ {
+ float e = dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w;
+ if (e > e1)
+ {
+ e2 = e1;
+ n2 = n1;
+ e1 = e;
+ n1 = GEM_PLANES[i].xyz;
+ }
+ else if (e > e2)
+ {
+ e2 = e;
+ n2 = GEM_PLANES[i].xyz;
+ }
+ }
+ if (e1 < best)
+ {
+ best = e1;
+ float s = length(cross(n1, n2));
+ g = (1.0 - smoothstep(0.0, 0.006, (e1 - e2) / max(s, 0.05))) * smoothstep(0.15, 0.6, s);
+ }
+ }
+ return g;
}
// Le modèle `shape` du thème `theme`, repère du prototype : (distance, id de matière).
@@ -1118,7 +1201,7 @@ float2 sculpt_proto(float3 p, int theme, int shape)
}
if (theme == 1)
{
- return float2(shape == 0 ? s_gem_arrow(p) : s_crystal_hand(p), 8.0);
+ return float2(s_gem_cut(p, shape), 8.0);
}
// Un seul appel pour les trois thèmes cerclés et leurs deux formes (FXC recopie chaque appel).
return s_rimmed(p, theme, shape);
@@ -1336,36 +1419,40 @@ float3 model_env(float3 d, float rough, float3 l, float3 fill)
return col;
}
-// Cyan, bleu, violet, orchidée.
+// Cyan, azur, bleu profond, violet.
float3 s_gem(float k)
{
k = saturate(k) * 3.0;
- float3 a = s_lin(0.20, 0.95, 1.0);
- float3 b = s_lin(0.15, 0.42, 1.0);
- float3 c = s_lin(0.45, 0.25, 0.95);
- float3 d = s_lin(0.88, 0.50, 1.0);
+ float3 a = s_lin(0.0, 0.95, 1.0);
+ float3 b = s_lin(0.10, 0.50, 1.0);
+ float3 c = s_lin(0.12, 0.22, 0.92);
+ float3 d = s_lin(0.55, 0.30, 1.0);
if (k < 1.0) return lerp(a, b, k);
if (k < 2.0) return lerp(b, c, k - 1.0);
return lerp(c, d, k - 2.0);
}
// Le cristal : la teinte vient d'où la facette regarde et d'où elle plie la vue (lues y vers le
-// haut, comme au prototype) ; la dispersion sépare le décalage par canal. Les facettes tournées
-// vers la lampe sont cyan, les autres violettes.
-float3 model_shade_crystal(float3 n, float3 rd, float3 L, float fall, float3 l, float3 fill)
+// haut, comme au prototype), plus une ondulation sur la normale qui sépare deux facettes voisines
+// comme dans une vraie pierre ; la dispersion sépare le décalage par canal. Les facettes tournées
+// vers la lampe sont cyan, les autres bleu profond ou violettes. Le verre luit de lui-même (un
+// fond fort sous la lampe) ; `glint` allume les arêtes vives.
+float3 model_shade_crystal(float3 n, float3 rd, float3 L, float fall, float3 l, float3 fill, float glint)
{
float cosi = saturate(dot(-rd, n));
float F = 0.04 + 0.96 * pow(1.0 - cosi, 5.0);
float3 t = refract(rd, n, 1.0 / 1.6);
- float k = 0.42 + 0.9 * dot(float2(n.x, -n.y), float2(0.7557, -0.6549))
- + 0.6 * dot(float2(t.x, -t.y), float2(0.6, -0.8));
+ float k = 0.4 + 1.2 * dot(float2(n.x, -n.y), float2(0.7557, -0.6549))
+ + 0.5 * dot(float2(t.x, -t.y), float2(0.6, -0.8))
+ + 0.3 * sin(11.0 * n.x - 8.0 * n.y + 3.0 * n.z);
float3 body = float3(s_gem(k - 0.08).r, s_gem(k).g, s_gem(k + 0.08).b);
- float3 col = body * (0.1 + 1.8 * fall * pow(max(dot(n, L), 0.0), 2.5));
+ float3 col = body * (0.45 + 0.65 * fall * pow(max(dot(n, L), 0.0), 1.5));
// Éclat : la vue rebondit sur le dos plat et allume la facette quand elle trouve la lampe.
- col += body * model_env(reflect(t, float3(0.0, 0.0, 1.0)) * float3(1.0, 1.0, -1.0), 0.15, l, fill) * 0.5;
- col += pow(max(dot(reflect(rd, n), L), 0.0), 30.0) * 2.0;
+ col += body * model_env(reflect(t, float3(0.0, 0.0, 1.0)) * float3(1.0, 1.0, -1.0), 0.15, l, fill) * 0.25;
+ col += pow(max(dot(reflect(rd, n), L), 0.0), 40.0) * 1.4;
col += model_env(reflect(rd, n), 0.05, l, fill) * F;
col += s_lin(0.5, 0.9, 1.0) * pow(1.0 - cosi, 4.0) * 0.6;
+ col += s_lin(0.7, 0.95, 1.0) * glint * (0.15 + 0.6 * fall);
return col;
}
@@ -1401,7 +1488,8 @@ float3 model_shade(float3 q, float3 n, float3 rd, float3 L, float fall, float sh
int id = sculpt_id();
if (id > 0 && (id - 1) / 2 == 1)
{
- return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill));
+ float glint = s_gem_glint(sculpt_point(q), (id - 1) % 2);
+ return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill, glint));
}
SculptMat m;
// Sur un sprite, reflets et brillance sur les arrondis seulement : le dessus plat d'un sprite
diff --git a/crates/compositor/src/shaders.metal b/crates/compositor/src/shaders.metal
index 77476dbd5..0157c79ca 100644
--- a/crates/compositor/src/shaders.metal
+++ b/crates/compositor/src/shaders.metal
@@ -590,7 +590,6 @@ inline int sculpt_id(constant Layer &layer)
constant float SCULPT_SCALE = 0.85;
constant float SCULPT_HOVER = 0.05;
constant float SCULPT_VOX = 0.0625;
-constant float SCULPT_HAND_ZC = 0.185;
constant float SCULPT_ZREF_ARROW = 0.2;
constant float SCULPT_ZREF_HAND = 0.185;
constant float SCULPT_LAMP_DIST = 1.9;
@@ -962,81 +961,164 @@ static float s_pixel_hand_dist(float2 p)
return d;
}
-static float s_gem_edge(float3 p, float2 a, float2 b, float z0)
-{
- float2 e = b - a;
- float len = length(e);
- float2 d = e / len;
- float2 q = p.xy - a;
- float dist = dot(q, float2(-d.y, d.x));
- float along = abs(dot(q, d) - 0.5 * len);
- float z = p.z - z0;
- float girdle = (z - 0.035 - 2.2 * dist) * 0.4138;
- float crown = (z - 0.07 - 0.6 * dist + 0.18 * along) * 0.8438;
- return max(-dist, max(girdle, crown));
-}
-
-static float s_gem_arrow(float3 p)
-{
- float z0 = SCULPT_HOVER + 0.03;
- float slab = max(p.z - z0 - 0.2, z0 - 0.03 - p.z);
- float head = max(slab, max(s_gem_edge(p, float2(-0.02, 0.03), float2(-0.02, -0.88), z0),
- max(s_gem_edge(p, float2(-0.02, -0.88), float2(0.66, -0.61), z0),
- s_gem_edge(p, float2(0.66, -0.61), float2(-0.02, 0.03), z0))));
- float tail = max(slab, max(max(s_gem_edge(p, float2(0.215, -0.665), float2(0.37, -1.0), z0),
- s_gem_edge(p, float2(0.37, -1.0), float2(0.53, -0.93), z0)),
- max(s_gem_edge(p, float2(0.53, -0.93), float2(0.38, -0.60), z0),
- s_gem_edge(p, float2(0.38, -0.60), float2(0.215, -0.665), z0))));
- return min(head, tail);
-}
+// Prism Glow : table générée par scripts/generate-prism-glow-gem.mjs (cf. HLSL).
+// <prism-glow-gem>
+constant float4 GEM_PLANES[182] = {
+ float4(0.0000, 0.0000, 1.0000, 0.2800), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-1.0000, 0.0000, 0.0000, 0.0200), float4(-0.9104, 0.0000, 0.4138, 0.0658),
+ float4(-0.5085, -0.1525, 0.8475, 0.2021), float4(-0.5085, 0.1525, 0.8475, 0.0725),
+ float4(0.3690, -0.9294, 0.0000, 0.8105), float4(0.3360, -0.8461, 0.4138, 0.7854),
+ float4(0.3294, -0.4163, 0.8475, 0.5427), float4(0.0459, -0.5289, 0.8475, 0.5358),
+ float4(0.6854, 0.7282, 0.0000, 0.0081), float4(0.6239, 0.6629, 0.4138, 0.0550),
+ float4(0.2374, 0.4748, 0.8475, 0.0654), float4(0.4596, 0.2657, 0.8475, 0.1971),
+ float4(0.0000, 0.0000, 1.0000, 0.2800), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-0.9076, -0.4199, 0.0000, 0.0841), float4(-0.8262, -0.3823, 0.4138, 0.1242),
+ float4(-0.3974, -0.3520, 0.8475, 0.3039), float4(-0.5255, -0.0751, 0.8475, 0.0359),
+ float4(0.4008, -0.9162, 0.0000, 1.0645), float4(0.3649, -0.8340, 0.4138, 1.0166),
+ float4(0.3436, -0.4047, 0.8475, 0.6723), float4(0.0641, -0.5270, 0.8475, 0.6645),
+ float4(0.9104, 0.4138, 0.0000, 0.0977), float4(0.8288, 0.3767, 0.4138, 0.1365),
+ float4(0.3998, 0.3493, 0.8475, 0.0418), float4(0.5260, 0.0715, 0.8475, 0.3117),
+ float4(-0.3665, 0.9304, 0.0000, -0.6975), float4(-0.3337, 0.8470, 0.4138, -0.5874),
+ float4(-0.3283, 0.4172, 0.8475, -0.2344), float4(-0.0444, 0.5290, 0.8475, -0.2207),
+ float4(0.0000, 0.0000, -1.0000, -0.0500), float4(0.0000, -1.0000, 0.0000, 0.7200),
+ float4(-1.0000, 0.0000, 0.0000, 0.1400), float4(1.0000, 0.0000, 0.0000, 0.1400),
+ float4(0.7682, 0.6402, 0.0000, 0.0499), float4(0.0000, 1.0000, 0.0000, 0.0000),
+ float4(-0.7682, 0.6402, 0.0000, 0.0499), float4(0.0000, -0.8575, 0.5145, 0.6946),
+ float4(-0.8575, 0.0000, 0.5145, 0.1972), float4(0.8575, 0.0000, 0.5145, 0.1972),
+ float4(0.6820, 0.5683, 0.4603, 0.1134), float4(0.7050, 0.4755, 0.5263, 0.1348),
+ float4(0.0000, 0.9119, 0.4104, 0.0616), float4(-0.6820, 0.5683, 0.4603, 0.1134),
+ float4(-0.7050, 0.4755, 0.5263, 0.1348), float4(0.0000, -0.4657, 0.8849, 0.4983),
+ float4(-0.6727, 0.0000, 0.7399, 0.2220), float4(0.6727, 0.0000, 0.7399, 0.2220),
+ float4(0.5772, 0.0452, 0.8153, 0.2220), float4(-0.5772, 0.0452, 0.8153, 0.2220),
+ float4(0.0000, 0.1092, 0.9940, 0.2436), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.6800), float4(-1.0000, 0.0000, 0.0000, -0.1200),
+ float4(1.0000, 0.0000, 0.0000, 0.2900), float4(0.7809, 0.6247, 0.0000, 0.0141),
+ float4(0.0000, 1.0000, 0.0000, -0.2900), float4(-0.7071, 0.7071, 0.0000, -0.3182),
+ float4(0.0000, -0.8137, 0.5812, 0.6405), float4(-0.8269, 0.0000, 0.5623, -0.0149),
+ float4(-0.7483, -0.1548, 0.6451, 0.1122), float4(0.8269, 0.0000, 0.5623, 0.3242),
+ float4(0.7483, -0.1548, 0.6451, 0.4190), float4(0.6354, 0.5083, 0.5812, 0.0986),
+ float4(0.8115, 0.0175, 0.5840, 0.3170), float4(0.0000, 0.8240, 0.5665, -0.1540),
+ float4(0.0970, 0.7938, 0.6003, -0.1159), float4(-0.5754, 0.5754, 0.5812, -0.1717),
+ float4(-0.0803, 0.7997, 0.5950, -0.1555), float4(-0.8112, 0.0171, 0.5845, -0.0153),
+ float4(0.0000, -0.7270, 0.6866, 0.6032), float4(0.5553, 0.4442, 0.7031, 0.1223),
+ float4(0.5988, 0.1571, 0.7853, 0.2492), float4(-0.4961, 0.4961, 0.7126, -0.1089),
+ float4(-0.5844, 0.1591, 0.7957, 0.0083), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.6800), float4(-1.0000, 0.0000, 0.0000, -0.2700),
+ float4(1.0000, 0.0000, 0.0000, 0.4400), float4(0.7809, 0.6247, 0.0000, 0.0968),
+ float4(0.0000, 1.0000, 0.0000, -0.3450), float4(-0.7071, 0.7071, 0.0000, -0.4632),
+ float4(0.0000, -0.8137, 0.5812, 0.6405), float4(-0.8160, 0.0000, 0.5780, -0.1336),
+ float4(-0.7620, -0.1270, 0.6350, -0.0241), float4(0.8160, 0.0000, 0.5780, 0.4458),
+ float4(0.7620, -0.1270, 0.6350, 0.5169), float4(0.6354, 0.5083, 0.5812, 0.1660),
+ float4(0.8133, 0.0035, 0.5818, 0.4437), float4(0.0000, 0.8240, 0.5665, -0.1993),
+ float4(0.0970, 0.7938, 0.6003, -0.1450), float4(-0.5754, 0.5754, 0.5812, -0.2897),
+ float4(-0.0803, 0.7997, 0.5950, -0.2116), float4(-0.8132, 0.0034, 0.5819, -0.1336),
+ float4(0.0000, -0.7944, 0.6075, 0.6327), float4(0.5553, 0.4442, 0.7031, 0.1812),
+ float4(0.5984, 0.1651, 0.7840, 0.3267), float4(-0.4961, 0.4961, 0.7126, -0.2106),
+ float4(-0.5832, 0.1673, 0.7949, -0.0912), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(0.0000, -1.0000, 0.0000, 0.7000), float4(-1.0000, 0.0000, 0.0000, -0.4200),
+ float4(1.0000, 0.0000, 0.0000, 0.5850), float4(0.7809, 0.6247, 0.0000, 0.1757),
+ float4(0.0000, 1.0000, 0.0000, -0.4000), float4(-0.7071, 0.7071, 0.0000, -0.6081),
+ float4(0.0000, -0.8137, 0.5812, 0.6568), float4(-0.8209, 0.0000, 0.5711, -0.2591),
+ float4(-0.7253, -0.1978, 0.6594, -0.0673), float4(0.8137, 0.0000, 0.5812, 0.5632),
+ float4(0.6354, 0.5083, 0.5812, 0.2302), float4(0.0000, 0.8240, 0.5665, -0.2446),
+ float4(0.0970, 0.7938, 0.6003, -0.1746), float4(-0.5754, 0.5754, 0.5812, -0.4077),
+ float4(-0.1042, 0.7945, 0.5983, -0.2760), float4(-0.8119, 0.0128, 0.5837, -0.2591),
+ float4(0.0000, -0.7761, 0.6306, 0.6405), float4(0.8000, 0.0000, 0.6000, 0.5590),
+ float4(0.5553, 0.4442, 0.7031, 0.2372), float4(0.5976, 0.1766, 0.7821, 0.3983),
+ float4(-0.5159, 0.5159, 0.6838, -0.3354), float4(-0.6148, 0.1737, 0.7693, -0.2095),
+ float4(0.0000, 0.0000, -1.0000, -0.0500), float4(-0.6163, -0.7875, 0.0000, 0.7101),
+ float4(-0.9985, -0.0555, 0.0000, 0.3938), float4(0.9950, -0.0995, 0.0000, -0.0498),
+ float4(0.7926, 0.6097, 0.0000, -0.3841), float4(0.0000, 1.0000, 0.0000, -0.3700),
+ float4(-0.7593, 0.6508, 0.0000, -0.0054), float4(-0.4930, -0.6300, 0.6000, 0.6581),
+ float4(-0.8418, -0.0468, 0.5378, 0.4127), float4(-0.7161, -0.2919, 0.6340, 0.5339),
+ float4(0.8194, -0.0819, 0.5673, 0.0441), float4(0.5064, -0.3383, 0.7932, 0.3238),
+ float4(0.6341, 0.4878, 0.6000, -0.2173), float4(0.7890, 0.0096, 0.6143, 0.0085),
+ float4(0.0000, 0.8000, 0.6000, -0.2060), float4(-0.6074, 0.5206, 0.6000, 0.0857),
+ float4(-0.7848, 0.0612, 0.6167, 0.3560), float4(-0.4497, -0.5746, 0.6839, 0.6262),
+ float4(-0.4725, -0.5166, 0.7140, 0.6044), float4(0.5943, 0.4571, 0.6617, -0.1848),
+ float4(0.5974, 0.2873, 0.7487, -0.0822), float4(0.0000, 0.7526, 0.6585, -0.1759),
+ float4(-0.5348, 0.4584, 0.7099, 0.1099), float4(-0.6276, 0.2044, 0.7513, 0.2637),
+ float4(-0.3077, -0.0453, 0.9504, 0.3548), float4(0.0000, 0.0000, -1.0000, -0.0500),
+ float4(-0.8384, -0.5450, 0.0000, 0.6121), float4(-0.4138, 0.9104, 0.0000, -0.4055),
+ float4(0.0000, -1.0000, 0.0000, 1.0000), float4(0.7853, -0.6192, 0.0000, 0.9176),
+ float4(1.0000, 0.0000, 0.0000, 0.5850), float4(0.0566, 0.9984, 0.0000, -0.5060),
+ float4(-0.6937, -0.4509, 0.5616, 0.5907), float4(-0.2912, 0.6406, 0.7105, -0.1788),
+ float4(-0.3872, 0.3638, 0.8472, 0.0404), float4(-0.4241, 0.2711, 0.8641, 0.1111),
+ float4(0.0000, -0.6690, 0.7433, 0.7805), float4(-0.0595, -0.6308, 0.7736, 0.7516),
+ float4(-0.4384, -0.4359, 0.7860, 0.5888), float4(0.6422, -0.5064, 0.5754, 0.8368),
+ float4(0.0108, -0.6477, 0.7618, 0.7661), float4(0.3229, -0.5208, 0.7903, 0.7620),
+ float4(0.6912, 0.0000, 0.7226, 0.5128), float4(0.5899, -0.2666, 0.7622, 0.6567),
+ float4(0.0435, 0.7663, 0.6410, -0.2922), float4(0.1017, 0.6072, 0.7880, -0.1502),
+ float4(0.4339, 0.3087, 0.8464, 0.2141), float4(-0.4000, 0.3006, 0.8658, 0.0864),
+ float4(-0.2957, -0.3907, 0.8717, 0.5519), float4(0.0239, -0.6091, 0.7927, 0.7392),
+ float4(0.1686, -0.4712, 0.8657, 0.6718), float4(0.1055, 0.5915, 0.7994, -0.1370),
+ float4(0.1450, 0.5209, 0.8412, -0.0674), float4(0.0152, -0.1336, 0.9909, 0.3808),
+ float4(-0.0779, -0.2355, 0.9688, 0.4421), float4(-0.1668, -0.2549, 0.9525, 0.4530),
+ float4(0.1324, -0.1566, 0.9787, 0.4232), float4(0.1566, -0.1906, 0.9691, 0.4552)
+};
+constant int GEM_PIECE[9] = { 0, 14, 32, 53, 77, 101, 124, 149, 182 };
+constant float3 GEM_BOX[4] = {
+ float3(0.320, -0.485, 0.165),
+ float3(0.350, 0.525, 0.125),
+ float3(0.107, -0.500, 0.175),
+ float3(0.487, 0.510, 0.135)
+};
+// </prism-glow-gem>
-static float s_facet_capsule(float3 p, float3 a, float3 b, float r, float spin)
+static float s_gem_cut(float3 p, int shape)
{
- float3 u = normalize(b - a);
- float3 v = normalize(cross(u, float3(0.0, 0.0, 1.0)));
- float3 w = cross(u, v);
- float3 q = p - b;
- float h = dot(q, u);
- float2 rad = float2(dot(q, v), dot(q, w));
- float d = max(h - r, -dot(p - a, u) - r);
- for (int k = 0; k < 6; k++)
+ float far = length(max(abs(p - GEM_BOX[2 * shape]) - GEM_BOX[2 * shape + 1], 0.0));
+ if (far > 0.05)
{
- float an = spin + float(k) * 1.0471976;
- float s = dot(rad, float2(cos(an), sin(an)));
- d = max(d, s - r);
- d = max(d, dot(rad, float2(cos(an + 0.5236), sin(an + 0.5236))) * 0.8660 + h * 0.5 - r);
- d = max(d, s * 0.5 + h * 0.8660 - r);
+ return far;
}
- return d;
-}
-
-constant float3 SCULPT_FACETS[10] = {
- float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), float3(0.0, 0.0, 1.0),
- float3(0.7071, 0.7071, 0.0), float3(0.7071, 0.0, 0.7071), float3(0.0, 0.7071, 0.7071),
- float3(0.5774, 0.5774, 0.5774), float3(0.4472, 0.0, 0.8944), float3(0.0, 0.4472, 0.8944),
- float3(0.3015, 0.3015, 0.9045)
-};
-
-static float s_facet_ellipsoid(float3 p, float3 r)
-{
- float3 q = abs(p);
- float d = -1e9;
- for (int i = 0; i < 10; i++)
+ float d = 1e9;
+ for (int k = shape == 0 ? 0 : 2; k < (shape == 0 ? 2 : 8); k++)
{
- d = max(d, dot(q, SCULPT_FACETS[i]) - length(r * SCULPT_FACETS[i]));
+ float e = -1e9;
+ for (int i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++)
+ {
+ e = max(e, dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w);
+ }
+ d = min(d, e);
}
return d;
}
-static float s_crystal_hand(float3 p)
+static float s_gem_glint(float3 p, int shape)
{
- float zc = SCULPT_HAND_ZC;
- float d = s_facet_ellipsoid(p - float3(0.185, -0.70, zc), float3(0.3, 0.235, 0.125));
- d = min(d, s_facet_capsule(p, float3(0.0, -0.52, zc), float3(0.0, -0.10, zc), 0.098, 0.3));
- d = min(d, s_facet_capsule(p, float3(0.17, -0.57, zc + 0.012), float3(0.17, -0.41, zc + 0.045), 0.086, 0.1));
- d = min(d, s_facet_capsule(p, float3(0.31, -0.59, zc + 0.01), float3(0.31, -0.45, zc + 0.04), 0.08, 0.5));
- d = min(d, s_facet_capsule(p, float3(0.435, -0.625, zc + 0.005), float3(0.435, -0.52, zc + 0.03), 0.07, 0.2));
- return min(d, s_facet_capsule(p, float3(0.03, -0.77, zc + 0.03), float3(-0.165, -0.60, zc + 0.065), 0.082, 0.7));
+ float best = 1e9;
+ float g = 1.0;
+ for (int k = shape == 0 ? 0 : 2; k < (shape == 0 ? 2 : 8); k++)
+ {
+ float e1 = -1e9;
+ float e2 = -1e9;
+ float3 n1 = float3(0.0);
+ float3 n2 = float3(0.0);
+ for (int i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++)
+ {
+ float e = dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w;
+ if (e > e1)
+ {
+ e2 = e1;
+ n2 = n1;
+ e1 = e;
+ n1 = GEM_PLANES[i].xyz;
+ }
+ else if (e > e2)
+ {
+ e2 = e;
+ n2 = GEM_PLANES[i].xyz;
+ }
+ }
+ if (e1 < best)
+ {
+ best = e1;
+ float s = length(cross(n1, n2));
+ g = (1.0 - smoothstep(0.0, 0.006, (e1 - e2) / max(s, 0.05))) * smoothstep(0.15, 0.6, s);
+ }
+ }
+ return g;
}
static float2 sculpt_proto(float3 p, int theme, int shape)
@@ -1047,7 +1129,7 @@ static float2 sculpt_proto(float3 p, int theme, int shape)
}
if (theme == 1)
{
- return float2(shape == 0 ? s_gem_arrow(p) : s_crystal_hand(p), 8.0);
+ return float2(s_gem_cut(p, shape), 8.0);
}
return s_rimmed(p, theme, shape);
}
@@ -1234,28 +1316,30 @@ static float3 model_env(float3 d, float rough, float3 l, float3 fill)
static float3 s_gem(float k)
{
k = saturate(k) * 3.0;
- float3 a = s_lin(0.20, 0.95, 1.0);
- float3 b = s_lin(0.15, 0.42, 1.0);
- float3 c = s_lin(0.45, 0.25, 0.95);
- float3 d = s_lin(0.88, 0.50, 1.0);
+ float3 a = s_lin(0.0, 0.95, 1.0);
+ float3 b = s_lin(0.10, 0.50, 1.0);
+ float3 c = s_lin(0.12, 0.22, 0.92);
+ float3 d = s_lin(0.55, 0.30, 1.0);
if (k < 1.0) return mix(a, b, k);
if (k < 2.0) return mix(b, c, k - 1.0);
return mix(c, d, k - 2.0);
}
-static float3 model_shade_crystal(float3 n, float3 rd, float3 L, float fall, float3 l, float3 fill)
+static float3 model_shade_crystal(float3 n, float3 rd, float3 L, float fall, float3 l, float3 fill, float glint)
{
float cosi = saturate(dot(-rd, n));
float F = 0.04 + 0.96 * pow(1.0 - cosi, 5.0);
float3 t = refract(rd, n, 1.0 / 1.6);
- float k = 0.42 + 0.9 * dot(float2(n.x, -n.y), float2(0.7557, -0.6549))
- + 0.6 * dot(float2(t.x, -t.y), float2(0.6, -0.8));
+ float k = 0.4 + 1.2 * dot(float2(n.x, -n.y), float2(0.7557, -0.6549))
+ + 0.5 * dot(float2(t.x, -t.y), float2(0.6, -0.8))
+ + 0.3 * sin(11.0 * n.x - 8.0 * n.y + 3.0 * n.z);
float3 body = float3(s_gem(k - 0.08).r, s_gem(k).g, s_gem(k + 0.08).b);
- float3 col = body * (0.1 + 1.8 * fall * pow(max(dot(n, L), 0.0), 2.5));
- col += body * model_env(reflect(t, float3(0.0, 0.0, 1.0)) * float3(1.0, 1.0, -1.0), 0.15, l, fill) * 0.5;
- col += pow(max(dot(reflect(rd, n), L), 0.0), 30.0) * 2.0;
+ float3 col = body * (0.45 + 0.65 * fall * pow(max(dot(n, L), 0.0), 1.5));
+ col += body * model_env(reflect(t, float3(0.0, 0.0, 1.0)) * float3(1.0, 1.0, -1.0), 0.15, l, fill) * 0.25;
+ col += pow(max(dot(reflect(rd, n), L), 0.0), 40.0) * 1.4;
col += model_env(reflect(rd, n), 0.05, l, fill) * F;
col += s_lin(0.5, 0.9, 1.0) * pow(1.0 - cosi, 4.0) * 0.6;
+ col += s_lin(0.7, 0.95, 1.0) * glint * (0.15 + 0.6 * fall);
return col;
}
@@ -1284,7 +1368,8 @@ static float3 model_shade(float3 q, float3 n, float3 rd, float3 L, float fall, f
int id = sculpt_id(layer);
if (id > 0 && (id - 1) / 2 == 1)
{
- return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill));
+ float glint = s_gem_glint(sculpt_point(q, layer), (id - 1) % 2);
+ return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill, glint));
}
SculptMat m;
float gloss = 1.0;
diff --git a/crates/compositor/src/vk_shaders/layer.wgsl b/crates/compositor/src/vk_shaders/layer.wgsl
index 616476b59..3a97bf932 100644
--- a/crates/compositor/src/vk_shaders/layer.wgsl
+++ b/crates/compositor/src/vk_shaders/layer.wgsl
@@ -610,7 +610,6 @@ fn sculpt_id() -> i32 {
const SCULPT_SCALE: f32 = 0.85;
const SCULPT_HOVER: f32 = 0.05;
const SCULPT_VOX: f32 = 0.0625;
-const SCULPT_HAND_ZC: f32 = 0.185;
const SCULPT_ZREF_ARROW: f32 = 0.2;
const SCULPT_ZREF_HAND: f32 = 0.185;
const SCULPT_LAMP_DIST: f32 = 1.9;
@@ -942,74 +941,153 @@ fn s_pixel_hand_dist(p: vec2<f32>) -> f32 {
return d;
}
-fn s_gem_edge(p: vec3<f32>, a: vec2<f32>, b: vec2<f32>, z0: f32) -> f32 {
- let e = b - a;
- let len = length(e);
- let d = e / len;
- let q = p.xy - a;
- let dist = dot(q, vec2<f32>(-d.y, d.x));
- let along = abs(dot(q, d) - 0.5 * len);
- let z = p.z - z0;
- let girdle = (z - 0.035 - 2.2 * dist) * 0.4138;
- let crown = (z - 0.07 - 0.6 * dist + 0.18 * along) * 0.8438;
- return max(-dist, max(girdle, crown));
-}
-
-fn s_gem_arrow(p: vec3<f32>) -> f32 {
- let z0 = SCULPT_HOVER + 0.03;
- let slab = max(p.z - z0 - 0.2, z0 - 0.03 - p.z);
- let head = max(slab, max(s_gem_edge(p, vec2<f32>(-0.02, 0.03), vec2<f32>(-0.02, -0.88), z0),
- max(s_gem_edge(p, vec2<f32>(-0.02, -0.88), vec2<f32>(0.66, -0.61), z0),
- s_gem_edge(p, vec2<f32>(0.66, -0.61), vec2<f32>(-0.02, 0.03), z0))));
- let tail = max(slab, max(max(s_gem_edge(p, vec2<f32>(0.215, -0.665), vec2<f32>(0.37, -1.0), z0),
- s_gem_edge(p, vec2<f32>(0.37, -1.0), vec2<f32>(0.53, -0.93), z0)),
- max(s_gem_edge(p, vec2<f32>(0.53, -0.93), vec2<f32>(0.38, -0.60), z0),
- s_gem_edge(p, vec2<f32>(0.38, -0.60), vec2<f32>(0.215, -0.665), z0))));
- return min(head, tail);
-}
-
-fn s_facet_capsule(p: vec3<f32>, a: vec3<f32>, b: vec3<f32>, r: f32, spin: f32) -> f32 {
- let u = normalize(b - a);
- let v = normalize(cross(u, vec3<f32>(0.0, 0.0, 1.0)));
- let w = cross(u, v);
- let q = p - b;
- let h = dot(q, u);
- let rad = vec2<f32>(dot(q, v), dot(q, w));
- var d = max(h - r, -dot(p - a, u) - r);
- for (var k = 0; k < 6; k++) {
- let an = spin + f32(k) * 1.0471976;
- let s = dot(rad, vec2<f32>(cos(an), sin(an)));
- d = max(d, s - r);
- d = max(d, dot(rad, vec2<f32>(cos(an + 0.5236), sin(an + 0.5236))) * 0.8660 + h * 0.5 - r);
- d = max(d, s * 0.5 + h * 0.8660 - r);
- }
- return d;
-}
-
-const SCULPT_FACETS = array<vec3<f32>, 10>(
- vec3<f32>(1.0, 0.0, 0.0), vec3<f32>(0.0, 1.0, 0.0), vec3<f32>(0.0, 0.0, 1.0),
- vec3<f32>(0.7071, 0.7071, 0.0), vec3<f32>(0.7071, 0.0, 0.7071), vec3<f32>(0.0, 0.7071, 0.7071),
- vec3<f32>(0.5774, 0.5774, 0.5774), vec3<f32>(0.4472, 0.0, 0.8944), vec3<f32>(0.0, 0.4472, 0.8944),
- vec3<f32>(0.3015, 0.3015, 0.9045)
+// Prism Glow : table générée par scripts/generate-prism-glow-gem.mjs (cf. HLSL).
+// <prism-glow-gem>
+const GEM_PLANES = array<vec4<f32>, 182>(
+ vec4<f32>(0.0000, 0.0000, 1.0000, 0.2800), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(-1.0000, 0.0000, 0.0000, 0.0200), vec4<f32>(-0.9104, 0.0000, 0.4138, 0.0658),
+ vec4<f32>(-0.5085, -0.1525, 0.8475, 0.2021), vec4<f32>(-0.5085, 0.1525, 0.8475, 0.0725),
+ vec4<f32>(0.3690, -0.9294, 0.0000, 0.8105), vec4<f32>(0.3360, -0.8461, 0.4138, 0.7854),
+ vec4<f32>(0.3294, -0.4163, 0.8475, 0.5427), vec4<f32>(0.0459, -0.5289, 0.8475, 0.5358),
+ vec4<f32>(0.6854, 0.7282, 0.0000, 0.0081), vec4<f32>(0.6239, 0.6629, 0.4138, 0.0550),
+ vec4<f32>(0.2374, 0.4748, 0.8475, 0.0654), vec4<f32>(0.4596, 0.2657, 0.8475, 0.1971),
+ vec4<f32>(0.0000, 0.0000, 1.0000, 0.2800), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(-0.9076, -0.4199, 0.0000, 0.0841), vec4<f32>(-0.8262, -0.3823, 0.4138, 0.1242),
+ vec4<f32>(-0.3974, -0.3520, 0.8475, 0.3039), vec4<f32>(-0.5255, -0.0751, 0.8475, 0.0359),
+ vec4<f32>(0.4008, -0.9162, 0.0000, 1.0645), vec4<f32>(0.3649, -0.8340, 0.4138, 1.0166),
+ vec4<f32>(0.3436, -0.4047, 0.8475, 0.6723), vec4<f32>(0.0641, -0.5270, 0.8475, 0.6645),
+ vec4<f32>(0.9104, 0.4138, 0.0000, 0.0977), vec4<f32>(0.8288, 0.3767, 0.4138, 0.1365),
+ vec4<f32>(0.3998, 0.3493, 0.8475, 0.0418), vec4<f32>(0.5260, 0.0715, 0.8475, 0.3117),
+ vec4<f32>(-0.3665, 0.9304, 0.0000, -0.6975), vec4<f32>(-0.3337, 0.8470, 0.4138, -0.5874),
+ vec4<f32>(-0.3283, 0.4172, 0.8475, -0.2344), vec4<f32>(-0.0444, 0.5290, 0.8475, -0.2207),
+ vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500), vec4<f32>(0.0000, -1.0000, 0.0000, 0.7200),
+ vec4<f32>(-1.0000, 0.0000, 0.0000, 0.1400), vec4<f32>(1.0000, 0.0000, 0.0000, 0.1400),
+ vec4<f32>(0.7682, 0.6402, 0.0000, 0.0499), vec4<f32>(0.0000, 1.0000, 0.0000, 0.0000),
+ vec4<f32>(-0.7682, 0.6402, 0.0000, 0.0499), vec4<f32>(0.0000, -0.8575, 0.5145, 0.6946),
+ vec4<f32>(-0.8575, 0.0000, 0.5145, 0.1972), vec4<f32>(0.8575, 0.0000, 0.5145, 0.1972),
+ vec4<f32>(0.6820, 0.5683, 0.4603, 0.1134), vec4<f32>(0.7050, 0.4755, 0.5263, 0.1348),
+ vec4<f32>(0.0000, 0.9119, 0.4104, 0.0616), vec4<f32>(-0.6820, 0.5683, 0.4603, 0.1134),
+ vec4<f32>(-0.7050, 0.4755, 0.5263, 0.1348), vec4<f32>(0.0000, -0.4657, 0.8849, 0.4983),
+ vec4<f32>(-0.6727, 0.0000, 0.7399, 0.2220), vec4<f32>(0.6727, 0.0000, 0.7399, 0.2220),
+ vec4<f32>(0.5772, 0.0452, 0.8153, 0.2220), vec4<f32>(-0.5772, 0.0452, 0.8153, 0.2220),
+ vec4<f32>(0.0000, 0.1092, 0.9940, 0.2436), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(0.0000, -1.0000, 0.0000, 0.6800), vec4<f32>(-1.0000, 0.0000, 0.0000, -0.1200),
+ vec4<f32>(1.0000, 0.0000, 0.0000, 0.2900), vec4<f32>(0.7809, 0.6247, 0.0000, 0.0141),
+ vec4<f32>(0.0000, 1.0000, 0.0000, -0.2900), vec4<f32>(-0.7071, 0.7071, 0.0000, -0.3182),
+ vec4<f32>(0.0000, -0.8137, 0.5812, 0.6405), vec4<f32>(-0.8269, 0.0000, 0.5623, -0.0149),
+ vec4<f32>(-0.7483, -0.1548, 0.6451, 0.1122), vec4<f32>(0.8269, 0.0000, 0.5623, 0.3242),
+ vec4<f32>(0.7483, -0.1548, 0.6451, 0.4190), vec4<f32>(0.6354, 0.5083, 0.5812, 0.0986),
+ vec4<f32>(0.8115, 0.0175, 0.5840, 0.3170), vec4<f32>(0.0000, 0.8240, 0.5665, -0.1540),
+ vec4<f32>(0.0970, 0.7938, 0.6003, -0.1159), vec4<f32>(-0.5754, 0.5754, 0.5812, -0.1717),
+ vec4<f32>(-0.0803, 0.7997, 0.5950, -0.1555), vec4<f32>(-0.8112, 0.0171, 0.5845, -0.0153),
+ vec4<f32>(0.0000, -0.7270, 0.6866, 0.6032), vec4<f32>(0.5553, 0.4442, 0.7031, 0.1223),
+ vec4<f32>(0.5988, 0.1571, 0.7853, 0.2492), vec4<f32>(-0.4961, 0.4961, 0.7126, -0.1089),
+ vec4<f32>(-0.5844, 0.1591, 0.7957, 0.0083), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(0.0000, -1.0000, 0.0000, 0.6800), vec4<f32>(-1.0000, 0.0000, 0.0000, -0.2700),
+ vec4<f32>(1.0000, 0.0000, 0.0000, 0.4400), vec4<f32>(0.7809, 0.6247, 0.0000, 0.0968),
+ vec4<f32>(0.0000, 1.0000, 0.0000, -0.3450), vec4<f32>(-0.7071, 0.7071, 0.0000, -0.4632),
+ vec4<f32>(0.0000, -0.8137, 0.5812, 0.6405), vec4<f32>(-0.8160, 0.0000, 0.5780, -0.1336),
+ vec4<f32>(-0.7620, -0.1270, 0.6350, -0.0241), vec4<f32>(0.8160, 0.0000, 0.5780, 0.4458),
+ vec4<f32>(0.7620, -0.1270, 0.6350, 0.5169), vec4<f32>(0.6354, 0.5083, 0.5812, 0.1660),
+ vec4<f32>(0.8133, 0.0035, 0.5818, 0.4437), vec4<f32>(0.0000, 0.8240, 0.5665, -0.1993),
+ vec4<f32>(0.0970, 0.7938, 0.6003, -0.1450), vec4<f32>(-0.5754, 0.5754, 0.5812, -0.2897),
+ vec4<f32>(-0.0803, 0.7997, 0.5950, -0.2116), vec4<f32>(-0.8132, 0.0034, 0.5819, -0.1336),
+ vec4<f32>(0.0000, -0.7944, 0.6075, 0.6327), vec4<f32>(0.5553, 0.4442, 0.7031, 0.1812),
+ vec4<f32>(0.5984, 0.1651, 0.7840, 0.3267), vec4<f32>(-0.4961, 0.4961, 0.7126, -0.2106),
+ vec4<f32>(-0.5832, 0.1673, 0.7949, -0.0912), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(0.0000, -1.0000, 0.0000, 0.7000), vec4<f32>(-1.0000, 0.0000, 0.0000, -0.4200),
+ vec4<f32>(1.0000, 0.0000, 0.0000, 0.5850), vec4<f32>(0.7809, 0.6247, 0.0000, 0.1757),
+ vec4<f32>(0.0000, 1.0000, 0.0000, -0.4000), vec4<f32>(-0.7071, 0.7071, 0.0000, -0.6081),
+ vec4<f32>(0.0000, -0.8137, 0.5812, 0.6568), vec4<f32>(-0.8209, 0.0000, 0.5711, -0.2591),
+ vec4<f32>(-0.7253, -0.1978, 0.6594, -0.0673), vec4<f32>(0.8137, 0.0000, 0.5812, 0.5632),
+ vec4<f32>(0.6354, 0.5083, 0.5812, 0.2302), vec4<f32>(0.0000, 0.8240, 0.5665, -0.2446),
+ vec4<f32>(0.0970, 0.7938, 0.6003, -0.1746), vec4<f32>(-0.5754, 0.5754, 0.5812, -0.4077),
+ vec4<f32>(-0.1042, 0.7945, 0.5983, -0.2760), vec4<f32>(-0.8119, 0.0128, 0.5837, -0.2591),
+ vec4<f32>(0.0000, -0.7761, 0.6306, 0.6405), vec4<f32>(0.8000, 0.0000, 0.6000, 0.5590),
+ vec4<f32>(0.5553, 0.4442, 0.7031, 0.2372), vec4<f32>(0.5976, 0.1766, 0.7821, 0.3983),
+ vec4<f32>(-0.5159, 0.5159, 0.6838, -0.3354), vec4<f32>(-0.6148, 0.1737, 0.7693, -0.2095),
+ vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500), vec4<f32>(-0.6163, -0.7875, 0.0000, 0.7101),
+ vec4<f32>(-0.9985, -0.0555, 0.0000, 0.3938), vec4<f32>(0.9950, -0.0995, 0.0000, -0.0498),
+ vec4<f32>(0.7926, 0.6097, 0.0000, -0.3841), vec4<f32>(0.0000, 1.0000, 0.0000, -0.3700),
+ vec4<f32>(-0.7593, 0.6508, 0.0000, -0.0054), vec4<f32>(-0.4930, -0.6300, 0.6000, 0.6581),
+ vec4<f32>(-0.8418, -0.0468, 0.5378, 0.4127), vec4<f32>(-0.7161, -0.2919, 0.6340, 0.5339),
+ vec4<f32>(0.8194, -0.0819, 0.5673, 0.0441), vec4<f32>(0.5064, -0.3383, 0.7932, 0.3238),
+ vec4<f32>(0.6341, 0.4878, 0.6000, -0.2173), vec4<f32>(0.7890, 0.0096, 0.6143, 0.0085),
+ vec4<f32>(0.0000, 0.8000, 0.6000, -0.2060), vec4<f32>(-0.6074, 0.5206, 0.6000, 0.0857),
+ vec4<f32>(-0.7848, 0.0612, 0.6167, 0.3560), vec4<f32>(-0.4497, -0.5746, 0.6839, 0.6262),
+ vec4<f32>(-0.4725, -0.5166, 0.7140, 0.6044), vec4<f32>(0.5943, 0.4571, 0.6617, -0.1848),
+ vec4<f32>(0.5974, 0.2873, 0.7487, -0.0822), vec4<f32>(0.0000, 0.7526, 0.6585, -0.1759),
+ vec4<f32>(-0.5348, 0.4584, 0.7099, 0.1099), vec4<f32>(-0.6276, 0.2044, 0.7513, 0.2637),
+ vec4<f32>(-0.3077, -0.0453, 0.9504, 0.3548), vec4<f32>(0.0000, 0.0000, -1.0000, -0.0500),
+ vec4<f32>(-0.8384, -0.5450, 0.0000, 0.6121), vec4<f32>(-0.4138, 0.9104, 0.0000, -0.4055),
+ vec4<f32>(0.0000, -1.0000, 0.0000, 1.0000), vec4<f32>(0.7853, -0.6192, 0.0000, 0.9176),
+ vec4<f32>(1.0000, 0.0000, 0.0000, 0.5850), vec4<f32>(0.0566, 0.9984, 0.0000, -0.5060),
+ vec4<f32>(-0.6937, -0.4509, 0.5616, 0.5907), vec4<f32>(-0.2912, 0.6406, 0.7105, -0.1788),
+ vec4<f32>(-0.3872, 0.3638, 0.8472, 0.0404), vec4<f32>(-0.4241, 0.2711, 0.8641, 0.1111),
+ vec4<f32>(0.0000, -0.6690, 0.7433, 0.7805), vec4<f32>(-0.0595, -0.6308, 0.7736, 0.7516),
+ vec4<f32>(-0.4384, -0.4359, 0.7860, 0.5888), vec4<f32>(0.6422, -0.5064, 0.5754, 0.8368),
+ vec4<f32>(0.0108, -0.6477, 0.7618, 0.7661), vec4<f32>(0.3229, -0.5208, 0.7903, 0.7620),
+ vec4<f32>(0.6912, 0.0000, 0.7226, 0.5128), vec4<f32>(0.5899, -0.2666, 0.7622, 0.6567),
+ vec4<f32>(0.0435, 0.7663, 0.6410, -0.2922), vec4<f32>(0.1017, 0.6072, 0.7880, -0.1502),
+ vec4<f32>(0.4339, 0.3087, 0.8464, 0.2141), vec4<f32>(-0.4000, 0.3006, 0.8658, 0.0864),
+ vec4<f32>(-0.2957, -0.3907, 0.8717, 0.5519), vec4<f32>(0.0239, -0.6091, 0.7927, 0.7392),
+ vec4<f32>(0.1686, -0.4712, 0.8657, 0.6718), vec4<f32>(0.1055, 0.5915, 0.7994, -0.1370),
+ vec4<f32>(0.1450, 0.5209, 0.8412, -0.0674), vec4<f32>(0.0152, -0.1336, 0.9909, 0.3808),
+ vec4<f32>(-0.0779, -0.2355, 0.9688, 0.4421), vec4<f32>(-0.1668, -0.2549, 0.9525, 0.4530),
+ vec4<f32>(0.1324, -0.1566, 0.9787, 0.4232), vec4<f32>(0.1566, -0.1906, 0.9691, 0.4552)
+);
+const GEM_PIECE = array<i32, 9>(0, 14, 32, 53, 77, 101, 124, 149, 182);
+const GEM_BOX = array<vec3<f32>, 4>(
+ vec3<f32>(0.320, -0.485, 0.165),
+ vec3<f32>(0.350, 0.525, 0.125),
+ vec3<f32>(0.107, -0.500, 0.175),
+ vec3<f32>(0.487, 0.510, 0.135)
);
+// </prism-glow-gem>
-fn s_facet_ellipsoid(p: vec3<f32>, r: vec3<f32>) -> f32 {
- let q = abs(p);
- var d = -1e9;
- for (var i = 0; i < 10; i++) {
- d = max(d, dot(q, SCULPT_FACETS[i]) - length(r * SCULPT_FACETS[i]));
+fn s_gem_cut(p: vec3<f32>, shape: i32) -> f32 {
+ let far = length(max(abs(p - GEM_BOX[2 * shape]) - GEM_BOX[2 * shape + 1], vec3<f32>(0.0)));
+ if far > 0.05 {
+ return far;
+ }
+ var d = 1e9;
+ for (var k = select(2, 0, shape == 0); k < select(8, 2, shape == 0); k++) {
+ var e = -1e9;
+ for (var i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++) {
+ e = max(e, dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w);
+ }
+ d = min(d, e);
}
return d;
}
-fn s_crystal_hand(p: vec3<f32>) -> f32 {
- let zc = SCULPT_HAND_ZC;
- var d = s_facet_ellipsoid(p - vec3<f32>(0.185, -0.70, zc), vec3<f32>(0.3, 0.235, 0.125));
- d = min(d, s_facet_capsule(p, vec3<f32>(0.0, -0.52, zc), vec3<f32>(0.0, -0.10, zc), 0.098, 0.3));
- d = min(d, s_facet_capsule(p, vec3<f32>(0.17, -0.57, zc + 0.012), vec3<f32>(0.17, -0.41, zc + 0.045), 0.086, 0.1));
- d = min(d, s_facet_capsule(p, vec3<f32>(0.31, -0.59, zc + 0.01), vec3<f32>(0.31, -0.45, zc + 0.04), 0.08, 0.5));
- d = min(d, s_facet_capsule(p, vec3<f32>(0.435, -0.625, zc + 0.005), vec3<f32>(0.435, -0.52, zc + 0.03), 0.07, 0.2));
- return min(d, s_facet_capsule(p, vec3<f32>(0.03, -0.77, zc + 0.03), vec3<f32>(-0.165, -0.60, zc + 0.065), 0.082, 0.7));
+fn s_gem_glint(p: vec3<f32>, shape: i32) -> f32 {
+ var best = 1e9;
+ var g = 1.0;
+ for (var k = select(2, 0, shape == 0); k < select(8, 2, shape == 0); k++) {
+ var e1 = -1e9;
+ var e2 = -1e9;
+ var n1 = vec3<f32>(0.0);
+ var n2 = vec3<f32>(0.0);
+ for (var i = GEM_PIECE[k]; i < GEM_PIECE[k + 1]; i++) {
+ let e = dot(p, GEM_PLANES[i].xyz) - GEM_PLANES[i].w;
+ if e > e1 {
+ e2 = e1;
+ n2 = n1;
+ e1 = e;
+ n1 = GEM_PLANES[i].xyz;
+ } else if e > e2 {
+ e2 = e;
+ n2 = GEM_PLANES[i].xyz;
+ }
+ }
+ if e1 < best {
+ best = e1;
+ let s = length(cross(n1, n2));
+ g = (1.0 - smoothstep(0.0, 0.006, (e1 - e2) / max(s, 0.05))) * smoothstep(0.15, 0.6, s);
+ }
+ }
+ return g;
}
fn sculpt_proto(p: vec3<f32>, theme: i32, shape: i32) -> vec2<f32> {
@@ -1017,7 +1095,7 @@ fn sculpt_proto(p: vec3<f32>, theme: i32, shape: i32) -> vec2<f32> {
return s_voxels(p, shape);
}
if theme == 1 {
- return vec2<f32>(select(s_crystal_hand(p), s_gem_arrow(p), shape == 0), 8.0);
+ return vec2<f32>(s_gem_cut(p, shape), 8.0);
}
return s_rimmed(p, theme, shape);
}
@@ -1185,10 +1263,10 @@ fn model_env(d: vec3<f32>, rough: f32, l: vec3<f32>, fill: vec3<f32>) -> vec3<f3
fn s_gem(k0: f32) -> vec3<f32> {
let k = saturate(k0) * 3.0;
- let a = s_lin(0.20, 0.95, 1.0);
- let b = s_lin(0.15, 0.42, 1.0);
- let c = s_lin(0.45, 0.25, 0.95);
- let d = s_lin(0.88, 0.50, 1.0);
+ let a = s_lin(0.0, 0.95, 1.0);
+ let b = s_lin(0.10, 0.50, 1.0);
+ let c = s_lin(0.12, 0.22, 0.92);
+ let d = s_lin(0.55, 0.30, 1.0);
if k < 1.0 {
return mix(a, b, k);
}
@@ -1198,18 +1276,21 @@ fn s_gem(k0: f32) -> vec3<f32> {
return mix(c, d, k - 2.0);
}
-fn model_shade_crystal(n: vec3<f32>, rd: vec3<f32>, L: vec3<f32>, fall: f32, l: vec3<f32>, fill: vec3<f32>) -> vec3<f32> {
+fn model_shade_crystal(n: vec3<f32>, rd: vec3<f32>, L: vec3<f32>, fall: f32, l: vec3<f32>, fill: vec3<f32>,
+ glint: f32) -> vec3<f32> {
let cosi = saturate(dot(-rd, n));
let F = 0.04 + 0.96 * pow(1.0 - cosi, 5.0);
let t = refract(rd, n, 1.0 / 1.6);
- let k = 0.42 + 0.9 * dot(vec2<f32>(n.x, -n.y), vec2<f32>(0.7557, -0.6549))
- + 0.6 * dot(vec2<f32>(t.x, -t.y), vec2<f32>(0.6, -0.8));
+ let k = 0.4 + 1.2 * dot(vec2<f32>(n.x, -n.y), vec2<f32>(0.7557, -0.6549))
+ + 0.5 * dot(vec2<f32>(t.x, -t.y), vec2<f32>(0.6, -0.8))
+ + 0.3 * sin(11.0 * n.x - 8.0 * n.y + 3.0 * n.z);
let body = vec3<f32>(s_gem(k - 0.08).r, s_gem(k).g, s_gem(k + 0.08).b);
- var col = body * (0.1 + 1.8 * fall * pow(max(dot(n, L), 0.0), 2.5));
- col = col + body * model_env(reflect(t, vec3<f32>(0.0, 0.0, 1.0)) * vec3<f32>(1.0, 1.0, -1.0), 0.15, l, fill) * 0.5;
- col = col + vec3<f32>(pow(max(dot(reflect(rd, n), L), 0.0), 30.0) * 2.0);
+ var col = body * (0.45 + 0.65 * fall * pow(max(dot(n, L), 0.0), 1.5));
+ col = col + body * model_env(reflect(t, vec3<f32>(0.0, 0.0, 1.0)) * vec3<f32>(1.0, 1.0, -1.0), 0.15, l, fill) * 0.25;
+ col = col + vec3<f32>(pow(max(dot(reflect(rd, n), L), 0.0), 40.0) * 1.4);
col = col + model_env(reflect(rd, n), 0.05, l, fill) * F;
col = col + s_lin(0.5, 0.9, 1.0) * pow(1.0 - cosi, 4.0) * 0.6;
+ col = col + s_lin(0.7, 0.95, 1.0) * glint * (0.15 + 0.6 * fall);
return col;
}
@@ -1232,7 +1313,8 @@ fn model_shade(q: vec3<f32>, n: vec3<f32>, rd: vec3<f32>, L: vec3<f32>, fall: f3
l: vec3<f32>, fill: vec3<f32>) -> vec3<f32> {
let id = sculpt_id();
if id > 0 && (id - 1) / 2 == 1 {
- return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill));
+ let glint = s_gem_glint(sculpt_point(q), (id - 1) % 2);
+ return model_tonemap(model_shade_crystal(n, rd, L, fall, l, fill, glint));
}
var m: SculptMat;
var gloss = 1.0;
diff --git a/design/cursors/3d-direction.md b/design/cursors/3d-direction.md
index 4deee0245..ed7c55d99 100644
--- a/design/cursors/3d-direction.md
+++ b/design/cursors/3d-direction.md
@@ -13,7 +13,7 @@ compositor's beveled extrusion.
| Theme | Arrow model | Hand model |
| --- | --- | --- |
| Studio Ink | Black rim, a raised ivory band, a recessed satin black field. | Ivory glove cushion in a black rim, black ridges between the fingers. |
-| Prism Glow | Cut crystal: flat facets, a polygonal silhouette, cyan to violet dispersion. | The same glove cut into faceted fingers and palm. |
+| Prism Glow | Cut crystal: flat facets, a polygonal silhouette, cyan, deep blue and violet facets with bright edges. | A cut gem after `3d-concept.png`: an index column, three fingers side by side, the thumb and a faceted palm on one slab. |
| Pop Coral | Coral cushion in a navy rim, a yellow layer behind it offset down-left, two yellow click dashes. | Yellow glove cushion in a navy rim, two coral click dashes. |
| Pixel Candy | Beveled voxels: a pink face with mint and pale pink edges, purple blocks one step behind. | Voxel glove with the same colours and purple back layer. |
| Star Sprout | Glossy mint cushion framed by the navy outline of its drawing, carrying a star with a face and two leaves. | Ivory glove cushion in the same navy frame, navy ridges between the fingers, a mint cuff and the same star. |
@@ -37,4 +37,8 @@ click and size changes.
To change a model, edit it in all three shaders (`sculpt_proto`,
`sculpt_material`) and keep `sculpt.rs` in step: its boxes must contain the
shapes, and a test checks that the shaders mirror its constants. Pixel Candy's
-arrow voxels are sampled from the arrow polygon; `sculpt.rs` says how.
+arrow voxels are sampled from the arrow polygon; `sculpt.rs` says how. Prism
+Glow's pieces are convex polyhedra described in
+`scripts/generate-prism-glow-gem.mjs`, which writes their planes into the three
+shaders; change a piece there and run it, and a test checks the three tables
+agree.
diff --git a/docs/3d-effects-v2.md b/docs/3d-effects-v2.md
index 732a9561b..e1103e551 100644
--- a/docs/3d-effects-v2.md
+++ b/docs/3d-effects-v2.md
@@ -295,6 +295,11 @@ la couleur du trait, un coussin de couleur dedans (`s_rimmed`). Le PNG du thème
2D. En 3D, la scène nomme le modèle ; `sculpt.rs` en tient la boîte, qui pose le hotspot (pointe
de la flèche, bout de l'index), règle la garde au sol et borne la boîte de dessin. Emplacement du
cbuffer : `trail_a` = [modèle, épaisseur sous z = 0, hauteur au-dessus, 0] (`cursor_model_cb`).
+Les pièces de Prism Glow (tête et queue de la flèche ; index, trois doigts, pouce et paume de la
+main) sont des polyèdres convexes, le max des plans de leurs faces : une table que
+`scripts/generate-prism-glow-gem.mjs` calcule (enveloppe convexe de points posés à la main) et
+écrit dans les trois shaders. Le verre luit de lui-même, chaque facette prend sa teinte de son
+orientation, et les arêtes vives s'allument (`s_gem_glint`).
- **Éclairage**, sprites extrudés compris : une lampe proche en haut à gauche, qui met un dégradé
et un reflet même sur une face plane ; une lumière d'appoint faible ; le côté ombré teinté par
diff --git a/scripts/generate-prism-glow-gem.mjs b/scripts/generate-prism-glow-gem.mjs
new file mode 100644
index 000000000..3f0a90ce0
--- /dev/null
+++ b/scripts/generate-prism-glow-gem.mjs
@@ -0,0 +1,309 @@
+// Cut-gem geometry of the Prism Glow 3D cursors (mode 15, theme 1).
+// Run with `node scripts/generate-prism-glow-gem.mjs` after changing a piece below: it rewrites
+// the GEM_PLANES, GEM_PIECE and GEM_BOX tables of the three compositor shaders, between their
+// `<prism-glow-gem>` markers.
+//
+// Every piece is a convex polyhedron, stored as the planes of its faces (unit outward normal,
+// offset): the shader takes the max of a piece's planes and the min over the pieces. Coordinates
+// are the prototype frame of crates/compositor/src/sculpt.rs: cursor height 1, x right, y UP,
+// z toward the camera, hotspot at the origin, screen at z = 0, underside of every model at
+// SCULPT_HOVER.
+
+import { readFile, writeFile } from "node:fs/promises";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+
+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
+const SHADERS = path.join(ROOT, "crates", "compositor", "src");
+const HOVER = 0.05;
+
+// The arrow: a head and a tail, each a slab whose every edge carries a wall, a steep girdle
+// facet and two crown facets that meet over the middle of the edge.
+const ARROW_Z0 = HOVER + 0.03;
+const ARROW = [
+ [
+ [-0.02, 0.03],
+ [-0.02, -0.88],
+ [0.66, -0.61],
+ ],
+ [
+ [0.215, -0.665],
+ [0.37, -1.0],
+ [0.53, -0.93],
+ [0.38, -0.6],
+ ],
+];
+
+// The hand, after the reference sheet (design/cursors/3d-concept.png): an index column, three
+// fingers side by side, the thumb and the palm, all on the same slab. A piece is its outline
+// (convex, counter-clockwise), the top of its wall `zg`, a crown ring inset by `c` at `zc`, and
+// the points its facets rise to. The fingers stand higher than the palm where they overlap it,
+// so their crease with the palm is the knuckle line.
+const HAND = [
+ {
+ name: "index",
+ outline: [
+ [-0.14, -0.72],
+ [0.14, -0.72],
+ [0.14, -0.09],
+ [0.065, 0.0],
+ [-0.065, 0.0],
+ [-0.14, -0.09],
+ ],
+ zg: 0.15,
+ c: 0.03,
+ zc: 0.2,
+ tops: [
+ [-0.035, -0.045, 0.25],
+ [0.035, -0.045, 0.25],
+ [0.0, -0.5, 0.3],
+ ],
+ },
+ {
+ name: "middle",
+ outline: [
+ [0.12, -0.68],
+ [0.29, -0.68],
+ [0.29, -0.34],
+ [0.25, -0.29],
+ [0.16, -0.29],
+ [0.12, -0.33],
+ ],
+ zg: 0.15,
+ c: 0.025,
+ zc: 0.185,
+ tops: [
+ [0.205, -0.345, 0.23],
+ [0.205, -0.57, 0.275],
+ ],
+ },
+ {
+ name: "ring",
+ outline: [
+ [0.27, -0.68],
+ [0.44, -0.68],
+ [0.44, -0.395],
+ [0.4, -0.345],
+ [0.31, -0.345],
+ [0.27, -0.385],
+ ],
+ zg: 0.15,
+ c: 0.025,
+ zc: 0.185,
+ tops: [
+ [0.355, -0.4, 0.23],
+ [0.355, -0.59, 0.27],
+ ],
+ },
+ {
+ name: "pinky",
+ outline: [
+ [0.42, -0.7],
+ [0.585, -0.7],
+ [0.585, -0.45],
+ [0.545, -0.4],
+ [0.46, -0.4],
+ [0.42, -0.44],
+ ],
+ zg: 0.15,
+ c: 0.025,
+ zc: 0.185,
+ tops: [
+ [0.5, -0.455, 0.23],
+ [0.5, -0.61, 0.265],
+ ],
+ },
+ {
+ name: "thumb",
+ outline: [
+ [-0.36, -0.62],
+ [-0.13, -0.8],
+ [-0.1, -0.5],
+ [-0.2, -0.37],
+ [-0.31, -0.37],
+ [-0.37, -0.44],
+ ],
+ zg: 0.15,
+ c: 0.03,
+ zc: 0.19,
+ tops: [
+ [-0.25, -0.47, 0.27],
+ [-0.2, -0.6, 0.28],
+ [-0.3, -0.55, 0.25],
+ ],
+ },
+ {
+ name: "palm",
+ outline: [
+ [-0.34, -0.6],
+ [-0.08, -1.0],
+ [0.38, -1.0],
+ [0.585, -0.74],
+ [0.585, -0.54],
+ [-0.12, -0.5],
+ ],
+ zg: 0.15,
+ c: 0.035,
+ zc: 0.18,
+ tops: [
+ [-0.04, -0.63, 0.3],
+ [0.26, -0.67, 0.29],
+ [0.03, -0.9, 0.24],
+ [0.47, -0.68, 0.26],
+ [0.22, -0.86, 0.265],
+ [-0.19, -0.7, 0.255],
+ [0.43, -0.84, 0.235],
+ ],
+ },
+];
+
+const sub = (a, b) => a.map((v, i) => v - b[i]);
+const dot = (a, b) => a.reduce((s, v, i) => s + v * b[i], 0);
+const cross = (a, b) => [
+ a[1] * b[2] - a[2] * b[1],
+ a[2] * b[0] - a[0] * b[2],
+ a[0] * b[1] - a[1] * b[0],
+];
+
+function plane(n, w) {
+ const len = Math.hypot(...n);
+ return [...n.map((v) => v / len), w / len];
+}
+
+function edgeFrame(a, b) {
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]);
+ const d = [(b[0] - a[0]) / len, (b[1] - a[1]) / len];
+ return { len, d, inward: [-d[1], d[0]] };
+}
+
+function arrowPiece(outline) {
+ const z0 = ARROW_Z0;
+ const planes = [plane([0, 0, 1], z0 + 0.2), plane([0, 0, -1], -(z0 - 0.03))];
+ outline.forEach((a, i) => {
+ const { len, d, inward: m } = edgeFrame(a, outline[(i + 1) % outline.length]);
+ const am = a[0] * m[0] + a[1] * m[1];
+ const ad = a[0] * d[0] + a[1] * d[1];
+ planes.push(plane([-m[0], -m[1], 0], -am));
+ planes.push(plane([-2.2 * m[0], -2.2 * m[1], 1], z0 + 0.035 - 2.2 * am));
+ for (const s of [1, -1]) {
+ const n = [-0.6 * m[0] + 0.18 * s * d[0], -0.6 * m[1] + 0.18 * s * d[1], 1];
+ planes.push(plane(n, z0 + 0.07 - 0.6 * am + 0.18 * s * (ad + 0.5 * len)));
+ }
+ });
+ return planes;
+}
+
+// The outline moved inward by `c`: the offset edges, each crossed with the previous one.
+function inset(outline, c) {
+ const lines = outline.map((a, i) => {
+ const { d, inward } = edgeFrame(a, outline[(i + 1) % outline.length]);
+ return { p: [a[0] + inward[0] * c, a[1] + inward[1] * c], d };
+ });
+ return lines.map(({ p: p2, d: d2 }, i) => {
+ const { p: p1, d: d1 } = lines[(i + lines.length - 1) % lines.length];
+ const det = d1[0] * -d2[1] + d2[0] * d1[1];
+ const t = ((p2[0] - p1[0]) * -d2[1] + d2[0] * (p2[1] - p1[1])) / det;
+ return [p1[0] + d1[0] * t, p1[1] + d1[1] * t];
+ });
+}
+
+function handPoints({ outline, zg, c, zc, tops }) {
+ return [
+ ...outline.map(([x, y]) => [x, y, HOVER]),
+ ...outline.map(([x, y]) => [x, y, zg]),
+ ...inset(outline, c).map(([x, y]) => [x, y, zc]),
+ ...tops,
+ ];
+}
+
+// Faces of the convex hull: every plane through three of the points with all the others behind.
+function hullPlanes(points) {
+ const planes = [];
+ const eps = 1e-7;
+ for (let i = 0; i < points.length; i++) {
+ for (let j = i + 1; j < points.length; j++) {
+ for (let k = j + 1; k < points.length; k++) {
+ const n = cross(sub(points[j], points[i]), sub(points[k], points[i]));
+ if (Math.hypot(...n) < 1e-9) continue;
+ let p = plane(n, dot(n, points[i]));
+ const side = points.map((q) => dot(p.slice(0, 3), q) - p[3]);
+ if (side.some((s) => s > eps) && side.some((s) => s < -eps)) continue;
+ if (side.some((s) => s > eps)) p = p.map((v) => -v);
+ if (!planes.some((q) => q.every((v, m) => Math.abs(v - p[m]) < 1e-6))) planes.push(p);
+ }
+ }
+ }
+ return planes;
+}
+
+function box(points) {
+ const lo = [0, 1, 2].map((i) => Math.min(...points.map((p) => p[i])));
+ const hi = [0, 1, 2].map((i) => Math.max(...points.map((p) => p[i])));
+ return [lo.map((v, i) => (v + hi[i]) / 2), lo.map((v, i) => (hi[i] - v) / 2 + 0.01)];
+}
+
+const pieces = [...ARROW.map(arrowPiece), ...HAND.map((h) => hullPlanes(handPoints(h)))];
+const planes = pieces.flat();
+const starts = pieces.reduce((s, p) => [...s, s[s.length - 1] + p.length], [0]);
+const arrowPoints = ARROW.flat().flatMap(([x, y]) => [
+ [x, y, HOVER],
+ [x, y, ARROW_Z0 + 0.2],
+]);
+const boxes = [...box(arrowPoints), ...box(HAND.flatMap(handPoints))];
+
+const num = (v, digits) => {
+ const s = v.toFixed(digits);
+ return Number(s) === 0 ? (0).toFixed(digits) : s;
+};
+
+function block(lang) {
+ const v4 = { wgsl: "vec4<f32>", hlsl: "float4", metal: "float4" }[lang];
+ const v3 = { wgsl: "vec3<f32>", hlsl: "float3", metal: "float3" }[lang];
+ const rows = [];
+ for (let i = 0; i < planes.length; i += 2) {
+ const pair = planes.slice(i, i + 2).map((p) => `${v4}(${p.map((v) => num(v, 4)).join(", ")})`);
+ rows.push(` ${pair.join(", ")}`);
+ }
+ const boxRows = boxes.map((b) => ` ${v3}(${b.map((v) => num(v, 3)).join(", ")})`);
+ if (lang === "wgsl") {
+ return [
+ `const GEM_PLANES = array<vec4<f32>, ${planes.length}>(`,
+ rows.join(",\n"),
+ ");",
+ `const GEM_PIECE = array<i32, ${starts.length}>(${starts.join(", ")});`,
+ "const GEM_BOX = array<vec3<f32>, 4>(",
+ boxRows.join(",\n"),
+ ");",
+ ].join("\n");
+ }
+ const decl = lang === "hlsl" ? "static const" : "constant";
+ return [
+ `${decl} float4 GEM_PLANES[${planes.length}] = {`,
+ rows.join(",\n"),
+ "};",
+ `${decl} int GEM_PIECE[${starts.length}] = { ${starts.join(", ")} };`,
+ `${decl} float3 GEM_BOX[4] = {`,
+ boxRows.join(",\n"),
+ "};",
+ ].join("\n");
+}
+
+const targets = [
+ ["vk_shaders/layer.wgsl", "wgsl"],
+ ["shaders.hlsl", "hlsl"],
+ ["shaders.metal", "metal"],
+];
+const marked = /(\/\/ <prism-glow-gem>\n)[\s\S]*?(\/\/ <\/prism-glow-gem>)/;
+const sources = await Promise.all(
+ targets.map(([file]) => readFile(path.join(SHADERS, file), "utf8")),
+);
+targets.forEach(([file], i) => {
+ if (!marked.test(sources[i])) throw new Error(`${file}: no <prism-glow-gem> markers`);
+});
+for (const [i, [file, lang]] of targets.entries()) {
+ const src = sources[i].replace(marked, (_, open, close) => `${open}${block(lang)}\n${close}`);
+ await writeFile(path.join(SHADERS, file), src);
+}
+console.log(
+ `${planes.length} planes: ${HAND.map((h, i) => `${h.name} ${pieces[i + 2].length}`).join(", ")}`,
+);