SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::VertexLayoutDesc Struct Reference

#include <VertexLayout.hpp>

Public Attributes

std::vector< VertexAttribute > attributes
std::string gbufferShaderStem
std::string shaderStem
std::string shadowShaderStem
uint32_t stride = 0
bool transparentReadsScene = false
std::string transparentShaderStem

Detailed Description

A complete custom vertex layout plus the shader stems that consume it. Register once at startup; the handle keys pipelines and mesh creation. Shader stems are consumed by the Vulkan backend; OpenGL instead binds the layout's attributes to its own fixed shader programs.

Fill one of these when your geometry does not fit the engine's built-in vertex type: packed voxel vertices, extra UV sets, per-vertex instance data, anything you want to define yourself. stride is the size of one vertex in bytes and each VertexAttribute gives a shader location, a component format, and a byte offset inside that vertex.

The four shader stems name the pipeline variants the format participates in. An empty stem skips that pass entirely, so a format with no shadowShaderStem casts no shadows and a format with no gbufferShaderStem is forward only. There is no fallback shader: if a named stem fails to load, the backend logs an error and skips that pass for this format.

struct VoxelVertex {
float position[3];
float normal[3];
float uv[2];
uint32_t packedLight;
};
desc.stride = sizeof(VoxelVertex);
desc.attributes = {
offsetof(VoxelVertex, position)},
offsetof(VoxelVertex, normal)},
{2, Sleak::VertexAttribFormat::Float2, offsetof(VoxelVertex, uv)},
offsetof(VoxelVertex, packedLight)},
};
desc.shaderStem = "flat_shader";
desc.shadowShaderStem = "shadow_depth_voxel";
desc.gbufferShaderStem = "gbuffer_voxel";
desc.transparentShaderStem = "water_shader";
static VertexFormatHandle Register(const VertexLayoutDesc &desc)
uint32_t VertexFormatHandle
std::string transparentShaderStem
std::vector< VertexAttribute > attributes

Set transparentReadsScene for transparent geometry that refracts or reflects what lies behind it, such as water. The first transparent draw of the format in a frame snapshots the scene drawn so far, and its shaders can then read it:

  • Vulkan, descriptor set 3: binding 2 scene color (linear HDR), binding 3 scene depth, binding 4 sky cubemap, binding 5 the SceneReadUBO block below.
  • OpenGL: texture unit 4 scene color (tonemapped, as shown), unit 5 scene depth, unit 6 sky cubemap, uniform block binding 4 SceneReadUBO.
uniform SceneReadUBO {
mat4 ViewProj; // unjittered, row-major engine matrix
mat4 InvViewProj;
vec4 ScreenSize; // width, height, 1/width, 1/height
vec4 Camera; // TAA jitter in NDC (xy), near, far
vec4 Flags; // x: scene textures valid, y: sky valid
};

Add Camera.xy * gl_Position.w to the clip position after the Vulkan Y flip so the draw lines up with the jittered opaque geometry.

On Vulkan, transparent draws set the HDR scene alpha to 0. TAA reads that as a reactive mask and trusts history less there, since animated or refracted content is not described by the depth buffer.

See also
VertexFormatRegistry, VertexAttribute, VertexAttribFormat, MeshBatch

Definition at line 101 of file VertexLayout.hpp.

Member Data Documentation

◆ attributes

std::vector<VertexAttribute> Sleak::VertexLayoutDesc::attributes

Definition at line 103 of file VertexLayout.hpp.

◆ gbufferShaderStem

std::string Sleak::VertexLayoutDesc::gbufferShaderStem

Definition at line 108 of file VertexLayout.hpp.

◆ shaderStem

std::string Sleak::VertexLayoutDesc::shaderStem

Definition at line 104 of file VertexLayout.hpp.

◆ shadowShaderStem

std::string Sleak::VertexLayoutDesc::shadowShaderStem

Definition at line 106 of file VertexLayout.hpp.

◆ stride

uint32_t Sleak::VertexLayoutDesc::stride = 0

Definition at line 102 of file VertexLayout.hpp.

◆ transparentReadsScene

bool Sleak::VertexLayoutDesc::transparentReadsScene = false

Definition at line 112 of file VertexLayout.hpp.

◆ transparentShaderStem

std::string Sleak::VertexLayoutDesc::transparentShaderStem

Definition at line 110 of file VertexLayout.hpp.