Documentation ¶
Overview ¶
Package forward is a package that defines an OpenGL forward renderer.
At present both lights and shadows are present only in their basic form.
For more information, look at the `examples` folder and a set of shaders can be found in `examples/assets/forwardshaders`.
Index ¶
- Constants
- func CreateBasicShader() (*fizzle.RenderShader, error)
- func CreateBasicSkinnedShader() (*fizzle.RenderShader, error)
- func CreateColorShader() (*fizzle.RenderShader, error)
- func CreateColorTextShader() (*fizzle.RenderShader, error)
- func CreateDiffuseUnlitShader() (*fizzle.RenderShader, error)
- func CreateShadowmapGeneratorShader() (*fizzle.RenderShader, error)
- type ForwardRenderer
- func (fr *ForwardRenderer) ChangeResolution(width, height int32)
- func (fr *ForwardRenderer) Destroy()
- func (fr *ForwardRenderer) DrawLines(r *fizzle.Renderable, shader *fizzle.RenderShader, ...)
- func (fr *ForwardRenderer) DrawRenderable(r *fizzle.Renderable, binder renderer.RenderBinder, perspective mgl.Mat4, ...)
- func (fr *ForwardRenderer) DrawRenderableWithShader(r *fizzle.Renderable, shader *fizzle.RenderShader, ...)
- func (fr *ForwardRenderer) EnableShadowMappingLight(l *Light)
- func (fr *ForwardRenderer) EndRenderFrame()
- func (fr *ForwardRenderer) EndShadowMapping()
- func (fr *ForwardRenderer) GetActiveLightCount() int
- func (fr *ForwardRenderer) GetActiveShadowLightCount() int
- func (fr *ForwardRenderer) GetAspectRatio() float32
- func (fr *ForwardRenderer) GetGraphics() graphics.GraphicsProvider
- func (fr *ForwardRenderer) GetResolution() (int32, int32)
- func (fr *ForwardRenderer) Init(width, height int32) error
- func (fr *ForwardRenderer) NewDirectionalLight(dir mgl.Vec3) *Light
- func (fr *ForwardRenderer) NewLight() *Light
- func (fr *ForwardRenderer) NewPointLight(location mgl.Vec3) *Light
- func (fr *ForwardRenderer) NewShadowMap() *ShadowMap
- func (fr *ForwardRenderer) SetGraphics(gp graphics.GraphicsProvider)
- func (fr *ForwardRenderer) SetupShadowMapRendering()
- func (fr *ForwardRenderer) StartShadowMapping()
- type Light
- type ShadowMap
Constants ¶
const (
// MaxForwardLights is the maximum amount of lights supported by this renderer.
MaxForwardLights = 4
)
Variables ¶
This section is empty.
Functions ¶
func CreateBasicShader ¶ added in v0.3.0
func CreateBasicShader() (*fizzle.RenderShader, error)
CreateBasicShader creates a new shader object using the built in basic shader code.
func CreateBasicSkinnedShader ¶ added in v0.3.0
func CreateBasicSkinnedShader() (*fizzle.RenderShader, error)
CreateBasicSkinnedShader creates a new shader object using the built in basic shader code with GPU skinning for bones.
func CreateColorShader ¶ added in v0.3.0
func CreateColorShader() (*fizzle.RenderShader, error)
CreateColorShader creates a new shader object using the built in flat color shader code that uses Material.DiffuseColor.
func CreateColorTextShader ¶ added in v0.3.0
func CreateColorTextShader() (*fizzle.RenderShader, error)
CreateColorTextShader creates a new shader object using the built in flat color shader code that uses Material.DiffuseColor and is meant to be used to draw characters in a texture font.
func CreateDiffuseUnlitShader ¶ added in v0.3.0
func CreateDiffuseUnlitShader() (*fizzle.RenderShader, error)
CreateDiffuseUnlitShader creates a new shader object using the built in diffuse texture shader that is unlit (no lighting calculated).
func CreateShadowmapGeneratorShader ¶ added in v0.3.0
func CreateShadowmapGeneratorShader() (*fizzle.RenderShader, error)
CreateShadowmapGeneratorShader creates a new shader object using the built in shadowmap generator shader. This can be used to render objects for a shadow map texture to do dynamic shadows in a scene.
Types ¶
type ForwardRenderer ¶
type ForwardRenderer struct { // OnScreenSizeChanged is the function called by the renderer after // a screen size change is detected. OnScreenSizeChanged func(fr *ForwardRenderer, width int32, height int32) // ActiveLights are the current lights that should be used while // drawing Renderables. ActiveLights [MaxForwardLights]*Light // contains filtered or unexported fields }
ForwardRenderer is a forward-rendering style renderer, meaning that when it draws the geometry it lights it at the same time and the output goes to the output framebuffer, which is the only framebuffer.
func NewForwardRenderer ¶
func NewForwardRenderer(g graphics.GraphicsProvider) *ForwardRenderer
NewForwardRenderer creates a new forward rendering style render engine object.
func (*ForwardRenderer) ChangeResolution ¶
func (fr *ForwardRenderer) ChangeResolution(width, height int32)
ChangeResolution should be called when the underlying rendering window changes size.
func (*ForwardRenderer) Destroy ¶
func (fr *ForwardRenderer) Destroy()
Destroy releases any data the renderer was holding that it 'owns'.
func (*ForwardRenderer) DrawLines ¶
func (fr *ForwardRenderer) DrawLines(r *fizzle.Renderable, shader *fizzle.RenderShader, binder renderer.RenderBinder, perspective mgl.Mat4, view mgl.Mat4, camera fizzle.Camera)
DrawLines draws the Renderable using graphics.LINES mode instead of graphics.TRIANGLES.
func (*ForwardRenderer) DrawRenderable ¶
func (fr *ForwardRenderer) DrawRenderable(r *fizzle.Renderable, binder renderer.RenderBinder, perspective mgl.Mat4, view mgl.Mat4, camera fizzle.Camera)
DrawRenderable draws a Renderable object with the supplied projection and view matrixes.
func (*ForwardRenderer) DrawRenderableWithShader ¶
func (fr *ForwardRenderer) DrawRenderableWithShader(r *fizzle.Renderable, shader *fizzle.RenderShader, binder renderer.RenderBinder, perspective mgl.Mat4, view mgl.Mat4, camera fizzle.Camera)
DrawRenderableWithShader draws a Renderable object with the supplied projection and view matrixes and a different shader than what is set in the Renderable.
func (*ForwardRenderer) EnableShadowMappingLight ¶
func (fr *ForwardRenderer) EnableShadowMappingLight(l *Light)
EnableShadowMappingLight enables the light to start casting shadows with draw functions and the appropriate shaders. NOTE: A good client would call StartShadowMapping() and EndShadowMapping() before and after doing shadow draws.
func (*ForwardRenderer) EndRenderFrame ¶
func (fr *ForwardRenderer) EndRenderFrame()
EndRenderFrame is the function called at end of the frame.
func (*ForwardRenderer) EndShadowMapping ¶
func (fr *ForwardRenderer) EndShadowMapping()
EndShadowMapping unbinds the shadow map framebuffer and lets the renderer proceed as normal.
func (*ForwardRenderer) GetActiveLightCount ¶
func (fr *ForwardRenderer) GetActiveLightCount() int
GetActiveLightCount counts the number of *Light set in the ForwardRenderer's ActiveLights array until a nil is hit. NOTE: Obviously requires ActiveLights to be packed sequentially.
func (*ForwardRenderer) GetActiveShadowLightCount ¶
func (fr *ForwardRenderer) GetActiveShadowLightCount() int
GetActiveShadowLightCount counts the number of *Light set in the ForwardRenderer's ActiveLights array that support ShadowMaps until a nil is hit or a light doesn't support shadows. NOTE: Obviously requires ActiveLights to be packed sequentially with lights that support shadow maps in front. Life's not perfect.
func (*ForwardRenderer) GetAspectRatio ¶
func (fr *ForwardRenderer) GetAspectRatio() float32
GetAspectRatio returns the ratio of screen width to height.
func (*ForwardRenderer) GetGraphics ¶
func (fr *ForwardRenderer) GetGraphics() graphics.GraphicsProvider
GetGraphics returns the renderer's the graphics provider.
func (*ForwardRenderer) GetResolution ¶
func (fr *ForwardRenderer) GetResolution() (int32, int32)
GetResolution returns the current dimensions of the renderer.
func (*ForwardRenderer) Init ¶
func (fr *ForwardRenderer) Init(width, height int32) error
Init initializes the renderer.
func (*ForwardRenderer) NewDirectionalLight ¶
func (fr *ForwardRenderer) NewDirectionalLight(dir mgl.Vec3) *Light
NewDirectionalLight creates a new light and sets it up to be a directional light.
func (*ForwardRenderer) NewLight ¶
func (fr *ForwardRenderer) NewLight() *Light
NewLight creates a new light object and returns it without setting any default attributes.
func (*ForwardRenderer) NewPointLight ¶
func (fr *ForwardRenderer) NewPointLight(location mgl.Vec3) *Light
NewPointLight creates a new light and sets it up to be a point light.
func (*ForwardRenderer) NewShadowMap ¶
func (fr *ForwardRenderer) NewShadowMap() *ShadowMap
NewShadowMap creates a new shadow map object
func (*ForwardRenderer) SetGraphics ¶
func (fr *ForwardRenderer) SetGraphics(gp graphics.GraphicsProvider)
SetGraphics initializes then renderer with the graphics provider.
func (*ForwardRenderer) SetupShadowMapRendering ¶
func (fr *ForwardRenderer) SetupShadowMapRendering()
SetupShadowMapRendering is called to create the framebuffer to render the shadows and must be called before rendering shadow maps.
func (*ForwardRenderer) StartShadowMapping ¶
func (fr *ForwardRenderer) StartShadowMapping()
StartShadowMapping binds the shadow map framebuffer for use by the lights to render shadows.
type Light ¶
type Light struct { // Position is the location of the light in world space Position mgl.Vec3 // Direction is the direction the light points in Direction mgl.Vec3 // DiffuseColor is the color the light emmits DiffuseColor mgl.Vec4 // DiffuseIntensity is how strong the diffuse light should be DiffuseIntensity float32 // SpecularIntensity is how strong the specular highlight should be SpecularIntensity float32 // AmbientIntensity is how strong the ambient light should be AmbientIntensity float32 // ConstAttenuation is the constant coefficient for the attenuation factor ConstAttenuation float32 // LinearAttenuation is the linear coefficient for the attenuation factor LinearAttenuation float32 // QuadraticAttenuation is the quadratic coefficient for the attenuation factor QuadraticAttenuation float32 // Strength is the scale factor on the light strength. Strength float32 // ShadowMap is the texture, and other data, used to render // shadows casted by the light. This member is nil when // the light does not cast shadows. ShadowMap *ShadowMap // contains filtered or unexported fields }
Light is a basic light structure used in the forward renderer.
func (*Light) CreateShadowMap ¶
CreateShadowMap allocates a texture and sets up the projections to draw the shadows.
func (*Light) UpdateShadowMapData ¶
func (l *Light) UpdateShadowMapData()
UpdateShadowMapData updates a shadow maps internal structures based on data from the light.
type ShadowMap ¶
type ShadowMap struct { // Texture is the texture for the shadowmap Texture graphics.Texture // TextureSize is the size of the texture in memory. TextureSize int32 // Direction controls the direction the shadowmap points in. Direction mgl.Vec3 // Near is the near distance for the shadowmap projection Near float32 // Far is the far distance for the shadowmap projection Far float32 // Up defines the Up vector for the projection when casting shadows. Defaults to {0,1,0} Up mgl.Vec3 // Projection is the projection transformation matrix for the shadowmap Projection mgl.Mat4 // View is the view transformation matrix for the shadowmap // Updated with UpdateShadowMapData(). View mgl.Mat4 // ViewProjMatrix is the combination view-projection matrix. // Updated with UpdateShadowMapData(). ViewProjMatrix mgl.Mat4 // ShadowBiasedMatrix is the shadow biased matrix to account for the difference between NDC and texture space. // Updated with UpdateShadowMapData(). BiasedMatrix mgl.Mat4 // contains filtered or unexported fields }
ShadowMap contains the id of the shadow map texture as well as the associated vectors and matrixes needed to render the shadow map for the owning light. NOTE: only point lights via a given direction are supported at present.