Documentation ¶
Index ¶
- Constants
- func CameraViewMat(pos, target, up math32.Vector3) *math32.Matrix4
- type Ambient
- type Camera
- type Colors
- type Directional
- type Groups
- func (i Groups) Desc() string
- func (i Groups) Int64() int64
- func (i Groups) MarshalText() ([]byte, error)
- func (i *Groups) SetInt64(in int64)
- func (i *Groups) SetString(s string) error
- func (i Groups) String() string
- func (i *Groups) UnmarshalText(text []byte) error
- func (i Groups) Values() []enums.Enum
- type NLights
- type Object
- type Phong
- func (ph *Phong) AddAmbient(color math32.Vector3)
- func (ph *Phong) AddDirectional(color, pos math32.Vector3)
- func (ph *Phong) AddPoint(color, pos math32.Vector3, linDecay, quadDecay float32)
- func (ph *Phong) AddSpot(color, pos, dir math32.Vector3, ...)
- func (ph *Phong) ConfigLights() *Phong
- func (ph *Phong) Release()
- func (ph *Phong) Render(rp *wgpu.RenderPassEncoder)
- func (ph *Phong) RenderEnd(rp *wgpu.RenderPassEncoder)
- func (ph *Phong) RenderOneColor(rp *wgpu.RenderPassEncoder)
- func (ph *Phong) RenderStart() (*wgpu.RenderPassEncoder, error)
- func (ph *Phong) RenderTexture(rp *wgpu.RenderPassEncoder)
- func (ph *Phong) RenderVertexColor(rp *wgpu.RenderPassEncoder)
- func (ph *Phong) ResetAll()
- func (ph *Phong) ResetLights()
- func (ph *Phong) ResetMeshes()
- func (ph *Phong) ResetObjects()
- func (ph *Phong) ResetTextures()
- func (ph *Phong) SetAmbient(idx int, color math32.Vector3)
- func (ph *Phong) SetCamera(view, projection *math32.Matrix4)
- func (ph *Phong) SetDirectional(idx int, color, pos math32.Vector3)
- func (ph *Phong) SetMesh(name string, mesh shape.Mesh)
- func (ph *Phong) SetObject(name string, ob *Object)
- func (ph *Phong) SetPoint(idx int, color, pos math32.Vector3, linDecay, quadDecay float32)
- func (ph *Phong) SetSpot(idx int, color, pos, dir math32.Vector3, ...)
- func (ph *Phong) SetTexture(name string, tx *Texture)
- func (ph *Phong) UseMesh(name string) error
- func (ph *Phong) UseNoTexture()
- func (ph *Phong) UseObject(name string) error
- func (ph *Phong) UseObjectIndex(idx int) error
- func (ph *Phong) UseTexture(name string) error
- type Point
- type Spot
- type Texture
- type Tiling
Constants ¶
const MaxLights = 8
MaxLights is upper limit on number of any given type of light
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ambient ¶
type Ambient struct { // color of light, which multiplies ambient color of materials. Color math32.Vector3 // contains filtered or unexported fields }
Ambient provides diffuse uniform lighting. Typically only one of these.
type Camera ¶
type Camera struct { // View Camera: transforms world into camera-centered, 3D coordinates. View math32.Matrix4 // Projection Camera: transforms camera coords into 2D render coordinates. Projection math32.Matrix4 }
Camera contains the camera view and projection matricies, for uniform uploading.
type Colors ¶
type Colors struct { // main color of surface, used for both ambient and diffuse color // in standard Phong model. Alpha component determines transparency. // Note that transparent objects require more complex rendering. Color math32.Vector4 // ShinyBright has shininess and brightness factors: // // X = shininess spread factor (30 default), which determines // how focally the surface shines back directional light, which // is an exponential factor, where 0 = very broad diffuse reflection, // and higher values (typically max of 128) have a smaller more // focal specular reflection. // // Y = shine reflection factor (1 default), which determines how much // of the incident light is reflected back (0 = no shine). // // Z = brightness factor (1 default), which is an overall multiplier // on final computed color value, which can be used to tune the // overall brightness of various surfaces relative to each other // for a given set of lighting parameters. ShinyBright math32.Vector4 // color that surface emits independent of any lighting, // i.e., glow. Can be used for marking lights with an object. Emissive math32.Vector4 // texture tiling repeat and offset factors. Tiling Tiling }
Colors are the material colors with padding for direct uploading to shader.
func NewColors ¶
NewColors returns a new Colors with given values. Texture defaults to using full texture with 0 offset.
func (*Colors) SetTilingOffset ¶
SetTilingOffset sets texture start offsets in each direction
func (*Colors) SetTilingRepeat ¶
SetTilingRepeat sets how often to repeat the texture in each direction
func (*Colors) UseFullTexture ¶
UseFullTexture sets the texture parameters to render the full texture: repeat = 1,1; offset = 0,0
type Directional ¶
type Directional struct { // color of light at full intensity. Color math32.Vector3 // position of light vector. Think of it shining down from // this position toward the origin, i.e., the negation of // this position is the vector. Pos math32.Vector3 // contains filtered or unexported fields }
Directional is directional light, which is assumed to project light toward the origin based on its position, with no attenuation, like the Sun. For rendering, the position is negated and normalized to get the direction vector (i.e., absolute distance doesn't matter).
type Groups ¶
type Groups int32 //enums:enum
Groups are the VarGroup numbers.
const GroupsN Groups = 4
GroupsN is the highest valid value for type Groups, plus one.
func GroupsValues ¶
func GroupsValues() []Groups
GroupsValues returns all possible values for the type Groups.
func (Groups) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Groups) SetString ¶
SetString sets the Groups value from its string representation, and returns an error if the string is invalid.
func (*Groups) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Object ¶
type Object struct { Colors // Matrix specifies the transformation matrix for this specific Object ("model"). Matrix math32.Matrix4 // contains filtered or unexported fields }
Object is the object-specific data: Colors and transform Matrix. It must be updated on a per-object basis prior to each render pass. It is 8 vec4 in size = 8 * 4 * 4 = 128 bytes.
type Phong ¶
type Phong struct { // The current camera view and projection matricies. // This is used for updating the object WorldMatrix. Camera Camera // number of each type of light NLights NLights // ambient lights Ambient [MaxLights]Ambient // directional lights Directional [MaxLights]Directional // point lights Point [MaxLights]Point // spot lights Spot [MaxLights]Spot // a texture was selected for next draw via [UseTexture]. // if true, overrides other options. UseCurTexture bool // a per-vertex color was selected for next draw. UseVertexColor bool // render using wireframe instead of filled polygons. // this must be set prior to configuring the Phong rendering system. // note: not currently supported in WebGPU. Wireframe bool `default:"false"` // rendering system System *gpu.GraphicsSystem // overall lock on Phong operations, use Lock, Unlock on Phong sync.Mutex // contains filtered or unexported fields }
Phong implements standard Blinn-Phong rendering pipelines in a gpu GraphicsSystem. Add Lights and call SetMesh, SetTexture, SetObject to config.
Rendering starts with RenderStart, followed by Use* calls to specify the render parameters for each item, followed by the Render() method that calls the proper pipeline's render methods.
func NewPhong ¶
NewPhong returns a new Phong system that is ready to be configured by calls to SetMesh, SetTexture, SetObject, in addition to adding lights. Renderer can either be a Surface or a RenderTexture.
func (*Phong) AddAmbient ¶
AddAmbient adds Ambient light at given position
func (*Phong) AddDirectional ¶
AddDirectional adds directional light
func (*Phong) AddSpot ¶
func (ph *Phong) AddSpot(color, pos, dir math32.Vector3, angDecay, cutAngle, linDecay, quadDecay float32)
AddSpot adds spot light Defaults: angDecay=15, cutAngle=45 (max 90), linDecay=.01, quadDecay=0.001
func (*Phong) ConfigLights ¶
ConfigLights can be called after initial Config whenver the Lights data has changed, to sync changes up to the GPU.
func (*Phong) Release ¶
func (ph *Phong) Release()
Release should be called to release all the GPU resources.
func (*Phong) Render ¶
func (ph *Phong) Render(rp *wgpu.RenderPassEncoder)
Render does one step of rendering given current Use* settings, which can be updated in between subsequent Render calls.
func (*Phong) RenderEnd ¶
func (ph *Phong) RenderEnd(rp *wgpu.RenderPassEncoder)
func (*Phong) RenderOneColor ¶
func (ph *Phong) RenderOneColor(rp *wgpu.RenderPassEncoder)
RenderOneColor renders current settings to onecolor pipeline.
func (*Phong) RenderStart ¶
func (ph *Phong) RenderStart() (*wgpu.RenderPassEncoder, error)
RenderStart starts the render pass, returning the RenderPassEncoder used for encoding the rendering commands for this pass. This also ensures that all updated object data from SetObject* calls is transferred to the GPU.
func (*Phong) RenderTexture ¶
func (ph *Phong) RenderTexture(rp *wgpu.RenderPassEncoder)
RenderTexture renders current settings to texture pipeline
func (*Phong) RenderVertexColor ¶
func (ph *Phong) RenderVertexColor(rp *wgpu.RenderPassEncoder)
RenderVertexColor renders current settings to vertexcolor pipeline
func (*Phong) ResetAll ¶
func (ph *Phong) ResetAll()
ResetAll resets all the dynamic resources: Objects, Meshes, Textures and Lights.
func (*Phong) ResetLights ¶
func (ph *Phong) ResetLights()
ResetLights resets number of lights to 0 -- for reconfig
func (*Phong) ResetMeshes ¶
func (ph *Phong) ResetMeshes()
ResetMeshes resets the meshes for reconfiguring.
func (*Phong) ResetObjects ¶
func (ph *Phong) ResetObjects()
ResetObjects resets the objects for reconfiguring
func (*Phong) SetAmbient ¶
SetAmbient sets Ambient light at index to given position
func (*Phong) SetCamera ¶
SetCamera the camera view and projection matrixes, and updates uniform data, so they are ready to use.
func (*Phong) SetDirectional ¶
SetDirectional sets directional light at given index
func (*Phong) SetMesh ¶
SetMesh sets a Mesh using the shape.Mesh interface for the source of the mesh data, and sets the values directly. If Mesh already exists, then data is updated. It is ready for [UseMesh] after this point.
func (*Phong) SetObject ¶
SetObject sets Object data with given unique name identifier. If object already exists, then data is updated if different.
func (*Phong) SetPoint ¶
SetPoint sets point light at given index. Defaults: linDecay=.1, quadDecay=.01
func (*Phong) SetSpot ¶
func (ph *Phong) SetSpot(idx int, color, pos, dir math32.Vector3, angDecay, cutAngle, linDecay, quadDecay float32)
SetSpot sets spot light at given index Defaults: angDecay=15, cutAngle=45 (max 90), linDecay=.01, quadDecay=0.001
func (*Phong) SetTexture ¶
SetTexture sets given Texture to be available for [UseTexture] call during render. If it already exists, it is updated, otherwise added.
func (*Phong) UseMesh ¶
UseMesh selects mesh by name for current render step. Mesh must have been added / updated via SetMesh method. If mesh has per-vertex colors, these are selected for rendering, and texture is turned off. UseTexture* after this to override.
func (*Phong) UseNoTexture ¶
func (ph *Phong) UseNoTexture()
UseNoTexture turns off texture rendering
func (*Phong) UseObject ¶
UseObject selects object by name for current render step. Object must have already been added / updated via [SetObject]. If object has per-vertex colors, these are selected for rendering, and texture is turned off. UseTexture* after this to override.
func (*Phong) UseObjectIndex ¶
UseObjectIndex selects object by index for current render step. If object has per-vertex colors, these are selected for rendering, and texture is turned off. UseTexture* after this to override.
func (*Phong) UseTexture ¶
UseTexture selects texture by name for current render step.
type Point ¶
type Point struct { // color of light a full intensity. Color math32.Vector3 // position of light in world coordinates. Pos math32.Vector3 // X = Linear distance decay factor (default .01). // Y = Quadratic distance quadratic decay factor // (default .001, dominates at longer distances) Decay math32.Vector3 // contains filtered or unexported fields }
Point is an omnidirectional light with a position and associated decay factors, which divide the light intensity as a function of linear and quadratic distance. The quadratic factor dominates at longer distances.
type Spot ¶
type Spot struct { // color of light a full intensity. Color math32.Vector3 // position of light in world coordinates. Pos math32.Vector3 // direction of light vector. Dir math32.Vector3 // X = Angular decay, in degrees (15 default) // Y = CutAngle is cutoff angle in degrees beyond which no light (45 default). // Z = LinDecay distance linear decay (.01 default) // W = QuadDecay distance Distance quadratic decay factor (0.001 default), // which dominates at longer distances Decay math32.Vector4 // contains filtered or unexported fields }
Spotlight is a light with a position and direction and associated decay factors and angles, which divide the light intensity as a function of linear and quadratic distance. The quadratic factor dominates at longer distances.
type Texture ¶
Texture has texture image and other params. Stored as image.RGBA for GPU compatibility.