• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    C++
  • License
    Other
  • Created almost 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A 2D dynamic lighting system with accurate soft shadows.

Let There Be Light 2

A 2D dynamic soft shadows system with accurate penumbras/antumbras.

Install

LTBL2 relies only on SFML.

To get SFML, choose a package from here: http://www.sfml-dev.org/download/sfml/2.2/

LTBL2 uses CMake as the build system. You can get CMake here: http://www.cmake.org/download/

Quick Start

The first step is to include LTBL2's light system:

#include <ltbl/lighting/LightSystem.h>

To use LTBL2, you must first load the resources LTBL2 requires. The resources are located in the resources directory.

You will need to load 2 SFML shader objects:

sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;
unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");

You will also need to load a texture:

sf::Texture penumbraTexture;
penumbraTexture.loadFromFile("resources/penumbraTexture.png");
penumbraTexture.setSmooth(true);

It is important that you set the texture filtering to smooth, otherwise it will look pixelated.

Now you can create the LightSystem object:

ltbl::LightSystem ls;
ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), window->getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

Where the first parameter is a starting region for the quadtree (doesn't need to be exact, it will automatically adjust itself!). The second parameter is the size of the rendering region. This is typically the size of the window you ultimately want to apply the lighting to. The other parameters are the resources we loaded earlier.

LTBL2 has 2 basic light types: Point emission and direction emission. Point emission can be used for point lights and spot lights. Direction emission is mostly for sunlight.

To create a light, you will need to create a light mask texture. Two defaults, one for point and one for direction, are provided in the resources directory. The light mask texture defines the shape of the light source.

LTBL2 lights use SFML sprites to render. So you will set the light's sprite to use your mask texture, and then properly set the sprite's origin, size, position, and rotation as is usual with SFML.

Below is an example for creating one point light and one directional light:

std::shared_ptr<ltbl::LightPointEmission> light = std::make_shared<ltbl::LightPointEmission>();

light->emissionSprite.setOrigin(<some_origin>);
light->emissionSprite.setTexture(<mask_texture>);
light->emissionSprite.setColor(<color>);
light->emissionSprite.setPosition(<position_of_light>);
light->localCastCenter = sf::Vector2f(0.0f, 0.0f); // This is where the shadows emanate from relative to the sprite

ls.addLight(light);

...

std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

light->emissionSprite.setTexture(<mask_texture>);
light->castDirection = sf::Vector2f(<cast_direction>);

ls.addLight(light);

To create occluders, you must create a ltbl::LightShape object, and set the SFML shape it contains to represent the occluder:

std::shared_ptr<ltbl::LightShape> lightShape = std::make_shared<ltbl::LightShape>();

lightShape->shape.setPointCount(<number_of_points>);

for (int j = 0; j < fixedPoints.size(); j++)
	lightShape->shape.setPoint(j, <point>);

lightShape->shape.setPosition(<position>);

ls.addShape(lightShape);

More instructions to come. You are of course welcome to post on the SFML forum thread for help: http://en.sfml-dev.org/forums/index.php?topic=16895.0

License

LTBL2 Copyright (C) 2014-2020 Eric Laukien

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

LTBL2 uses the following external libraries:

SFML - source code is licensed under the zlib/png license.

More Repositories

1

PGE

PGE: Parallel Game Engine
C++
98
star
2

AILib

A large collection of mostly reinforcement learning agents.
C++
84
star
3

NeoRL

Neocortex-like reinforcement learning that runs on the GPU or CPU (OpenCL)
C++
69
star
4

TsetlinMachine

An implementation of the Tsetlin machine in C++
C++
61
star
5

ERL

ERL - Evolved Reinforcement Learner
C++
42
star
6

ContinuousHTMGPU

A continuous implementation of hierarchical temporal memory on the GPU
C++
39
star
7

pyhtfe

Python bindings to HTFE
C++
33
star
8

EvolvedVirtualCreaturesRepo

3DVCE
C++
25
star
9

GLLight2D

A real-time 2D path tracer with global illumination.
C++
17
star
10

GSDR

Generative SDR demo
C++
13
star
11

HTSL

Hierarchical Temporal Sparse Learner
C++
13
star
12

HTFERL

A variant of HTM where spatial and temporal pooling are accomplished with the same mechanism
C++
13
star
13

MiniNeoRL

Simple, small, fully-connected Python version of NeoRL
Python
11
star
14

BIDInet

A bi-directional information flow reinforcement learning agent.
C++
11
star
15

PyTorch_BSN

Optimize any PyTorch neural network with Bandit Swarm Networks (BSN)
Python
8
star
16

TeensyAtariPlayingAgent

An agent for playing Atari games running on a Teensy microcontroller
C++
7
star
17

HEInetGPU

Hierarchical extension of EInet on the GPU
C++
7
star
18

HyperNEAT

C++11 implementation of NEAT and HyperNEAT.
C++
6
star
19

NeoRL-CPU

CPU version of NeoRL.
C++
6
star
20

Lorcan-Mini

Smaller version of my previous quadruped robot, Lorcan!
Python
5
star
21

Link

Link text to commands and generated programs.
C
3
star
22

HTFE

HTFERL without the RL (pure predictor)
C++
3
star
23

PySwarm

Python bindings to Swarm
C++
3
star
24

GANTheftAutoWithAOgmaNeo

Based on Sentdex's "GAN Theft Auto", but using AOgmaNeo instead of a GAN
Python
3
star
25

Swarm

Implementation of BSN (Bandit Swarm Networks)
C++
3
star
26

pyHTFERL

A python version of HTFERL
Python
3
star
27

OdinTriadicMemory

A re-implementation of Peter Overmann's Triadic Memory in Odin
Odin
3
star
28

ExpView

Experiment plot viewer for machine learning with git
C++
1
star
29

Roguelike

A RTS Roguelike.
C++
1
star
30

leca

Learned Elementary Cellular Automata (Leca)
C++
1
star
31

PySumo

A simple robot sumo simulation for reinforcement learning in Python.
Python
1
star