Rune and Ember: The Fantasy and Magic Material Collection
- ..
- .metadata141 B
- README.md4.0 KB
- properties.yaml6.2 KB
- shader.wgsl31.8 KB
README.md
fantasyCrystal
fantasyMaterials' enchanted-crystal shader (crystalAzure, crystalAmethyst, crystalPainted, crystalToon). Two layers make the crystal:
The druse: a crystal cluster on any surface. On flat faces (a wall, a floor tile, a cube face) a cluster of faceted crystals is laid over the surface in UV space, periodic over one UV repeat (seamless; the catalog's repeat is 0.5 m). It has three sizes of crystal (3, 5 and 9 cells per repeat, so a few big ones and many small). Each crystal is an offset hexagonal pyramid on an elongated base: six flat facets meet at an apex set toward its tip. Every facet has its own normal, which goes into the shading, so each one catches the light differently. Crystals stand in front of one another by height, with sharp ridges where facets meet, outlines and creases where crystals overlap, and dark rock (matrix_color) in the gaps. Each crystal has a heart of light: a thin white-hot core along its axis and saturated glow round it, gathered toward its base or tip (glow_tip), breathing on its own phase from input.time only. druse sets how much of a flat face it covers. druse_curved sets the same on curved faces (0 keeps spheres and cylinder sides as one cut-glass body). druse_spread fans the growth direction, druse_density thins the middle and small crystals, druse_height and facet_tilt set how steep the facets read. Fine lines and the thin heart fade out once a crystal spans only a few pixels, so the cluster doesn't shimmer at a distance.
The body: a solid see-through crystal with a heart of light. Glassy faces reflect the room (the engine's PBR with a screen-traced reflection). Through them you see the room behind, bent by refraction and tinted by Beer-Lambert absorption over the real path through the body. Inside, a white-hot core on the object's up axis fades into saturated light filling the body, a few ragged fracture planes catch that light, milky veils drift through it, and the edges glow. Curved meshes get flat cut facets (facets). This is what curved shapes show, and what flat faces show beneath the druse where druse < 1.
Styles.
style0, realistic: deep glass tinted bybody_color, the light inside each crystal varying from facet to facet, a thin white heart, bright ridges and outline, an occasional straight fracture lit from inside.style1, hand-painted: each crystal brushed intint_bottom(cyan) ortint_top(violet), split byhue_split. Facets facing the painter's upper-left light are painted lighter, with a soft inner wash, painted white strokes on lit ridges and dark rock between.style2, toon: flat cel-shaded facet bands from a fixed upper-left light, hard white glints on lit tips and ridges, ink outlines (ink_color) between crystals. On curved bodies it keeps the hard white rim and ink silhouette.
No textures.
How it draws (no sorting glitches). It reads the opaque room from the scene-colour copy and covers the pixel itself (render: { type: premultiplied, depth_write: true, cull: back, queue: 2950 }, alpha 1). Every overlap (two crystals, one crystal twice, a crystal and a ghost) is settled by the depth test, in any draw order. Queue 2950 puts it ahead of the other see-through surfaces: they composite over it when in front and are hidden by it when behind, as by a stone. Its far side is modelled inside the shader (exit distance, core, fractures) rather than drawn.
The object frame. A vertex_clip hook passes the point's position in the object's own frame (metres) in the vertex colour, and the object's height scale in its alpha. The fragment recovers the rotation from screen derivatives (exact on a triangle) and traces the refracted ray in object space. Core extent (core_from/core_to) is in object units along the up axis, for meshes centred on their origin (a unit primitive spans -0.5..0.5). body_radius, core_radius and halo_radius are in metres. The druse needs no tangents: the UV gradients come from screen derivatives.