material

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GPUEffectParamsSource string

GPUEffectParamsSource is the canonical WGSL definition of the EffectParams struct. Matches GPUEffectParams layout exactly (16 bytes, std430 aligned).

View Source
var GPUOverlayParamsSource string

GPUOverlayParamsSource is the canonical WGSL definition of the OverlayParams struct. Matches GPUOverlayParams layout exactly (16 bytes, std430 aligned).

Functions

This section is empty.

Types

type GPUEffectParams

type GPUEffectParams struct {
	TintColor [4]float32 // offset 0: RGB tint color + alpha blend intensity (16 bytes)
}

GPUEffectParams is the GPU-aligned uniform for the textured and skinned-rainbow fragment shaders. The RGB channels set the tint color; the alpha channel controls the tint blend intensity (0.0 = no tint, 1.0 = fully tinted). Matches the WGSL EffectParams struct layout exactly (see GPUEffectParamsSource). Size: 16 bytes (one vec4<f32>, std430 aligned).

func (*GPUEffectParams) Marshal

func (g *GPUEffectParams) Marshal() []byte

Marshal serializes the GPUEffectParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 16-byte buffer ready for GPU upload.

func (*GPUEffectParams) Size

func (g *GPUEffectParams) Size() int

Size returns the size of the GPUEffectParams struct in bytes.

Returns:

  • int: the size of the struct in bytes.

type GPUOverlayParams

type GPUOverlayParams struct {
	OverlayColor [4]float32 // offset 0: RGBA overlay color written to all fragments (16 bytes)
}

GPUOverlayParams is the GPU-aligned uniform for the overlay fragment shader. Matches the WGSL OverlayParams struct layout exactly (see GPUOverlayParamsSource). Size: 16 bytes (one vec4<f32>, std430 aligned).

func (*GPUOverlayParams) Marshal

func (g *GPUOverlayParams) Marshal() []byte

Marshal serializes the GPUOverlayParams struct into a byte buffer suitable for GPU upload.

Returns:

  • []byte: 16-byte buffer ready for GPU upload.

func (*GPUOverlayParams) Size

func (g *GPUOverlayParams) Size() int

Size returns the size of the GPUOverlayParams struct in bytes.

Returns:

  • int: the size of the struct in bytes.

type Material

type Material interface {
	common.Delegate[Material]

	// Name retrieves the material identifier.
	//
	// Returns:
	//   - string: the name of the material
	Name() string

	// BaseColor retrieves the albedo/diffuse RGBA color of the material.
	//
	// Returns:
	//   - [4]float32: the base color as RGBA values
	BaseColor() [4]float32

	// Metallic retrieves the metallic factor of the material.
	// A value of 0.0 represents a dielectric surface, 1.0 represents a fully metallic surface.
	//
	// Returns:
	//   - float32: the metallic factor
	Metallic() float32

	// Roughness retrieves the roughness factor of the material.
	// A value of 0.0 represents a perfectly smooth surface, 1.0 represents a fully rough surface.
	//
	// Returns:
	//   - float32: the roughness factor
	Roughness() float32

	// DiffuseTexture retrieves the diffuse/albedo texture data reference, or nil if none is set.
	//
	// Returns:
	//   - *common.ImportedTexture: the diffuse texture, or nil
	DiffuseTexture() *common.ImportedTexture

	// NormalTexture retrieves the normal map texture data reference, or nil if none is set.
	//
	// Returns:
	//   - *common.ImportedTexture: the normal texture, or nil
	NormalTexture() *common.ImportedTexture

	// MetallicRoughnessTexture retrieves the metallic-roughness texture data reference, or nil if none is set.
	//
	// Returns:
	//   - *common.ImportedTexture: the metallic-roughness texture, or nil
	MetallicRoughnessTexture() *common.ImportedTexture

	// PipelineKey retrieves the key identifying the render pipeline this material uses.
	//
	// Returns:
	//   - string: the pipeline key
	PipelineKey() string

	// BindGroupProvider retrieves the bind group provider holding GPU-side resources for this material.
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the bind group provider, or nil if not yet initialized
	BindGroupProvider() bind_group_provider.BindGroupProvider

	// SetPipelineKey sets the render pipeline key for this material.
	//
	// Parameters:
	//   - key: the pipeline key to associate with this material
	SetPipelineKey(key string)

	// SetBindGroupProvider sets the bind group provider for this material.
	//
	// Parameters:
	//   - provider: the bind group provider containing GPU resources for this material
	SetBindGroupProvider(provider bind_group_provider.BindGroupProvider)

	// FragmentShaderPath retrieves the path to the fragment shader associated with this material.
	// An empty string indicates that the engine default fragment shader should be used.
	//
	// Returns:
	//   - string: the fragment shader asset path, or empty for the engine default
	FragmentShaderPath() string

	// SetFragmentShaderPath sets the path to the fragment shader for this material.
	//
	// Parameters:
	//   - path: the fragment shader asset path
	SetFragmentShaderPath(path string)

	// Provider retrieves the bind group provider associated with the specified group index.
	// Returns nil if no provider has been set for the given group.
	//
	// Parameters:
	//   - group: the bind group index to look up
	//
	// Returns:
	//   - bind_group_provider.BindGroupProvider: the provider for the group, or nil
	Provider(group int) bind_group_provider.BindGroupProvider

	// SetProvider stores a bind group provider for the specified group index.
	// This allows a material to own GPU resources across multiple bind groups
	// (e.g. textures at one group and effect uniforms at another).
	//
	// Parameters:
	//   - group: the bind group index
	//   - provider: the bind group provider to associate with the group
	SetProvider(group int, provider bind_group_provider.BindGroupProvider)
}

Material defines the interface for a render material, encapsulating surface properties, texture references, and GPU resource bindings needed for draw calls.

Surface properties (name, base color, metallic, roughness, textures) are set at load time and are read-only through this interface. GPU resource references (pipeline key, bind group provider) are mutable so they can be configured after construction during the Loader GPU-init phase.

func NewMaterial

func NewMaterial(options ...MaterialBuilderOption) Material

NewMaterial creates a new Material instance configured with the provided options.

Parameters:

  • options: variadic list of MaterialBuilderOption functions to configure the material

Returns:

  • Material: a new Material instance

type MaterialBuilderOption

type MaterialBuilderOption func(*material)

MaterialBuilderOption is a function that configures a material instance during construction.

func WithBaseColor

func WithBaseColor(color [4]float32) MaterialBuilderOption

WithBaseColor is an option builder that sets the albedo/diffuse RGBA color of the material.

Parameters:

  • color: the base color as RGBA float32 values

Returns:

  • MaterialBuilderOption: a function that applies the base color option to a material

func WithBindGroupProvider

func WithBindGroupProvider(provider bind_group_provider.BindGroupProvider) MaterialBuilderOption

WithBindGroupProvider is an option builder that sets the bind group provider for the material.

Parameters:

  • provider: the bind group provider containing GPU resources for the material

Returns:

  • MaterialBuilderOption: a function that applies the bind group provider option to a material

func WithDiffuseTexture

func WithDiffuseTexture(tex *common.ImportedTexture) MaterialBuilderOption

WithDiffuseTexture is an option builder that sets the diffuse/albedo texture reference.

Parameters:

  • tex: the imported texture data for the diffuse map

Returns:

  • MaterialBuilderOption: a function that applies the diffuse texture option to a material

func WithFragmentShaderPath added in v0.1.0

func WithFragmentShaderPath(path string) MaterialBuilderOption

WithFragmentShaderPath is an option builder that sets the fragment shader asset path for the material. An empty path (the default) tells the engine to use its standard textured fragment shader.

Parameters:

  • path: the fragment shader asset path relative to the project root

Returns:

  • MaterialBuilderOption: a function that applies the fragment shader path option to a material

func WithMetallic

func WithMetallic(metallic float32) MaterialBuilderOption

WithMetallic is an option builder that sets the metallic factor of the material.

Parameters:

  • metallic: the metallic factor (0.0 = dielectric, 1.0 = metal)

Returns:

  • MaterialBuilderOption: a function that applies the metallic option to a material

func WithMetallicRoughnessTexture

func WithMetallicRoughnessTexture(tex *common.ImportedTexture) MaterialBuilderOption

WithMetallicRoughnessTexture is an option builder that sets the metallic-roughness texture reference.

Parameters:

  • tex: the imported texture data for the metallic-roughness map

Returns:

  • MaterialBuilderOption: a function that applies the metallic-roughness texture option to a material

func WithName

func WithName(name string) MaterialBuilderOption

WithName is an option builder that sets the name of the material.

Parameters:

  • name: the identifier for the material

Returns:

  • MaterialBuilderOption: a function that applies the name option to a material

func WithNormalTexture

func WithNormalTexture(tex *common.ImportedTexture) MaterialBuilderOption

WithNormalTexture is an option builder that sets the normal map texture reference.

Parameters:

  • tex: the imported texture data for the normal map

Returns:

  • MaterialBuilderOption: a function that applies the normal texture option to a material

func WithPipelineKey

func WithPipelineKey(key string) MaterialBuilderOption

WithPipelineKey is an option builder that sets the render pipeline key for the material.

Parameters:

  • key: the pipeline key to associate with the material

Returns:

  • MaterialBuilderOption: a function that applies the pipeline key option to a material

func WithRoughness

func WithRoughness(roughness float32) MaterialBuilderOption

WithRoughness is an option builder that sets the roughness factor of the material.

Parameters:

  • roughness: the roughness factor (0.0 = smooth, 1.0 = rough)

Returns:

  • MaterialBuilderOption: a function that applies the roughness option to a material

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL