Skip to main content

SurfaceStyle

Trait SurfaceStyle 

Source
pub trait SurfaceStyle: ShaderValues + Default {
    const PASS: DrawPass;
    const SURFACE: Option<&'static str> = None;
    const DISPLACE: Option<&'static str> = None;
}
Expand description

A look of a game’s own, written in WGSL and stitched into the engine’s shader at startup.

Required if you want a surface the materials cannot draw: implement it on a type whose fields are the values its WGSL reads, and name that type in Game::SurfaceStyles. The engine keeps the instance data, the lighting, the shadows and the curves that take the frame to the screen; the two hooks below are where a style’s own code runs.

Required Associated Constants§

Source

const PASS: DrawPass

The pass this style’s draws land in, whatever their material holds; see the module’s own docs.

Provided Associated Constants§

Source

const SURFACE: Option<&'static str> = None

WGSL declaring fn surface(surface: Surface) -> Surface, run in the fragment stage before the surface is lit; None leaves the engine’s own code there. Surface is the engine’s, and the module’s own docs state what each of its fields holds.

Surface holds the base color as color, the world-space normal, the light the surface adds of its own as emissive, and the world position and uv it is read at. The engine draws with color, normal and emissive; world and uv are there only to read. A draw with a Frame of its own reads its texels at this uv, held within that window. The engine lights with the normal as it is returned, so a style that turns it keeps it unit length.

Source

const DISPLACE: Option<&'static str> = None

WGSL declaring fn displace(placed: Placed) -> vec3<f32>, run in the vertex stage, which returns how far to move the vertex in world space; None leaves the vertex where the transform placed it.

Placed holds the world position the transform placed the vertex at, its normal, its uv, and the local position the mesh was built with. A draw with a Frame of its own holds the raw uv of that window here; only surface reads one held within it. A light’s depth maps take the vertex unmoved, so a displaced surface casts the shadow of where it was placed, and so does the sphere the camera holds the draw by: what this moves is the look, not the draw.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§