Documentation ¶
Overview ¶
Package load fetches disk based 3D asset data. It's main purpose is to find the asset file and load its data into intermediate data structs.
- ".spv" spir-v shader module byte code
- ".png" image data
- ".shd" shader configuration description
- ".glb" vertex data, image data, animation data, material data
- ".wav" audio data
- ".ttf" true type font file.
- ".yaml" data file
This package is primary used internally for getting data from disk that is then upload to the render and audio systems.
Package load is provided as part of the vu (virtual universe) 3D engine.
Index ¶
- Constants
- Variables
- func SetAssetDir(ext, dir string)
- type AssetData
- type AttributeScope
- type AudioAttributes
- type AudioData
- type Buffer
- type ByteData
- type FontAtlas
- type Glyph
- type ImageData
- type MeshData
- type PBRMaterialData
- type PacketUniform
- type PassUniform
- type Shader
- type ShaderAttribute
- type ShaderData
- type ShaderDataType
- type ShaderPass
- type ShaderStage
- type ShaderUniform
- type UniformScope
Constants ¶
const ( Vertexes = iota // 0 required:V3 float32 Texcoords // 1 optional:V2 float32 Normals // 2 optional:V3 float32 Tangents // 3 optional:V4 float32 Colors // 4 optional:V3 uint8 Joints // 5 FUTURE:V4 uint8 animations Weights // 6 FUTURE:V4 uint8 animations Indexes // 7 required:uint16 - must be second last. VertexTypes // 8 number of vertex data types - must be last. )
Vertex MeshData attribute types.
const ( InstancePosition = iota // position 0 V3 float32 InstanceColors // 1 V3 uint8 InstanceScales // 2 float32 InstanceTypes // number of instance data types - must be last. )
Instance Data attribute types describe per-instance model data. These are defined here because they are similar to vertex data types.
Variables ¶
var DataTypeSizes = map[ShaderDataType]uint32{ DataType_INT: 4, DataType_FLOAT: 4, DataType_LIGHT3: 96, DataType_MAT3: 36, DataType_MAT4: 64, DataType_SAMPLER: 0, DataType_VEC2: 8, DataType_VEC3: 12, DataType_VEC4: 16, }
var ReadFile func(string) ([]byte, error) = osReadFile
ReadFile can be overridden by the app to use other options than loading files from the file system. Eg: the app can use a go:embed FS.
var ShaderAttributeData = map[string]ShaderDataType{ "float": DataType_FLOAT, "vec2": DataType_VEC2, "vec3": DataType_VEC3, "vec4": DataType_VEC4, }
ShaderAttributeData are the currently supported data types for vertex and model-instance data. Expected use is for passing data from the engine to the render system.
var ShaderAttributeScope = map[string]AttributeScope{ "vertex": VertexAttribute, "instance": InstanceAttribute, }
ShaderAttributeScope categorizes vertex attributes into per-vertex data or per-model-instance data. Expected use is for passing data from the engine to the render system.
var ShaderAttributes = map[string]int{ "position": Vertexes, "texcoord": Texcoords, "normal": Normals, "tangent": Tangents, "v_color": Colors, "joint": Joints, "weight": Weights, "i_position": InstancePosition, "i_color": InstanceColors, "i_scale": InstanceScales, }
ShaderAttributes map glsl vertex attributes from shader programs to model data provided by code. Expected use is for passing data from the engine to the render system.
var ShaderPacketUniforms = map[string]PacketUniform{ "model": MODEL, "scale": SCALE, "color": COLOR, "material": MATERIAL, "args4": ARGS4, "args16": ARGS16, }
ShaderPacketUniforms are shader uniforms that apply to one model. Render data for a model is put into a render.Packet. Expected use is for passing data from the engine to the render system.
var ShaderPassUniforms = map[string]PassUniform{ "proj": PROJ, "view": VIEW, "cam": CAM, "lights": LIGHTS, "nlights": NLIGHTS, "time": TIME, }
ShaderPassUniforms are shader uniforms that apply to the a single scene (render pass). Expected use is for passing data from the engine to the render system.
var ShaderUniformData = map[string]ShaderDataType{ "int": DataType_INT, "float": DataType_FLOAT, "light3": DataType_LIGHT3, "mat3": DataType_MAT3, "mat4": DataType_MAT4, "sampler": DataType_SAMPLER, "vec2": DataType_VEC2, "vec3": DataType_VEC3, "vec4": DataType_VEC4, }
ShaderUniformData are the supported uniform data types. Expected use is for passing data from the engine to the render system.
var ShaderUniformScope = map[string]UniformScope{ "scene": SceneScope, "material": MaterialScope, "model": ModelScope, }
ShaderUniformScope is used to bind data in shaders. Expected use is for passing data from the engine to the render system.
Functions ¶
func SetAssetDir ¶ added in v0.20.0
func SetAssetDir(ext, dir string)
SetAssetDir can be used to add or change the default directory conventions for finding assets.
Types ¶
type AssetData ¶ added in v0.20.0
type AssetData struct { Filename string // request filename with extension Err error // nil if load was successful Data interface{} // struct of loaded data. }
AssetData is used to return loaded data. The caller is expected to switch on the Data type.
func Glb ¶ added in v0.20.0
Glb accepts a subset of a binary gltf.Document that describes a single mesh model. The single models limitiations is enforced as follows:
- one Scene
- one Node
- one Mesh
- one Mesh.Primitive
These conform to a single model exported from Blender.
func LoadAssetFile ¶ added in v0.20.0
LoadAssetFile returns one or more AssetData structs from the given asset filename.
type AttributeScope ¶ added in v0.20.0
type AttributeScope uint8
AttributeScope identifies the two types of attributes.
const ( VertexAttribute AttributeScope = iota InstanceAttribute )
type AudioAttributes ¶ added in v0.20.0
type AudioAttributes struct { Channels uint16 // Number of audio channels. Frequency uint32 // 8000, 44100, etc. DataSize uint32 // Size of audio data. SampleBits uint16 // 8 bits = 8, 16 bits = 16, etc. }
AudioAttributes describe how sound data is interpreted and played.
type AudioData ¶ added in v0.20.0
type AudioData struct { Data []byte // the sound data bytes. Attrs *AudioAttributes // Attributes describing the sound data. }
AudioData consists of the actual audio data bytes along with sounds attributes that describe how the sound data is interpreted and played.
AudioData is an intermediate data format that needs further processing to associate the sound with a 3D location and bind it to an audio device.
type Buffer ¶ added in v0.20.0
type Buffer struct { Data []byte // bytes in little-endian order. Count uint32 // total number of elements, ie: how many vertex vec3's. Stride uint32 // bytes for one element, eg: 12 for float32:vec3 }
Buffer holds byte data that can be uploaded to the GPU
func F32Buffer ¶ added in v0.20.0
F32Buffer converts a slice of float32s to a Buffer of bytes. Used to pass data to glsl vec float types
func U16Buffer ¶ added in v0.20.0
U16Buffer converts a slice of uint16 to a Buffer of bytes. Used to pass data to glsl vertex indexes.
func U32Buffer ¶ added in v0.20.0
U32Buffer converts a slice of uint32 to a Buffer of bytes. Used to pass data to glsl uvec int types
type FontAtlas ¶ added in v0.21.0
type FontAtlas struct { Tag string // asset ID is filename + font-size. Img ImageData // Atlas image ready for upload to GPU. Glyphs []Glyph // Character position mapping data. NRGBA *image.NRGBA }
FontAtlas holds UV texture mapping information for a font. This is an intermediate data format that needs further processing by something like a vu.Ent.MakeModel to send the atlas image to the GPU.
type Glyph ¶ added in v0.21.0
type Glyph struct { Char rune // Character. X, Y, W, H int // Character bit size. Xo, Yo, Xa int // Character offset. }
Glyph holds UV texture mapping information for one character. Expected to be used as part of FntData.
type MeshData ¶ added in v0.20.0
type MeshData []Buffer
MeshData contains per-vertex data. Data will be index the GLTF buffer.
type PBRMaterialData ¶ added in v0.20.0
type PBRMaterialData struct { ColorR float64 // material base color for solid PBR. ColorG float64 // "" ColorB float64 // "" ColorA float64 // "" Metallic float64 // metallic value if no m-r texture Roughness float64 // roughness value if no m-r texture }
PBRMaterialData describes a PBR solid material.
type PacketUniform ¶ added in v0.20.0
type PacketUniform uint8
PacketUniform is model scope uniform data.
const ( MODEL PacketUniform = iota // model SCALE // model COLOR // model MATERIAL // model ARGS4 // model shader specific data passing. ARGS16 // model shader specific data passing. PacketUniforms // must be last )
type PassUniform ¶ added in v0.20.0
type PassUniform uint8
PassUniform is scene scope uniform data.
const ( PROJ PassUniform = iota // scene VIEW // scene CAM // scene LIGHTS // scene NLIGHTS // scene TIME // scene PassUniforms // must be last )
type Shader ¶ added in v0.20.0
type Shader struct { // Name identifies the shader modules. eg: Name.frag, Name.vert Name string // unique name for this shader. Pass string // renderpass name for this shader. Stages ShaderStage // bit flags for the shader stages. // Set from shaderConfig.Render flags. CullModeNone bool // true disables backface culling. DrawLines bool // true to render lines instead of triangles. // Attrs must match the shader attributes in name and position, ie: // Attr[0].Name == position ... which matches // "layout(location=0) in vec3 position;" Attrs []ShaderAttribute // Uniforms must match the shader attributes in name and position // where scope also identifies a DescriptorSet. Uniforms []ShaderUniform }
Shader describes shader data and is used to generate render shaders on startup.
FUTURE: replace the yaml files with data gathered from shader code reflection. Not really a simple way to do Spirv reflection at the moment as the current tools generate lots of data which would be a pain to parse. See: spirv-cross, spirv-reflect command line tools.
func ShaderConfig ¶ added in v0.20.0
ShaderConfig loads compiled shader (spir-v) byte data.
func Shd ¶ added in v0.20.0
Shd loads a yaml shader configuration and returns it as a shader configuration struct. This is needed to provide a link between the render models and the shader programs.
func (*Shader) GetSamplerUniforms ¶ added in v0.20.0
func (s *Shader) GetSamplerUniforms() (uniforms []*ShaderUniform)
func (*Shader) GetSceneUniforms ¶ added in v0.20.0
func (s *Shader) GetSceneUniforms() (uniforms []*ShaderUniform)
type ShaderAttribute ¶ added in v0.20.0
type ShaderAttribute struct { Name string // unique name matching shader source code. AttrType int // matching mesh vertex attribute type AttrScope AttributeScope // vertex or instanced DataType ShaderDataType // describes the attribute data. }
ShaderAttribute identifies the data layouts for attributes.
type ShaderData ¶ added in v0.20.0
type ShaderData []byte
ShaderData differentiates shader data from other byte data.
func ShaderBytes ¶ added in v0.20.0
func ShaderBytes(name string) (data ShaderData, err error)
ShaderBytes loads compiled shader (spir-v) byte data.
type ShaderDataType ¶ added in v0.20.0
type ShaderDataType uint8
ShaderDataType helps describe shader attributes and uniforms
const ( DataType_INT ShaderDataType = iota DataType_FLOAT DataType_LIGHT3 // array of 3 lights DataType_MAT3 DataType_MAT4 DataType_SAMPLER DataType_VEC2 DataType_VEC3 DataType_VEC4 )
type ShaderPass ¶ added in v0.20.0
type ShaderPass uint8
ShaderPass identifies the render pass that the shader uses.
const ( Renderpass_3D ShaderPass = iota // 3D is rendered before 2D Renderpass_2D // )
type ShaderStage ¶ added in v0.20.0
type ShaderStage uint8
ShaderStage identifies the currently supported programmable shader stages that a shader can have.
const ( Stage_VERTEX ShaderStage = 1 << iota // vertex processing. Stage_GEOMETRY // eg: turn points into quads. Stage_FRAGMENT // pixel processing. )
type ShaderUniform ¶ added in v0.20.0
type ShaderUniform struct { Name string // unique name matching shader source code. Scope UniformScope // DataType ShaderDataType // PassUID PassUniform // index to pass data PacketUID PacketUniform // index to packet data }
ShaderUniform identifies the data layouts for uniforms.
type UniformScope ¶ added in v0.20.0
type UniformScope uint8
UniformScope identifies the three supported types of uniforms. The scope is directly related to the layout(set=x) value in the shader code.
const ( SceneScope UniformScope = iota // set per render pass: set=0 MaterialScope // set per material : set=1 ModelScope // set per model : push constants )