graphics

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	Node
	// contains filtered or unexported fields
}

Camera represents a 3D camera.

func (*Camera) AspectRatio

func (c *Camera) AspectRatio() float32

AspectRatio returns the aspect ratio to be maintained when rendering with this camera. This setting works in combination with FoVMode and FoV settings.

func (*Camera) AutoExposure

func (c *Camera) AutoExposure() bool

AutoExposure returns whether this camera will try and automatically adjust the exposure setting to maintain a proper brightness of the final image.

func (*Camera) AutoFocus

func (c *Camera) AutoFocus() bool

AutoFocus returns whether this camera will try and automatically focus on objects.

func (*Camera) Delete

func (c *Camera) Delete()

Delete removes this camera from the scene.

func (*Camera) Exposure

func (c *Camera) Exposure() float32

Exposure returns the exposure setting of this camera.

func (*Camera) FoV

func (c *Camera) FoV() sprec.Angle

FoV returns the field-of-view angle for this camera.

func (*Camera) FoVMode

func (c *Camera) FoVMode() FoVMode

FoVMode returns the mode of field-of-view. This determines how the FoV setting is used to calculate the final image in the vertical and horizontal directions.

func (*Camera) FocusRange

func (c *Camera) FocusRange() (float32, float32)

FocusRange changes the range from near to far in which the image will be in focus.

func (*Camera) MaximumExposure added in v0.3.0

func (c *Camera) MaximumExposure() float32

MaximumExposure returns the maximum exposure that the camera may use during AutoExposure.

func (*Camera) MinimumExposure added in v0.3.0

func (c *Camera) MinimumExposure() float32

MinimumExposure returns the maximum exposure that the camera may use during AutoExposure.

func (*Camera) SetAspectRatio

func (c *Camera) SetAspectRatio(ratio float32)

SetAspectRatio changes the aspect ratio of this camera.

func (*Camera) SetAutoExposure

func (c *Camera) SetAutoExposure(enabled bool)

SetAutoExposure changes whether this cammera should attempt to do automatic exposure adjustment.

func (*Camera) SetAutoFocus

func (c *Camera) SetAutoFocus(enabled bool)

SetAutoFocus changes whether this camera should attempt to automatically focus on object in the scene.

func (*Camera) SetExposure

func (c *Camera) SetExposure(exposure float32)

SetExposure changes the exposure setting of this camera. Smaller values mean that the final image will be darker and higher values mean that the final image will be brighter with 1.0 being the starting point.

func (*Camera) SetFoV

func (c *Camera) SetFoV(angle sprec.Angle)

SetFoV changes the field-of-view angle setting of this camera.

func (*Camera) SetFoVMode

func (c *Camera) SetFoVMode(mode FoVMode)

SetFoVMode changes the field-of-view mode of this camera.

func (*Camera) SetFocusRange

func (c *Camera) SetFocusRange(near, far float32)

SetFocusRange changes the focus range for this camera.

func (*Camera) SetMaximumExposure added in v0.3.0

func (c *Camera) SetMaximumExposure(maxExposure float32)

SetMaximumExposure changes the maximum exposure for this camera.

func (*Camera) SetMinimumExposure added in v0.3.0

func (c *Camera) SetMinimumExposure(minExposure float32)

SetMinimumExposure changes the maximum exposure for this camera.

type CubeTexture

type CubeTexture struct {
	// contains filtered or unexported fields
}

CubeTexture represents a cube texture.

func (*CubeTexture) Delete

func (t *CubeTexture) Delete()

Delete releases any resources allocated for this texture.

type CubeTextureDefinition

type CubeTextureDefinition struct {
	Dimension int

	MinFilter Filter
	MagFilter Filter

	InternalFormat InternalFormat
	DataFormat     DataFormat

	FrontSideData  []byte
	BackSideData   []byte
	LeftSideData   []byte
	RightSideData  []byte
	TopSideData    []byte
	BottomSideData []byte
}

CubeTextureDefinition contains all the information needed to create a CubeTexture.

type DataFormat

type DataFormat int
const (
	DataFormatRGBA8 DataFormat = 1 + iota
	DataFormatRGBA32F
)

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine represents an entrypoint to 3D graphics rendering.

func NewEngine added in v0.4.0

func NewEngine(api render.API, shaders ShaderCollection) *Engine

func (*Engine) Create

func (e *Engine) Create()

Create initializes this 3D engine.

func (*Engine) CreateCubeTexture

func (e *Engine) CreateCubeTexture(definition CubeTextureDefinition) *CubeTexture

CreateCubeTexture creates a new CubeTexture using the specified definition.

func (*Engine) CreateMeshTemplate

func (e *Engine) CreateMeshTemplate(definition MeshTemplateDefinition) *MeshTemplate

CreateMeshTemplate creates a new MeshTemplate using the specified definition.

func (*Engine) CreatePBRMaterial

func (e *Engine) CreatePBRMaterial(definition PBRMaterialDefinition) *Material

CreatePBRMaterial creates a new Material that is based on PBR definition.

func (*Engine) CreateScene

func (e *Engine) CreateScene() *Scene

CreateScene creates a new 3D Scene. Entities managed within a given scene are isolated within that scene.

func (*Engine) CreateTwoDTexture

func (e *Engine) CreateTwoDTexture(definition TwoDTextureDefinition) *TwoDTexture

CreateTwoDTexture creates a new TwoDTexture using the specified definition.

func (*Engine) Destroy

func (e *Engine) Destroy()

Destroy releases resources allocated by this 3D engine.

type Filter

type Filter int
const (
	FilterNearest Filter = 1 + iota
	FilterLinear
	FilterNearestMipmapNearest
	FilterNearestMipmapLinear
	FilterLinearMipmapNearest
	FilterLinearMipmapLinear
)

type FoVMode

type FoVMode string

FoVMode determines how the camera field of view is calculated in the horizontal and vertical directions.

const (
	// FoVModeAnamorphic will abide to the aspect ratio setting
	// and will pillerbox the image if necessary.
	FoVModeAnamorphic FoVMode = "anamorphic"

	// FoVModeHorizontalPlus will apply the FoV setting to the
	// vertical direction and will adjust the horizontal direction
	// accordingly to preserve the screen's aspect ratio.
	FoVModeHorizontalPlus FoVMode = "horizontal-plus"

	// FoVModeVertialMinus will apply the FoV setting to the
	// horizontal direction and will adjust the vertical direction
	// accordingly to preserve the screen's aspect ratio.
	FoVModeVertialMinus FoVMode = "vertical-minus"

	// FoVModePixelBased will use an orthogonal projection that
	// will match in side the screen pixel size.
	FoVModePixelBased FoVMode = "pixel-based"
)

type IndexFormat

type IndexFormat int
const (
	IndexFormatU16 IndexFormat = 1 + iota
	IndexFormatU32
)

type InternalFormat

type InternalFormat int
const (
	InternalFormatRGBA8 InternalFormat = 1 + iota
	InternalFormatRGBA32F
)

type Light

type Light struct {
	Node
	// contains filtered or unexported fields
}

Light represents a light emitting object in the scene.

func (*Light) Delete

func (l *Light) Delete()

func (*Light) Intensity

func (l *Light) Intensity() sprec.Vec3

Intensity returns the light intensity.

func (*Light) Mode added in v0.4.0

func (l *Light) Mode() LightMode

func (*Light) ReflectionTexture added in v0.4.0

func (l *Light) ReflectionTexture() *CubeTexture

ReflectionTexture returns the texture that is used to calculate the lighting on an object as a result of reflected light rays.

func (*Light) RefractionTexture added in v0.4.0

func (l *Light) RefractionTexture() *CubeTexture

RefractionTexture returns the texture that is used to calculate the lighting on an object as a result of refracted light rays.

func (*Light) SetIntensity

func (l *Light) SetIntensity(intensity sprec.Vec3)

SetIntensity changes the light intensity.

func (*Light) SetMode added in v0.4.0

func (l *Light) SetMode(mode LightMode)

func (*Light) SetReflectionTexture added in v0.4.0

func (l *Light) SetReflectionTexture(texture *CubeTexture)

SetReflectionTexture changes the reflection texture.

func (*Light) SetRefractionTexture added in v0.4.0

func (l *Light) SetRefractionTexture(texture *CubeTexture)

SetRefractionTexture changes the refraction texture.

type LightMode added in v0.4.0

type LightMode int
const (
	LightModeDirectional LightMode = 1 + iota
	LightModeAmbient
)

type Material

type Material struct {
	// contains filtered or unexported fields
}

Material determines the appearance of a mesh on the screen.

func (*Material) Delete

func (m *Material) Delete()

Delete releases resources allocated for this material.

type Mesh

type Mesh struct {
	Node
	// contains filtered or unexported fields
}

Mesh represents an instance of a 3D mesh.

func (*Mesh) Delete

func (m *Mesh) Delete()

Delete removes this mesh from the scene.

type MeshTemplate

type MeshTemplate struct {
	// contains filtered or unexported fields
}

MeshTemplate represents the definition of a mesh. Multiple mesh instances can be created off of one template reusing resources.

func (*MeshTemplate) Delete

func (t *MeshTemplate) Delete()

Delete releases any resources allocated by this template.

type MeshTemplateDefinition

type MeshTemplateDefinition struct {
	VertexData   []byte
	VertexFormat VertexFormat
	IndexData    []byte
	IndexFormat  IndexFormat
	SubMeshes    []SubMeshTemplateDefinition
}

MeshTemplateDefinition contains everything needed to create a new MeshTemplate.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a positioning of some entity in the 3D scene.

func (*Node) Matrix added in v0.4.0

func (n *Node) Matrix() sprec.Mat4

Matrix returns the matrix transformation of this node.

func (*Node) Position

func (n *Node) Position() sprec.Vec3

Position returns this entity's position.

func (*Node) Rotation

func (n *Node) Rotation() sprec.Quat

Rotation returns this entity's rotation.

func (*Node) Scale

func (n *Node) Scale() sprec.Vec3

Scale returns this entity's scale.

func (*Node) SetPosition

func (n *Node) SetPosition(position sprec.Vec3)

SetPosition changes this entity's position.

func (*Node) SetRotation

func (n *Node) SetRotation(rotation sprec.Quat)

SetRotation changes this entity's rotation.

func (*Node) SetScale

func (n *Node) SetScale(scale sprec.Vec3)

SetScale changes this entity's scale.

type PBRMaterialDefinition

type PBRMaterialDefinition struct {
	BackfaceCulling  bool
	AlphaBlending    bool
	AlphaTesting     bool
	AlphaThreshold   float32
	Metalness        float32
	MetalnessTexture *TwoDTexture
	Roughness        float32
	RoughnessTexture *TwoDTexture
	AlbedoColor      sprec.Vec4
	AlbedoTexture    *TwoDTexture
	NormalScale      float32
	NormalTexture    *TwoDTexture
}

PBRMaterialDefinition contains the information needed to create a PBR Material.

type Primitive

type Primitive int
const (
	PrimitivePoints Primitive = 1 + iota
	PrimitiveLines
	PrimitiveLineStrip
	PrimitiveLineLoop
	PrimitiveTriangles
	PrimitiveTriangleStrip
	PrimitiveTriangleFan
)

type Scene

type Scene struct {
	// contains filtered or unexported fields
}

Scene represents a collection of 3D render entities that comprise a single visual scene.

func (*Scene) CreateAmbientLight

func (s *Scene) CreateAmbientLight() *Light

CreateAmbientLight creates a new ambient light object to be used within this scene.

func (*Scene) CreateCamera

func (s *Scene) CreateCamera() *Camera

CreateCamera creates a new camera object to be used with this scene.

func (*Scene) CreateDirectionalLight

func (s *Scene) CreateDirectionalLight() *Light

CreateDirectionalLight creates a new directional light object to be used within this scene.

func (*Scene) CreateMesh

func (s *Scene) CreateMesh(template *MeshTemplate) *Mesh

CreateMesh creates a new mesh instance from the specified template and places it in the scene.

func (*Scene) Delete

func (s *Scene) Delete()

Delete removes this scene and releases all entities allocated for it.

func (*Scene) Render

func (s *Scene) Render(viewport Viewport, camera *Camera)

Render draws this scene to the specified viewport looking through the specified camera.

func (*Scene) RenderFramebuffer added in v0.4.0

func (s *Scene) RenderFramebuffer(framebuffer render.Framebuffer, viewport Viewport, camera *Camera)

Render draws this scene to the specified viewport looking through the specified camera.

func (*Scene) Sky

func (s *Scene) Sky() *Sky

Sky returns this scene's sky object. You can use the Sky object to control the background appearance.

type ShaderCollection added in v0.4.0

type ShaderCollection struct {
	ExposureSet         func() ShaderSet
	PostprocessingSet   func(mapping ToneMapping) ShaderSet
	DirectionalLightSet func() ShaderSet
	AmbientLightSet     func() ShaderSet
	SkyboxSet           func() ShaderSet
	SkycolorSet         func() ShaderSet
	PBRShaderSet        func(definition PBRMaterialDefinition) ShaderSet
}

type ShaderSet added in v0.4.0

type ShaderSet struct {
	VertexShader   func() string
	FragmentShader func() string
}

type Sky

type Sky struct {
	// contains filtered or unexported fields
}

Sky represents the Scene's background.

func (*Sky) BackgroundColor

func (s *Sky) BackgroundColor() sprec.Vec3

BackgroundColor returns the color of the background.

func (*Sky) SetBackgroundColor

func (s *Sky) SetBackgroundColor(color sprec.Vec3)

SetBackgroundColor changes the color of the background.

func (*Sky) SetSkybox

func (s *Sky) SetSkybox(skybox *CubeTexture)

SetSkybox sets a cube texture to be used as the background. If nil is specified, then a texture will not be used and instead the background color will be drawn instead.

func (*Sky) Skybox

func (s *Sky) Skybox() *CubeTexture

// Skybox returns the cube texture to be used as the background. // If one has not been set, this method returns nil.

type SubMeshTemplateDefinition

type SubMeshTemplateDefinition struct {
	Primitive   Primitive
	IndexOffset int
	IndexCount  int
	Material    *Material
}

SubMeshTemplateDefinition represents a portion of a mesh that is drawn with a specific material.

type ToneMapping added in v0.4.0

type ToneMapping string
const (
	ReinhardToneMapping    ToneMapping = "reinhard"
	ExponentialToneMapping ToneMapping = "exponential"
)

type TwoDTexture

type TwoDTexture struct {
	// contains filtered or unexported fields
}

TwoDTexture represents a two-dimensional texture.

func (*TwoDTexture) Delete

func (t *TwoDTexture) Delete()

Delete releases any resources allocated for this texture.

type TwoDTextureDefinition

type TwoDTextureDefinition struct {
	Width  int
	Height int

	WrapS Wrap
	WrapT Wrap

	MinFilter     Filter
	MagFilter     Filter
	UseAnisotropy bool

	InternalFormat InternalFormat
	DataFormat     DataFormat

	Data []byte
}

TwoDTextureDefinition contains all the information needed to create a TwoDTexture.

type VertexFormat

type VertexFormat struct {
	HasCoord            bool
	CoordOffsetBytes    int
	CoordStrideBytes    int
	HasNormal           bool
	NormalOffsetBytes   int
	NormalStrideBytes   int
	HasTangent          bool
	TangentOffsetBytes  int
	TangentStrideBytes  int
	HasTexCoord         bool
	TexCoordOffsetBytes int
	TexCoordStrideBytes int
	HasColor            bool
	ColorOffsetBytes    int
	ColorStrideBytes    int
}

type Viewport

type Viewport struct {
	X      int
	Y      int
	Width  int
	Height int
}

Viewport represents an area on the screen to which rendering will occur.

func NewViewport

func NewViewport(x, y, width, height int) Viewport

NewViewport creates a new Viewport with the specified parameters.

type Wrap

type Wrap int
const (
	WrapClampToEdge Wrap = 1 + iota
	WrapRepeat
	WrapMirroredRepat
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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