Documentation
¶
Index ¶
- Constants
- func CameraViewMat(pos, target, up math32.Vector3) *math32.Matrix4
- type AmbientLight
- type Colors
- type CurRender
- type DirLight
- type Mesh
- type Mtxs
- type NLights
- type Phong
- func (ph *Phong) AddAmbientLight(color math32.Vector3)
- func (ph *Phong) AddColor(name string, clr *Colors)
- func (ph *Phong) AddDirLight(color, pos math32.Vector3)
- func (ph *Phong) AddMesh(name string, numVertex, nIndex int, hasColor bool)
- func (ph *Phong) AddPointLight(color, pos math32.Vector3, linDecay, quadDecay float32)
- func (ph *Phong) AddSpotLight(color, pos, dir math32.Vector3, ...)
- func (ph *Phong) AddTexture(name string, tex *Texture)
- func (ph *Phong) AllocTextures()
- func (ph *Phong) Config()
- func (ph *Phong) ConfigLights()
- func (ph *Phong) ConfigMeshes()
- func (ph *Phong) ConfigMeshesTextures()
- func (ph *Phong) ConfigPipeline(pl *vgpu.Pipeline)
- func (ph *Phong) ConfigSys()
- func (ph *Phong) ConfigTextures()
- func (ph *Phong) DeleteMesh(name string)
- func (ph *Phong) DeleteTexture(name string)
- func (ph *Phong) Destroy()
- func (ph *Phong) MeshFloatsByIndex(i int) (pos, norm, tex, clr math32.ArrayF32, idx math32.ArrayU32)
- func (ph *Phong) MeshFloatsByName(name string) (pos, norm, tex, clr math32.ArrayF32, idx math32.ArrayU32)
- func (ph *Phong) ModMeshByIndex(i int)
- func (ph *Phong) ModMeshByName(name string)
- func (ph *Phong) Push(pl *vgpu.Pipeline, push *PushU)
- func (ph *Phong) Render()
- func (ph *Phong) RenderOnecolor()
- func (ph *Phong) RenderTexture()
- func (ph *Phong) RenderVtxColor()
- func (ph *Phong) ResetMeshes()
- func (ph *Phong) ResetNLights()
- func (ph *Phong) ResetTextures()
- func (ph *Phong) SetAmbientLight(idx int, color math32.Vector3)
- func (ph *Phong) SetDirLight(idx int, color, pos math32.Vector3)
- func (ph *Phong) SetModelMtx(model *math32.Matrix4)
- func (ph *Phong) SetPointLight(idx int, color, pos math32.Vector3, linDecay, quadDecay float32)
- func (ph *Phong) SetSpotLight(idx int, color, pos, dir math32.Vector3, ...)
- func (ph *Phong) SetViewProjection(view, projection *math32.Matrix4)
- func (ph *Phong) Sync()
- func (ph *Phong) UpdateTextureIndex(idx int) error
- func (ph *Phong) UpdateTextureName(name string) error
- func (ph *Phong) UseColor(clr, emis color.Color, shiny, reflect, bright float32)
- func (ph *Phong) UseColorIndex(idx int) error
- func (ph *Phong) UseColorName(name string) error
- func (ph *Phong) UseFullTexture()
- func (ph *Phong) UseMeshIndex(idx int) error
- func (ph *Phong) UseMeshName(name string) error
- func (ph *Phong) UseNoTexture()
- func (ph *Phong) UseTextureIndex(idx int) error
- func (ph *Phong) UseTextureName(name string) error
- func (ph *Phong) UseTexturePars(repeat math32.Vector2, off math32.Vector2)
- type PointLight
- type PushU
- type Sets
- type SpotLight
- type TexPars
- type Texture
Constants ¶
const MaxLights = 8
MaxLights is upper limit on number of any given type of light
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AmbientLight ¶
type AmbientLight struct { // color of light -- multiplies ambient color of materials Color math32.Vector3 // contains filtered or unexported fields }
AmbientLight provides diffuse uniform lighting -- typically only one of these
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 // X = shininess spread factor, Y = shine reflection factor, Z = brightness factor: shiny = specular shininess factor -- how focally the surface shines back directional light -- this is an exponential factor, with 0 = very broad diffuse reflection, and higher values (typically max of 128) having a smaller more focal specular reflection. Shine reflect = 1 for full shine white reflection (specular) color, 0 = no shine reflection. bright = overall multiplier on final computed color value -- can be used to tune the overall brightness of various surfaces relative to each other for a given set of lighting parameters. W is used for Tex idx. 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 }
Colors are the material colors with padding for direct uploading to shader
type CurRender ¶
type CurRender struct { // index of descriptor collection to use -- for threaded / parallel rendering -- see vgup.Vars NDescs for more info DescIndex int // a texture was selected -- if true, overrides other options UseTexture bool // a per-vertex color was selected UseVtxColor bool // current model pose matrix ModelMtx math32.Matrix4 // camera view and projection matrixes VPMtx Mtxs // current color surface properties Color Colors // texture parameters -- repeat, offset TexPars TexPars // index of currently selected texture TexIndex int }
CurRender holds info about the current render as updated by Use* methods -- determines which pipeline is used. Default is single color.
type DirLight ¶
type DirLight 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 }
DirLight 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 Mesh ¶
type Mesh struct { // number of vertex points, as math32.Vector3 -- always includes math32.Vector3 normals and math32.Vector2 texture coordinates NVtx int // number of indexes, as math32.ArrayU32 NIndex int // has per-vertex colors, as math32.Vector4 per vertex HasColor bool }
Mesh records the number of elements in an indexed triangle mesh, which always includes normals and texture coordinates, and optionally per-vertex colors.
type Mtxs ¶
type Mtxs struct { // View Matrix: transforms world into camera-centered, 3D coordinates View math32.Matrix4 // Projection Matrix: transforms camera coords into 2D render coordinates Projection math32.Matrix4 }
Mtxs contains the camera view and projection matricies, for uniform uploading
type Phong ¶
type Phong struct { // number of each type of light NLights NLights // ambient lights Ambient [MaxLights]AmbientLight // directional lights Dir [MaxLights]DirLight // point lights Point [MaxLights]PointLight // spot lights Spot [MaxLights]SpotLight // render using wireframe instead of filled polygons -- this must be set prior to configuring the Phong rendering system Wireframe bool `default:"false"` // state for current rendering Cur CurRender // meshes -- holds all the mesh data -- must be configured prior to rendering Meshes ordmap.Map[string, *Mesh] // textures -- must be configured prior to rendering -- a maximum of 16 textures is supported for full cross-platform portability Textures ordmap.Map[string, *Texture] // colors, optionally available for looking up by name -- not used directly in rendering Colors ordmap.Map[string, *Colors] // rendering system Sys vgpu.System // mutex on updating UpdateMu sync.Mutex `display:"-" copier:"-" json:"-" xml:"-"` }
Phong implements standard Blinn-Phong rendering pipelines in a vgpu System. Must Add all Lights, Meshes, Colors, Textures first, and call Config() to configure everything prior to first RenderStart.
Meshes are configured initially with numbers of points, then after Config(), points are set by calling MeshFloatsBy* and assigning values.
If any changes are made to numbers or sizes of anything, you must call Config() again.
Changes to data only can be synced by calling Sync()
Rendering starts with RenderStart, followed by Use* calls to specify the parameters for each item, and then a Draw call to add the rendering command, followed by RenderEnd.
func (*Phong) AddAmbientLight ¶
AddAmbientLight adds Ambient light at given position
func (*Phong) AddDirLight ¶
AddDirLight adds directional light
func (*Phong) AddMesh ¶
AddMesh adds a Mesh with name and given number of vertices, indexes, and optional per-vertex color
func (*Phong) AddPointLight ¶
AddPointLight adds point light. Defaults: linDecay=.1, quadDecay=.01
func (*Phong) AddSpotLight ¶
func (ph *Phong) AddSpotLight(color, pos, dir math32.Vector3, angDecay, cutAngle, linDecay, quadDecay float32)
AddSpotLight adds spot light Defaults: angDecay=15, cutAngle=45 (max 90), linDecay=.01, quadDecay=0.001
func (*Phong) AddTexture ¶
AddTexture adds to list of textures
func (*Phong) AllocTextures ¶
func (ph *Phong) AllocTextures()
AllocTextures allocates textures that have been previously configured, via ConfigTextures(), after Phong.Sys.Config() has been called.
func (*Phong) Config ¶
func (ph *Phong) Config()
Config configures everything after everything has been Added
func (*Phong) ConfigLights ¶
func (ph *Phong) ConfigLights()
ConfigLights configures the rendering for the lights that have been added.
func (*Phong) ConfigMeshes ¶
func (ph *Phong) ConfigMeshes()
ConfigMeshes configures vals for meshes -- this is the first of two passes in configuring and setting mesh values -- Phong.Sys.Config is called after this method (and everythign else is configured).
func (*Phong) ConfigMeshesTextures ¶
func (ph *Phong) ConfigMeshesTextures()
ConfigMeshesTextures configures the Meshes and Textures based on everything added in the Phong config, prior to Sys.Config() which does host allocation.
func (*Phong) ConfigPipeline ¶
ConfigPipeline configures graphics settings on the pipeline
func (*Phong) ConfigSys ¶
func (ph *Phong) ConfigSys()
ConfigSys configures the vDraw System and pipelines.
func (*Phong) ConfigTextures ¶
func (ph *Phong) ConfigTextures()
ConfigTextures configures vals for textures -- this is the first of two passes -- call Phong.Sys.Config after everything is config'd. This automatically allocates images by size so everything fits within the MaxTexturesPerStage limit, as texture arrays.
func (*Phong) DeleteMesh ¶
DeleteMesh deletes Mesh with name
func (*Phong) DeleteTexture ¶
DeleteTexture deletes texture with name
func (*Phong) MeshFloatsByIndex ¶ added in v0.0.10
func (ph *Phong) MeshFloatsByIndex(i int) (pos, norm, tex, clr math32.ArrayF32, idx math32.ArrayU32)
MeshFloatsByIndex returns the math32.ArrayF32's and math32.ArrayU32 for given mesh for assigning values to the mesh. Must call ModMeshByIndex after setting these values to mark as modified.
func (*Phong) MeshFloatsByName ¶
func (ph *Phong) MeshFloatsByName(name string) (pos, norm, tex, clr math32.ArrayF32, idx math32.ArrayU32)
MeshFloatsByName returns the math32.ArrayF32's and math32.ArrayU32 for given mesh for assigning values to the mesh. Must call ModMeshByName after setting these values to mark as modified.
func (*Phong) ModMeshByIndex ¶ added in v0.0.10
ModMeshByIndex marks given mesh by index as modified. Must call after modifying mesh values, to mark for syncing
func (*Phong) ModMeshByName ¶
ModMeshByName marks given mesh by name as modified. Must call after modifying mesh values, to mark for syncing
func (*Phong) Render ¶
func (ph *Phong) Render()
Render does one step of rendering given current Use* settings
func (*Phong) RenderOnecolor ¶
func (ph *Phong) RenderOnecolor()
RenderOnecolor renders current settings to onecolor pipeline
func (*Phong) RenderTexture ¶
func (ph *Phong) RenderTexture()
RenderTexture renders current settings to texture pipeline
func (*Phong) RenderVtxColor ¶
func (ph *Phong) RenderVtxColor()
RenderVtxColor renders current settings to vertexcolor pipeline
func (*Phong) ResetMeshes ¶
func (ph *Phong) ResetMeshes()
ResetMeshes resets the meshes for reconfiguring
func (*Phong) ResetNLights ¶
func (ph *Phong) ResetNLights()
ResetNLights resets number of lights to 0 -- for reconfig
func (*Phong) SetAmbientLight ¶
SetAmbientLight sets Ambient light at index to given position
func (*Phong) SetDirLight ¶
SetDirLight sets directional light at given index
func (*Phong) SetModelMtx ¶
SetModelMtx sets the model pose matrix -- must be set per render step (otherwise last one will be used)
func (*Phong) SetPointLight ¶
SetPointLight sets point light at given index. Defaults: linDecay=.1, quadDecay=.01
func (*Phong) SetSpotLight ¶
func (ph *Phong) SetSpotLight(idx int, color, pos, dir math32.Vector3, angDecay, cutAngle, linDecay, quadDecay float32)
SetSpotLight sets spot light at given index Defaults: angDecay=15, cutAngle=45 (max 90), linDecay=.01, quadDecay=0.001
func (*Phong) SetViewProjection ¶ added in v0.1.3
SetViewProjection sets the camera view and projection matrixes, and updates uniform data, so they are ready to use.
func (*Phong) Sync ¶
func (ph *Phong) Sync()
Sync synchronizes any changes in val data up to GPU device memory. any changes in numbers or sizes of any element requires a Config call.
func (*Phong) UpdateTextureIndex ¶ added in v0.0.10
UpdateTextureIndex updates texture by index -- call this when the underlying image changes. Assumes the size remains the same. Must Sync for the changes to take effect.
func (*Phong) UpdateTextureName ¶
UpdateTextureName updates texture by name
func (*Phong) UseColorIndex ¶ added in v0.0.10
UseColorIndex selects color by index for current render step
func (*Phong) UseColorName ¶
UseColorName selects color by name for current render step
func (*Phong) UseFullTexture ¶
func (ph *Phong) UseFullTexture()
UseFullTexture sets the texture parameters for the next render command: to render the full texture: repeat = 1,1; off = 0,0
func (*Phong) UseMeshIndex ¶ added in v0.0.10
UseMeshIndex selects mesh by index for current render step. If mesh has per-vertex colors, these are selected for rendering, and texture is turned off. UseTexture* after this to override.
func (*Phong) UseMeshName ¶
UseMeshName selects mesh by name for current render step 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) UseTextureIndex ¶ added in v0.0.10
UseTextureIndex selects texture by index for current render step
func (*Phong) UseTextureName ¶
UseTextureName selects texture by name for current render step
type PointLight ¶
type PointLight struct { // color of light a full intensity Color math32.Vector3 // position of light in world coordinates Pos math32.Vector3 // X = Linear, Y = Quad: Distance linear decay factor -- defaults to .1; Distance quadratic decay factor -- defaults to .01 -- dominates at longer distances Decay math32.Vector3 // contains filtered or unexported fields }
PointLight 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 PushU ¶
type PushU struct { // Model Matrix: poses object in world coordinates ModelMtx math32.Matrix4 // surface colors Color Colors // texture parameters Tex TexPars }
PushU is the push constants structure, holding everything that updates per object -- avoids any limitations on capacity.
type Sets ¶
type Sets int32 //enums:enum
Sets are variable set numbers - must coordinate with System sets!
const SetsN Sets = 4
SetsN is the highest valid value for type Sets, plus one.
func SetsValues ¶
func SetsValues() []Sets
SetsValues returns all possible values for the type Sets.
func (Sets) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Sets) SetString ¶
SetString sets the Sets value from its string representation, and returns an error if the string is invalid.
func (*Sets) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type SpotLight ¶
type SpotLight 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, Y = CutAngle, Z = LinDecay, W = QuadDecay: Angular decay factor -- defaults to 15; Cut off angle (in degrees) -- defaults to 45 -- max of 90; Distance linear decay factor -- defaults to 1; Distance quadratic decay factor -- defaults to 1 -- 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.