Procedural lightning effect Unity

DRAFT

This is a basic tutorial on how to create procedural lightning effect in Unity, this is my first attempt at using Unity so if you think there are bugs,issues or better ways of doing things let me know.

I am using a two step process

1) Generator
2) Renderer

I like to have them separated for couple different reasons but mainly to allow me to render them differently and create different lighting like effects.

Generator is responsible for generating segments and renderer is responsible for rendering segments to the screen.

My original version used a LineRenderer but I decided to go with a Mesh/MeshFilter for rendering as that gives me more control.  Each segment creates a new quad that is added to our mesh.

After 1 generation

light-mesh-001

Results after first pass.

light-001    light-002    light-003

Current status 

light-mesh-002    light-mesh-003    light-mesh-004

Implementation 

Segment class

public class Segment 
{
    public Vector2 start;

    public Vector2 end;

    public int generation;
    
    public Segment(Vector2 start, Vector2 end) : this(start, end, 0)
    {
               
    }

    public Segment(Vector3 start, Vector2 end, int generation)
    {
        this.start = start;
        this.end = end;
        this.generation = generation;
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *