3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Make the water glint edge replace the soft lobe so the step shows (#2036)
Nguyen Xuan Aned7b8836cda4
diff --git a/docs/material-maps.md b/docs/material-maps.mdindex 3336322b..82a755a0 100644--- a/docs/material-maps.md+++ b/docs/material-maps.md@@ -154,7 +154,7 @@ glTF import maps `alphaMode` MASK and BLEND, `alphaCutoff`, `doubleSided` and `b## Water glints-`material.waterGlint` adds stylized highlights to a `water` material, on top of the physical sun glint. Both parts are off until the field names them, so water without the field draws exactly as before.+`material.waterGlint` adds stylized highlights to a `water` material (sparkles come on top of the physical sun glint, the edge redraws it). Both parts are off until the field names them, so water without the field draws exactly as before.```json{ "tag": "water", "waterGlint": { "edge": { "threshold": 0.4 }, "sparkle": { "shape": "star", "size": 0.4 } } }@@ -162,7 +162,7 @@ glTF import maps `alphaMode` MASK and BLEND, `alphaCutoff`, `doubleSided` and `b| Part | Field | Accepts (default) | Does ||---|---|---|---|-| `edge` | `threshold` | 0.05 to 0.95 (0.4) | Cuts the glint lobe at this share of its peak, so the highlight is a flat shape with a clean border that follows the waves. Higher is smaller. |+| `edge` | `threshold` | 0.05 to 0.95 (0.4) | Replaces the soft glint with the lobe cut at this share of its peak, so the highlight is a flat shape with a clean border that follows the waves. Higher is smaller. || `edge` | `intensity` | 0 to 4 (1) | Brightness of that shape. || `sparkle` | `density` | 0 to 1 (0.35) | Share of cells that carry a sparkle. || `sparkle` | `size` | 0.02 to 2 m (0.12) | Width of a cell on the water, so how big a sparkle is. |diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.jsindex dd5dcdef..12b79373 100644--- a/src/agent-scene-capabilities.js+++ b/src/agent-scene-capabilities.js@@ -272,7 +272,7 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({})]))),materialSubsurface: 'material.subsurface { weight, radius, scale, color } as Blender Principled BSDF Subsurface; surface tag, rasterizer only. Ranges in scene_create.',materialRetro: 'material.retro { vertexSnap [width, height] (whole numbers 16 to 4096), affineUV true }: the PS1 look. vertexSnap rounds each vertex to a width by height screen grid so vertices jitter as the camera moves; affineUV interpolates texture coordinates without perspective correction so textures swim on large triangles. Set either or both. Raster renders only; the path tracer ignores it. Shadows ignore it. A material without retro renders exactly as before.',- materialWaterGlint: 'material.waterGlint { edge { threshold 0.05 to 0.95 (0.4), intensity 0 to 4 (1) }, sparkle { density 0 to 1 (0.35), size 0.02 to 2 m (0.12), threshold 0.9 to 0.9999 (0.985), shape dot | star (dot), twinkle 0 to 8 per second (1), intensity 0 to 4 (1) } } on a water material, both parts off unless named: stylized highlights on top of the physical sun glint. edge cuts the glint lobe at threshold into a flat hard-edged shape that follows the waves; raise threshold for a smaller shape. sparkle cuts the water into size-metre cells and lights the share given by density whose tilted facet mirrors the sun within threshold (a cosine, higher is fewer and tighter), so sparkles twinkle with the camera, the waves and time and never show on the side away from the sun. Sparkles fade in far water where a cell is under two pixels. Raster renders only; the path tracer ignores it. Painted light streaks are not built yet.',+ materialWaterGlint: 'material.waterGlint { edge { threshold 0.05 to 0.95 (0.4), intensity 0 to 4 (1) }, sparkle { density 0 to 1 (0.35), size 0.02 to 2 m (0.12), threshold 0.9 to 0.9999 (0.985), shape dot | star (dot), twinkle 0 to 8 per second (1), intensity 0 to 4 (1) } } on a water material, both parts off unless named: stylized highlights. edge replaces the soft sun glint with its lobe cut at threshold into a flat hard-edged shape that follows the waves; raise threshold for a smaller shape. sparkle cuts the water into size-metre cells and lights the share given by density whose tilted facet mirrors the sun within threshold (a cosine, higher is fewer and tighter), so sparkles twinkle with the camera, the waves and time and never show on the side away from the sun. Sparkles fade in far water where a cell is under two pixels. Raster renders only; the path tracer ignores it. Painted light streaks are not built yet.',materialWear: 'material.wear { mask, threshold 0.5, softness 0.25, metal { color, metallic 1, roughness 0.3 }, dirt { mask, threshold, softness, color, roughness 0.9 } }: the material own color, metallic and roughness are the paint; per pixel it turns to the metal layer where the vertex group mask is high, then to dirt (no metal, rougher) where the dirt group is high. Masks are vertex groups of the node mesh (vertex_group measure edge, curvature or occlusion), so a mesh with no UVs works. Rasterizer only; not with baked sky visibility.',alphaModes: RECIPE_ALPHA_MODES,materialPatterns: MATERIAL_PATTERN_TYPES, maxMaterialPatterns: MAX_MATERIAL_PATTERNS,diff --git a/src/glitter-shader.js b/src/glitter-shader.jsindex bdc6da72..493a9f2b 100644--- a/src/glitter-shader.js+++ b/src/glitter-shader.js@@ -2,7 +2,7 @@ import { invalidField } from './field-error.js';import { layerTextureSupport, registerShaderFeatureCode } from './shader-registry.js';// Stylized highlights of a water material: `waterGlint: { edge, sparkle }`. Both are off unless the field names them.-// edge: a hard-edged copy of the sun glint. The glint lobe is cut at `threshold` (0 to 1 of its peak), so the highlight is a flat+// edge: the sun glint redrawn with a hard edge: the soft lobe is taken out and the glint lobe is cut at `threshold` (0 to 1 of its peak), so the highlight is a flat// shape with a clean border that follows the waves, as Blinn-Phong specular followed by a step.// sparkle: glitter on the sun path. The water is cut into cells `size` metres wide. Each cell holds a tiny facet that tilts with the// wave under it and turns over time; it lights up when its mirror direction falls within `threshold` (cosine) of the@@ -83,6 +83,9 @@ const FINAL = ` if (TAG_WATER && (waterGlintEdge.x > 0.0 || waterGlintSparkle.wif (waterGlintEdge.x > 0.0) {float lobe = waterGlintLobe(normal, viewDirection, glintSun, waterLostVariance);float edgeWidth = 1.5 * fwidth(lobe) + 0.01;+ // The physical glint drawn by the water code is taken out first, so the flat shape replaces the soft lobe instead of hiding in it.+ float glintFresnel = 0.02 + 0.98 * pow(1.0 - max(dot(normalize(glintSun + viewDirection), viewDirection), 0.0), 5.0);+ radiance = max(radiance - vec3(1.0, 0.9, 0.7) * lobe * (0.5 + 40.0 * glintFresnel) * 6.0 * keyResponse * (1.0 - waterFoam), vec3(0.0));radiance += glintTint * smoothstep(waterGlintEdge.x - edgeWidth, waterGlintEdge.x + edgeWidth, lobe) * waterGlintEdge.y * 4.0;}if (waterGlintSparkle.w > 0.0) {