跳转到内容
查看源码

texture自动生成

分类:包 · 清单:use "kernels/";

表面着色用的纹理函数:图案、映射方式、图层与法线。

What a surface is drawn with, point by point as a shader asks: patterns, the ways a pattern is laid on a surface, layers and normals. Each is a function a scene’s own material calls where it shades a point (a G-buffer kernel, a distance field’s march, a mesh’s pixels), so a material is these words composed, not a feature of the renderer.

Layer: Graphics. Uses: random.

use "texture.entpkg";

Detail is drawn so it holds still on screen: a pattern’s lines, stripes and shapes take the width of the pixel they fall in (pix, in the pattern’s units: a point’s distance times the pixel’s angle) and are averaged over it, and detail that would crowd closer than a few pixels is let go (texture_fade).

  • kernels/layer.ent — Layers blended by their heights; a normal bent by a height’s slope, made from a height’s differences, taken from a face’s frame to the world, and two normals joined.
  • kernels/pattern.ent — Patterns on a surface’s plane: a grid’s cells, courses of bricks or boards, panels split by a hash, an opening inset in a cell; lines, stripes and any signed distance covered over a pixel.
  • kernels/projection.ent — A pattern laid on a surface: three planes blended by how it faces, the one face it is on, parallax, and the room seen through a window.

tests/ holds scenes and their replays, run on every backend: patterns.replay, surfaces.replay.

函数 简述
texture_height_blend(low: Float, high: Float, mask: Float, contrast: Float) -> Float How much of the upper layer shows (0 to 1) where the lower stands low high and the upper high (0 to 1 each), the mask mask asking for the upper: the higher of them wins over a band contrast wide.
texture_bump(n: Vec3, slope: Vec3, strength: Float) -> Vec3 A surface facing n bent by a height’s slope slope (the height’s change a meter, along the world’s axes), strength of it: the slope’s part along the surface tilts it.
texture_slope_normal(dx: Float, dy: Float, strength: Float) -> Vec3 A face’s normal in its own frame (x across, y up, z out of it) from a height’s change across it (dx) and up it (dy) a unit, strength of it.
texture_to_world(t: Vec3, n: Vec3, across: Vec3) -> Vec3 A normal in a face’s own frame (t, x across, y up, z out) taken to the world, the face facing n, its across across.
texture_normal_blend(base: Vec3, detail: Vec3) -> Vec3 Two normals in a face’s own frame joined (a detail’s over a base’s): the slopes added, the result still facing out.
texture_grid(uv: Vec2, size: Vec2) -> TextureCell The cell of a grid of cells size big that holds uv.
texture_courses(uv: Vec2, size: Vec2, shift: Float, jitter: Float, seed: Int) -> TextureCell The cell of courses size.y high of cells size.x long that holds uv, each course shifted shift of a cell on the one below (0.5 a running bond), and by up to jitter of a cell more by its hash (seed): bricks, stones, boards.
texture_panels(uv: Vec2, size: Vec2, splits: Int, seed: Int) -> TextureCell The panel that holds uv of a grid size big whose cells are split up to splits times, each time in two across their longer side at a hashed place (seed), so panels of a few sizes fit together: the hull of a ship, a facade’s cladding.
texture_inset(c: TextureCell, low: Vec2, high: Vec2) -> Float How far a point in cell c is from the opening inset in it from low to high (shares of the cell across and up), in the pattern’s units, negative inside: a window in a bay, a light in a panel.
texture_cover(d: Float, pix: Float) -> Float How much of a pixel pix wide the shape a signed distance d gives (negative inside) covers: its edge drawn smooth over the pixel.
texture_line(edge: Float, width: Float, pix: Float) -> Float How much of a pixel pix wide a line width pixels wide covers, edge from it (a line thinner than a pixel drawn fainter, not thinner).
texture_fade(spacing: Float, pix: Float) -> Float How much detail spacing apart is kept where a pixel is pix wide: all of it until it crowds closer than five pixels, none by two.
texture_joint(c: TextureCell, width: Float, pix: Float) -> Float The joints of cell c (mortar, seams, a mesh’s edges), width pixels wide where a pixel is pix wide, let go where the cells crowd.
texture_stripes(x: Float, period: Float, duty: Float, pix: Float) -> Float Stripes across x every period, duty of each one on, the share of a pixel pix wide they cover (averaged over the pixel exactly: no shimmer however fine).
texture_vary(c: Vec3, k: Float, amount: Float) -> Vec3 A color varied by a hash k (0 to 1), up to amount lighter or darker: no two bricks, panels or boards quite alike.
texture_planes(p: Vec3, n: Vec3, sharp: Float) -> TexturePlanes
texture_face(p: Vec3, n: Vec3) -> Vec3 The face a surface facing n is on, as a box’s or a building’s: where on it p is (x across it, y up it, or along z on a floor or roof) and which face (z: 0 facing along x, 1 up or down, 2 along z).
texture_face_axes(n: Vec3) -> Vec3 The axes across the face a surface facing n is on (1 for each the face spans): where a lattice’s lines are drawn on it.
texture_into(view: Vec3, n: Vec3, across: Vec3) -> Vec3 A view’s direction view taken into a face’s own frame (x across the face, y up it, z into it), the face facing n, its across across.
texture_parallax(uv: Vec2, view: Vec3, depth: Float) -> Vec2 Where on a pattern a view (view, the face’s own frame, texture_into) meets it when it lies depth behind the surface, from uv on the surface: a pattern set back (a recess, a reveal).
texture_room(at: Vec2, view: Vec3, depth: Float) -> Vec4 The room behind a window seen along a view (view, the face’s own frame), from at on the window (0 to 1 across and up), the room as wide and as high as the window’s cell and depth of that deep: where the view meets it (x, y across the wall it meets, 0 to 1), which wall (z: 0 the back, 1 a side, 2 the floor or the ceiling) and how far in it is (w, shares of the depth).
名称 写法
TextureCell struct TextureCell { at: Vec2; id: Vec2; size: Vec2; edge: Float; }
TexturePlanes struct TexturePlanes { x: Vec2; y: Vec2; z: Vec2; weight: Vec3; }

patterns.replay, surfaces.replay