Documentation
¶
Index ¶
- Constants
- Variables
- func CameraViewMat(pos, target, up mat32.Vec3) *mat32.Mat4
- type AmbientLight
- type Colors
- type CurRender
- type DirLight
- type Mesh
- type Mtxs
- type NLights
- type Phong
- func (ph *Phong) AddAmbientLight(color mat32.Vec3)
- func (ph *Phong) AddColor(name string, clr *Colors)
- func (ph *Phong) AddDirLight(color, pos mat32.Vec3)
- func (ph *Phong) AddMesh(name string, nVtx, nIdx int, hasColor bool)
- func (ph *Phong) AddPointLight(color, pos mat32.Vec3, linDecay, quadDecay float32)
- func (ph *Phong) AddSpotLight(color, pos, dir mat32.Vec3, angDecay, cutAngle, linDecay, quadDecay float32)
- func (ph *Phong) AddTexture(name string, tex *Texture)
- func (ph *Phong) Alloc()
- func (ph *Phong) AllocMeshes()
- func (ph *Phong) AllocTextures()
- func (ph *Phong) Config()
- func (ph *Phong) ConfigLights()
- func (ph *Phong) ConfigMeshes()
- func (ph *Phong) ConfigPipeline(pl *vgpu.Pipeline)
- func (ph *Phong) ConfigSys()
- func (ph *Phong) ConfigTextures()
- func (ph *Phong) Destroy()
- func (ph *Phong) MeshFloatsByIdx(i int) (pos, norm, tex, clr mat32.ArrayF32, idx mat32.ArrayU32)
- func (ph *Phong) MeshFloatsByName(name string) (pos, norm, tex, clr mat32.ArrayF32, idx mat32.ArrayU32)
- func (ph *Phong) ModMeshByIdx(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) SetModelMtx(model *mat32.Mat4)
- func (ph *Phong) SetViewPrjn(view, prjn *mat32.Mat4)
- func (ph *Phong) Sync()
- func (ph *Phong) UseColorIdx(idx int) error
- func (ph *Phong) UseColorName(name string) error
- func (ph *Phong) UseMeshIdx(idx int) error
- func (ph *Phong) UseMeshName(name string) error
- func (ph *Phong) UseNoTexture()
- func (ph *Phong) UseTextureIdx(idx int) error
- func (ph *Phong) UseTextureName(name string) error
- 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 ¶
var KiT_Sets = kit.Enums.AddEnum(SetsN, kit.NotBitFlag, nil)
Functions ¶
Types ¶
type AmbientLight ¶
type AmbientLight struct {
Color mat32.Vec3 `desc:"color of light -- multiplies ambient color of materials"`
// contains filtered or unexported fields
}
AmbientLight provides diffuse uniform lighting -- typically only one of these
type Colors ¶
type Colors struct {
Color mat32.Vec4 `` /* 200-byte string literal not displayed */
ShinyBright mat32.Vec4 `` /* 649-byte string literal not displayed */
Emissive mat32.Vec3 `desc:"color that surface emits independent of any lighting -- i.e., glow -- can be used for marking lights with an object"`
// contains filtered or unexported fields
}
Colors are the material colors with padding for direct uploading to shader
type CurRender ¶
type CurRender struct {
DescIdx int `desc:"index of descriptor collection to use -- for threaded / parallel rendering -- see vgup.Vars NDescs for more info"`
UseTexture bool `desc:"a texture was selected -- if true, overrides other options"`
UseVtxColor bool `desc:"a per-vertex color was selected"`
ModelMtx mat32.Mat4 `desc:"current model pose matrix"`
VPMtx Mtxs `desc:"camera view and projection matrixes"`
Color Colors `desc:"current color surface properties"`
TexIdx int `desc:"index of currently-selected texture"`
}
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 mat32.Vec3 `desc:"color of light at full intensity"`
Pos mat32.Vec3 `` /* 148-byte string literal not displayed */
// 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 {
NVtx int `desc:"number of vertex points, as mat32.Vec3 -- always includes mat32.Vec3 normals and mat32.Vec2 texture coordinates"`
NIdx int `desc:"number of indexes, as mat32.ArrayU32"`
HasColor bool `desc:"has per-vertex colors, as mat32.Vec4 per vertex"`
}
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 mat32.Mat4 `desc:"View Matrix: transforms world into camera-centered, 3D coordinates"`
Prjn mat32.Mat4 `desc:"Projection Matrix: transforms camera coords into 2D render coordinates"`
}
Mtxs contains the camera view and projection matricies, for uniform uploading
type Phong ¶
type Phong struct {
NLights NLights `desc:"number of each type of light"`
Ambient [MaxLights]AmbientLight `desc:"ambient lights"`
Dir [MaxLights]DirLight `desc:"directional lights"`
Point [MaxLights]PointLight `desc:"point lights"`
Spot [MaxLights]SpotLight `desc:"spot lights"`
Cur CurRender `desc:"state for current rendering"`
Meshes ordmap.Map[string, *Mesh] `desc:"meshes -- holds all the mesh data -- must be configured prior to rendering"`
Textures ordmap.Map[string, *Texture] `` /* 133-byte string literal not displayed */
Colors ordmap.Map[string, *Colors] `desc:"colors, optionally available for looking up by name -- not used directly in rendering"`
Sys vgpu.System `desc:"rendering system"`
}
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 verticies, 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 mat32.Vec3, 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) Alloc ¶
func (ph *Phong) Alloc()
Alloc allocate all vals based on currently-added Mesh, Color, Texture
func (*Phong) AllocTextures ¶
func (ph *Phong) AllocTextures()
AllocTextures allocates vals for textures
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 the rendering for the meshes
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 the rendering for the textures that have been added.
func (*Phong) MeshFloatsByIdx ¶
MeshFloatsByIdx returns the mat32.ArrayF32's and mat32.ArrayU32 for given mesh for assigning values to the mesh. Must call ModMeshByIdx after setting these values to mark as modified.
func (*Phong) MeshFloatsByName ¶
func (ph *Phong) MeshFloatsByName(name string) (pos, norm, tex, clr mat32.ArrayF32, idx mat32.ArrayU32)
MeshFloatsByName returns the mat32.ArrayF32's and mat32.ArrayU32 for given mesh for assigning values to the mesh. Must call ModMeshByName after setting these values to mark as modified.
func (*Phong) ModMeshByIdx ¶
ModMeshByIdx 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) SetModelMtx ¶
SetModelMtx sets the model pose matrix -- must be set per render step (otherwise last one will be used)
func (*Phong) SetViewPrjn ¶
SetViewPrjn 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) UseColorIdx ¶
UseColorIdx selects color by index for current render step
func (*Phong) UseColorName ¶
UseColorName selects color by name for current render step
func (*Phong) UseMeshIdx ¶
UseMeshIdx 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) UseTextureIdx ¶
UseTextureIdx 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 mat32.Vec3 `desc:"color of light a full intensity"`
Pos mat32.Vec3 `desc:"position of light in world coordinates"`
Decay mat32.Vec3 `` /* 160-byte string literal not displayed */
// 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 {
ModelMtx mat32.Mat4 `desc:"Model Matrix: poses object in world coordinates"`
Color Colors `desc:"surface colors"`
Tex TexPars `desc:"texture parameters"`
}
PushU is the push constants structure, holding everything that updates per object -- avoids any limitations on capacity.
type Sets ¶
type Sets int
Sets are variable set numbers - must coordinate with System sets!
func (*Sets) FromString ¶
type SpotLight ¶
type SpotLight struct {
Color mat32.Vec3 `desc:"color of light a full intensity"`
Pos mat32.Vec3 `desc:"position of light in world coordinates"`
Dir mat32.Vec3 `desc:"direction of light vector"`
Decay mat32.Vec4 `` /* 296-byte string literal not displayed */
// 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 TexPars ¶
type TexPars struct {
Repeat mat32.Vec2 `desc:"how often to repeat the texture in each direction"`
Off mat32.Vec2 `desc:"offset for when to start the texure in each direction"`
}
TexPars holds texture parameters for push constants -- idx is coded in shiny bright