Gorgon
Show / Hide Table of Contents

Class Gorgon2DLightingEffect

An effect used to render a scene with per-pixel lighting.

Inheritance
object
GorgonNamedObject
Gorgon2DEffect
Gorgon2DLightingEffect
Implements
IGorgonNamedObject
IDisposable
IGorgonGraphicsObject
Inherited Members
Gorgon2DEffect.BatchStateAllocator
Gorgon2DEffect.PixelShaderAllocator
Gorgon2DEffect.VertexShaderAllocator
Gorgon2DEffect.Macros
Gorgon2DEffect.Renderer
Gorgon2DEffect.Graphics
Gorgon2DEffect.Description
Gorgon2DEffect.CompileShader<T>(string, string)
Gorgon2DEffect.OnAfterRender(GorgonRenderTargetView)
Gorgon2DEffect.OnAfterRenderPass(int, GorgonRenderTargetView)
Gorgon2DEffect.BeginRender(GorgonRenderTargetView, GorgonBlendState, GorgonDepthStencilState, GorgonRasterState)
Gorgon2DEffect.BeginPass(int, GorgonRenderTargetView, GorgonCameraCommon)
Gorgon2DEffect.EndPass(int, GorgonRenderTargetView)
Gorgon2DEffect.EndRender(GorgonRenderTargetView)
Gorgon2DEffect.Precache()
Gorgon2DEffect.Dispose()
GorgonNamedObject.GetHashCode()
GorgonNamedObject.ToString()
GorgonNamedObject.Name
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()
object.MemberwiseClone()
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):

  1. 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.
  2. 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.
  3. 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...).
  4. 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 Source

Gorgon2DLightingEffect(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 renderer parameter is null.

See Also
Gorgon2DGBuffer

Properties

| Edit this page View Source

AmbientColor

Property to set or return the global ambient color.

Declaration
public GorgonColor AmbientColor { get; set; }
Property Value
Type Description
GorgonColor
See Also
Gorgon2DGBuffer
| Edit this page View Source

CheckLightDepth

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
Gorgon2DGBuffer
| Edit this page View Source

Lights

Property to return the list of point lights for rendering.

Declaration
public IList<GorgonLightCommon> Lights { get; }
Property Value
Type Description
IList<GorgonLightCommon>
See Also
Gorgon2DGBuffer
| Edit this page View Source

PassCount

Property to return the number of passes required to render the effect.

Declaration
public override int PassCount { get; }
Property Value
Type Description
int
Overrides
Gorgon2DEffect.PassCount
Remarks

This is merely for information, passes may or may not be exposed to the end user by the effect author.

See Also
Gorgon2DGBuffer

Methods

| Edit this page View Source

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Overrides
Gorgon2DEffect.Dispose(bool)
See Also
Gorgon2DGBuffer
| Edit this page View Source

OnBeforeRender(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
Gorgon2DEffect.OnBeforeRender(GorgonRenderTargetView, bool)
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
Gorgon2DGBuffer
| Edit this page View Source

OnBeforeRenderPass(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
Gorgon2DEffect.OnBeforeRenderPass(int, GorgonRenderTargetView, GorgonCameraCommon)
Remarks

Applications can use this to set up per-pass states and other configuration settings prior to executing a single render pass.

See Also
PassContinuationState
| Edit this page View Source

OnGetBatchState(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
Gorgon2DEffect.OnGetBatchState(int, IGorgon2DEffectBuilders, bool)
See Also
Gorgon2DGBuffer
| Edit this page View Source

OnInitialize()

Function called to initialize the effect.

Declaration
protected override void OnInitialize()
Overrides
Gorgon2DEffect.OnInitialize()
Remarks

Applications must implement this method to ensure that any required resources are created, and configured for the effect.

See Also
Gorgon2DGBuffer
| Edit this page View Source

Render(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 gbuffer, or the output parameter is null.

See Also
Gorgon2DGBuffer

Implements

IGorgonNamedObject
IDisposable
IGorgonGraphicsObject

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

Gorgon2DGBuffer
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author