pbr_parallax_occlusion.shader
- README.md4.4 KB
- preview.png26.0 KB
- properties.yaml2.3 KB
- shader.wgsl4.2 KB
This package holds more than this page lists. See all of its files in its world.
README.md
PBR Parallax Occlusion
Surface shader that draws a textured PBR surface through the relief a
height map describes, built on @builtin::shaderModules.parallax (the
module any lit shader calls for the same relief; the built-in pbr shader
carries it as a feature). Per fragment it marches the view into the height
texture in tangent space and reads every map at the UV where the view met
the relief, through the derivatives of the face's own UV, so the relief's
edges pick no coarser mip. A UV that spans several tiles keeps every tile.
A second, shorter march toward the sun takes the sun off the points a raised
feature stands in front of; it runs only on fragments the sun lights. The
surface those samples describe is lit by zero_pbr_shade, the shading the
built-in pbr shader gets: every kind of light with its shadow, a spot's
cookie and the sun's transmittance, the indirect term darkened by the
occlusion map, and emissive on top. The shader returns scene light, and the
display pass applies the one tone curve, so with parallax_depth_scale = 0
a surface reads as a pbr surface with the same inputs. An unbound
normal_texture reads as a flat normal.
Domain
surface — bind to a .material.
Files
shader.wgsl— the fragment shader; the engine generates the vertex stage.README.md— this file.
Texture slots
Standard PBR slots plus a sixth height_texture:
@group(1) binding | Slot name | Notes |
|---|---|---|
| 1/2 | base_color_texture | albedo |
| 3/4 | normal_texture | tangent-space normals |
| 5/6 | roughness_metallic_texture | G = roughness, B = metallic (glTF) |
| 7/8 | emissive_texture | optional emissive |
| 9/10 | occlusion_texture | optional AO |
| 11/12 | height_texture | R = depth into surface (0 = at face, 1 = deep) under the default height_map_is_depth = true; height (1 = highest) under false. Unbound reads 0 |
The engine reflects @group(1) bindings via naga and builds the bind-group layout per shader, so adding the sixth slot needs no Rust changes.
Parameters
parallax_depth_scale: f32— max UV offset, in UV-space units. It stays below the size of the features the height map draws: a relief deeper than a course of bricks is tall draws each brick's side across the course beside it (parallax_cubeships 0.025 over courses about 0.033 apart). POM is gated on this being > 0 — set it to 0 and the shader draws plain textured PBR.max_parallax_layer_count: f32— the march's steps at a grazing view; a view straight down takes 40% of them and the self-shadow half. The step the view ray passes below the relief on is halved five times, so a feature's side is drawn from the texels at its edge at any count; a feature narrower than one step can fall between two steps, and more steps keep it. 128 is the cost ceiling.parallax_fade_start,parallax_fade_end: f32— world distance from the camera over which the relief flattens (20 and 40 by default); past the second no march runs.height_map_is_depth: bool: which wayheight_textureruns.true(the default here) reads R as depth, white deepest, the way the maps made for this shader (parallax_bricksamong them) are authored.falsereads it as height, white highest, the conventionpbrand the parallax module take by default.
Notes
- Which way the map runs is the one switch
height_map_is_depth, with the same name and meaning onpbr, on this shader and in the module (ZeroParallax.height_map_is_depth). Only the default differs:truehere,falseonpbr. A relief that reads inside out (raised parts sunk, grooves standing proud) is a map read the wrong way round: flipheight_map_is_depthrather than inverting the image. - This shader has no UV transform; a surface whose texture repeats
(
uv_scale) is apbrmaterial withheight_textureandparallax_depth_scale. - The relief is drawn by the fragment stage: the depth the surface writes and the shadow it casts are those of the flat face.
- The relief flattens toward a grazing view, so the silhouette of a curved mesh keeps its shape.
- The march runs in
fragment(), which the engine calls from both the forward and the G-buffer entries, so a deferred camera draws the relief too.