Coder Social home page Coder Social logo

opensourcegamedeveloper / sample-lights-and-shadows Goto Github PK

View Code? Open in Web Editor NEW

This project forked from defold/sample-lights-and-shadows

0.0 0.0 0.0 820 KB

Example of how to achieve pixel perfect shadows in a 2D view

License: MIT License

GLSL 16.39% Lua 41.31% Go 42.30%

sample-lights-and-shadows's Introduction

Lights and Shadows

Example of how to achieve pixel perfect shadows in a 2D view. The sample is based on the following sources:

Installation

You can use this solution in your own project by adding this this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/defold/sample-lights-and-shadows/archive/master.zip

Usage

The main components of this light and shadow casting example are:

  • lights/lightsource.script - Attach this script to any game object that should act as a lightsource. Modify the exposed script properties to control the light properties:
    • radius [number] - Radius of the lightsource in pixels
    • color [vector4] - Color of the lightsource (RGBA)
    • arc_angle [number] - Arc angle of the lightsource. Can be used to generate a cone of light up to an arc angle of 180 degrees. Anything above 180 degrees will result in a full circle.
    • static [boolean] - Use this for static lights that do not move or rotate to skip updates of light position and rotation each frame.
  • lights/render/light_quad.go - A game object with a basic model quad, used as a render target when drawing lights and shadows.
  • lights/render/lights.render and lights/render/lights.render_script - The render file and render script used when drawing lights and shadows (and also all of the standard Defold components such as sprites, particles, tilemaps etc)
  • lights/materials/light_occluder_*.material - Materials to use for sprite, tilemaps and other components that should occlude light and cast shadows.

Step 1 - Render script

Open game.project and scroll down to Bootstrap and change Render file to lights/render/lights.render. This render script works like the default render script with the addition of also drawing lights and shadows.

Step 2 - Add light quad

Add the lights/render/light_quad.go to a collection where lights and shadows should be calculated.

Step 3 - Add lightsources

Attach the lights/lightsource.script to any game object that should act as a lightsource.

Configure the lightsource properties to your liking.

Step 4 - Add light occluders

Change the material for any component that should cast shadows when lit by a lightsource. Select a material from lights/materials/ matching the component type casting shadows.

Example

There is an example included in this repository. It sets up a few lightsources and occluders and lets you move around the scene.

sample-lights-and-shadows's People

Contributors

britzl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.