Making an advanced lighting system

23

Index

Contributors

Stats

10,080 visits, 24,092 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

What we need

On one hand, we need a set of objects inside a container for the light, and we need to setup a family for the shadows.

Light🔦

Objects

We need four objects inside a container

LightSource Sprite
The sprite that is going to be used as the base for the light, and will contain every instance variable
ShadowLight
Used to cast shadows from scenery objects
Shadow DrawingCanvas
This is the canvas that will be used to render the light and the shadows
LightCircle Sprite
The sprite that contains the animation for the light circle.

This is the sprite I used for the light circle:

Note that you can add multiple frames to the animation, or even multiple animations, and you can add a Sine behavior to add some wavy movement.

Instance variables

Here is the list of every instance variable I used for the light source.

radius
The light radius in pixels
colorR
Color red property from 0 to 255
colorG
Color green property from 0 to 255
colorB
Color blue property from 0 to 255
minSizeMult and maxSizeMult
The shadow's height varies depending on the distance from the center, these values control the minimum and maximum size multipliers for the shadow
Sharpness
The light's sharpness, 0 produces very blurry shadows, 100 produces sharp shadows
BlurMinAngle and BlurMaxAngle
The shadow blur's angle depends on the distance from the center, these values control the minimum and maximum angle of the blur
strength
The light's opacity from 0 to 100
Shivering
Whether to activate the light circle's sine behavior, and add a little bit of shivering
ShiverPeriod
The sine behavior's period
ShiverMagnitude
The sine behavior's magnitude

Shadow Caster Family

The family needs a ShadowCaster behavior and a few instance variables. Whether the shadow caster behavior is enabled will define whether the family will cast a ShadowLight shadow or a normal shadow.

Here are the needed instance vars

isShadow
Wether the current instance is a shadow instance or not.
masterUID
The parent Shadow Caster object of that shadow.
destroy
Destroying objects in C3 happens at the end of the frame, this variable is used to tag shadows that need to be destroyed so they don't get picked during that frame.
initOpacity
Used to store opacity before rendering the blur effect and restoring it after.
  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • This great! Thanks!

  • trying to follow your tuto, great so far but I'm confuse on the page 5:

    OBJECT POOLING and PLACE THE SHADOW screencap don'tseem to show the same nested script.

    On the first one you see the event showcaster>>> pick instance with UID=uid with direct action linked to it and other events following (not sub event) and in the 2nd screenshot you see that the condition showcaster>>> pick instance with UID=uid has some other sub event.. which one is correct?