Code Monkey home page Code Monkey logo

bevy-magic-light-2d's Introduction

๐Ÿ”ฎ Bevy Magic Light 2D โ€“ experimental dynamic 2D global illumination system.

Build status dependency status

Discord

๐Ÿšง Beware! This repo is heavily under construction and a lot of things may change.

Experimental dynamic 2D global illumination system for Bevy, based on SDF ray-marching and screen space irradiance cache probes.

Demo

cargo run --example minimal
cargo run --example krypta
cargo run --example movement

Bevy Magic Light 2D โ€“ Demo

Implementation is based on several approaches:

  • First pass computes SDF for all occluders and stores it in a texture with one channel.
  • Second pass computes irradiance from direct light. We check amount of light received by probe taking into account occlusion which checked using SDF. The final contribution for each light source is computed using square falloff.
  • Third pass computes secondary bounced light. The approach is similar to the second pass, but instead of direct light, it uses irradiance is sampled from the probes. We use exponential sampling to check how much of reflected light is received by probe. Same as in the second pass SDF is used to check occlusion and the final contribution is computed using square falloff.
  • Finally, we combine results from the second and third passes combining cache from the previous eight frames. The we optionally filter the result using a edge-aware smoothing filter and apply Gamma correction.

The main performance gain is coming from computing value of only 1 / 64 number of pixels (for 8x8 probe size). The rest of the pixels are interpolated from the nearest probes.

Usage

cargo run --example krypta
  • WASD to control camera.
  • LMC to place a light source.
  • RMC to change color of light source.

TODOs

Optimizations

  • Use jump flood algorithm for calculating SDF.
  • Precomputed noise.
  • Guided sampling for secondary light.

Features

  • Light can bounce from occluders.
  • Arbitrary number of bounces via configuration.
  • Handle camera scale and rotation.
  • Support multiple layers.
  • Expose settings instead of harcoding them.
  • Support resize of targets.
  • Support transparent occluders.
  • Support color transfer from occluders.
  • Add inspector for GI settings.
  • Add support for emissive materials and other types of light sources.

Address limitations

  • SDF for offscreen occluders.

Others

  • Add examples and HUD explaining how to use example.

License

Copyright 2022 Vladimir Zaytsev <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

bevy-magic-light-2d's People

Contributors

dbenson24 avatar issew avatar specificprotagonist avatar xyzw-io avatar zaycev avatar

Watchers

 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.