Class Gorgon2DLightingEffect
An effect used to render a scene with per-pixel lighting.
Inherited Members
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public class Gorgon2DLightingEffect : Gorgon2DEffect, IGorgonNamedObject, IDisposable, IGorgonGraphicsObject
Remarks
This effect simulates lighting on 2D rendering by using a normal map (and specular map) to determine how to render a pixels shading. It does this by using a G-Buffer which contains a render target for the diffuse (unlit color), specular, and normal map data.
The effect renders the lighting data in 2 passes. The first renders the diffuse layer using a callback defined by the user to render their objects that they wish to have lit. Then, the 2nd pass combines all the layers of the G-buffer together using additive blending for each light defined and returns the combined lighting data to a render target specified by the user. This output can then be combined with the scene using additive blending to produce the desired lighting effect.
information
Please note that this last compositing pass is not done by the effect and must be handled by the user. This is done in the interest of flexibility to allow the user to decide how to best handle the compositing of their scene.
In order for a sprite, or other 2D graphics object to be rendered using lighting, the backing texture must use a texture with an array count of 3 or higher. Each index of the array corresponds to a layer used by the G-buffer to composite the lighting together. These array indices must be in the following order (while the word sprite is used, this can apply to anything that is textured):
- The diffuse layer for the sprite - This is just the unlit colors for your sprite, basically the standard texture you'd normally use. Ideally, this texture should not contain any shading at all as this will be handled by the effect.
- The specular layer for the sprite - This is the texture array index that controls which parts of the sprite are "shiny". Leaving this black will produce no specular hilighting at all, while pure white will make all parts of it shiny. This amount of specular is controlled by the SpecularPower property on a light.
- The normal map layer for the sprite - This is the texture array index that provides normals for the lighting calculations. This layer must have data in it or else no lighting will be applied. Gorgon does not generate normal map for your texture, however there are a multitude of tools available online to help with this (e.g. CrazyBump, SpriteIlluminator, etc...).
- The position buffer for the sprite - This is the texture array index that world position data for the lighting calculations. This layer may be omitted by passing -1 to a position index parameter. The Gorgon2DGBuffer will use always positional data and will generate world position data based on whatever you render.
The user must also supply at least a single light source to effectively view the lighting on the 2D object.
Constructors
| Edit this page View SourceGorgon2DLightingEffect(Gorgon2D)
Initializes a new instance of the Gorgon2DLightingEffect class.
Declaration
public Gorgon2DLightingEffect(Gorgon2D renderer)
Parameters
Type | Name | Description |
---|---|---|
Gorgon2D | renderer | The renderer used to draw with the effect. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
See Also
Properties
| Edit this page View SourceAmbientColor
Property to set or return the global ambient color.
Declaration
public GorgonColor AmbientColor { get; set; }
Property Value
Type | Description |
---|---|
GorgonColor |
See Also
| Edit this page View SourceCheckLightDepth
Property to set or return whether to check if the light is behind an object or not.
Declaration
public bool CheckLightDepth { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceLights
Property to return the list of point lights for rendering.
Declaration
public IList<GorgonLightCommon> Lights { get; }
Property Value
Type | Description |
---|---|
IList<GorgonLightCommon> |
See Also
| Edit this page View SourcePassCount
Property to return the number of passes required to render the effect.
Declaration
public override int PassCount { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
Remarks
This is merely for information, passes may or may not be exposed to the end user by the effect author.
See Also
Methods
| Edit this page View SourceDispose(bool)
Releases unmanaged and - optionally - managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
|
Overrides
See Also
| Edit this page View SourceOnBeforeRender(GorgonRenderTargetView, bool)
Function called prior to rendering.
Declaration
protected override void OnBeforeRender(GorgonRenderTargetView output, bool sizeChanged)
Parameters
Type | Name | Description |
---|---|---|
GorgonRenderTargetView | output | The final render target that will receive the rendering from the effect. |
bool | sizeChanged | true if the output size changed since the last render, or false if it's the same. |
Overrides
Remarks
Applications can use this to set up common states and other configuration settings prior to executing the render passes. This is an ideal method to initialize and resize your internal render targets (if applicable).
See Also
| Edit this page View SourceOnBeforeRenderPass(int, GorgonRenderTargetView, GorgonCameraCommon)
Function called prior to rendering a pass.
Declaration
protected override PassContinuationState OnBeforeRenderPass(int passIndex, GorgonRenderTargetView output, GorgonCameraCommon camera)
Parameters
Type | Name | Description |
---|---|---|
int | passIndex | The index of the pass to render. |
GorgonRenderTargetView | output | The final render target that will receive the rendering from the effect. |
GorgonCameraCommon | camera | The currently active camera. |
Returns
Type | Description |
---|---|
PassContinuationState | A PassContinuationState to instruct the effect on how to proceed. |
Overrides
Remarks
Applications can use this to set up per-pass states and other configuration settings prior to executing a single render pass.
See Also
| Edit this page View SourceOnGetBatchState(int, IGorgon2DEffectBuilders, bool)
Function called to build a new (or return an existing) 2D batch state.
Declaration
protected override Gorgon2DBatchState OnGetBatchState(int passIndex, IGorgon2DEffectBuilders builders, bool statesChanged)
Parameters
Type | Name | Description |
---|---|---|
int | passIndex | The index of the current rendering pass. |
IGorgon2DEffectBuilders | builders | The builder types that will manage the state of the effect. |
bool | statesChanged | true if the blend, raster, or depth/stencil state was changed. false if not. |
Returns
Type | Description |
---|---|
Gorgon2DBatchState | The 2D batch state. |
Overrides
See Also
| Edit this page View SourceOnInitialize()
Function called to initialize the effect.
Declaration
protected override void OnInitialize()
Overrides
Remarks
Applications must implement this method to ensure that any required resources are created, and configured for the effect.
See Also
| Edit this page View SourceRender(IGorgonGBuffer, GorgonRenderTargetView, GorgonCameraCommon)
Function to render the effect using the array indices of the diffuse texture.
Declaration
public void Render(IGorgonGBuffer gbuffer, GorgonRenderTargetView output, GorgonCameraCommon camera = null)
Parameters
Type | Name | Description |
---|---|---|
IGorgonGBuffer | gbuffer | A Gbuffer containing the diffuse, normal and specular maps. |
GorgonRenderTargetView | output | The final output target for the effect. |
GorgonCameraCommon | camera | [Optional] The camera used to transform the lights to camera space. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |