Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

material.shader (procNode)

A material made from any surface .shader: each property its properties.yaml declares is set by name in properties, and each texture slot by name in textures; a property left out keeps the shader's default. The names given are held to what the shader declares, and a name it does not declare is refused naming the ones it does. blend, queue, cull and depthWrite override the shader's own render settings, each left empty (or unwired) to keep it. Wiring geometry fills the shader's buffer property with one Vec4 per live element, so a surface answers to elements another part of the graph made.

It answers one element whose Material attribute holds the material record, with the material kind stated on the detail attribute records. Any input that takes a material takes it (geometry.set_material, instances.set_material, instances.pack, instances.to_points, elements.entity), io.output shows it and io.export saves it as a .material. material.pbrMat makes the standard metallic-roughness material from its maps.

local glow = g.material.shader({
    shader = asset.resolve("@builtin::shaders.pbr", "shader"),
    properties = { roughness = 0.3 },
    blend = "additive",
    cull = "none",
})
local card = g.geometry.set_material({ geometry = g.mesh.plane({}), material = glow })

Inputs

  • shader (AssetRef<shader>). The surface .shader the material is made from, written asset.resolve("<identity>", "shader"). A name given as text is refused, naming the reference to write.
  • properties (Record, optional). Values of the shader's declared properties, by name: a number for a float or int, { r, g, b, a } for a colour, an array of 2-4 numbers for a vector. Each one can be a constant, an animated value or another node's output wired in; an animated one moves on every frame the material is drawn.
  • textures (Record<Texture>, optional). Textures for the shader's declared texture slots, by slot name: a Texture a texture.* node made, or a reference to a .texture asset.
  • geometry (Geometry, optional). Elements the surface reads: the attribute name of each live element of its class, one Vec4 each, fills the shader's buffer property. The shader reads them as array<vec4<f32>> from its vertex(), vertex_clip() and fragment() hooks: the live elements first, every element after them zero.
  • blend (String, default "", one of "", "opaque", "transparent", "alpha", "alphaBlend", "additive", "add", "premultiplied", "premultipliedAlpha", "multiply", "cutout", "alphaCutout"). How the surface combines with what is behind it: additive (add) adds its colour; transparent (alpha, alphaBlend) lays it over by its alpha; premultiplied (premultipliedAlpha) takes colour already multiplied by alpha; multiply darkens by it; cutout (alphaCutout) keeps or drops each pixel by its alpha. Empty keeps the shader's own.
  • queue (Int, optional, at least 0). The draw order among the surfaces: 2000 is opaque, 3000 transparent, 4000 overlay, and a number between orders within a queue. Unwired keeps the shader's own.
  • cull (String, default "", one of "", "back", "front", "none"). Which faces are left undrawn: none draws both sides. Empty keeps the shader's own.
  • depthWrite (String, default "", one of "", "true", "false"). Whether the surface writes depth. Empty keeps the shader's own.
  • name (String, default "data0"). The Vec4 attribute of geometry the buffer property holds, one per element.
  • class (String, default "point", one of "point", "vertex", "primitive"). Which class of geometry fills the buffer property.

Outputs

  • material (Geometry). One element whose Material attribute holds the material record.