Giter Site home page Giter Site logo

light2d's Introduction

light2d

This project illustrates light rendering in 2D with C.

All samples output PNGs with svpng.

License: public domain.

Basic

Use Monte Carol integration and ray marching of signed distance field (SDF) to render a emissive circle.

Source code: basic.c

Uniform sampling (64 samples per pixel):

Uniform sampling with different number of samples per pixel:

Stratified sampling (64 samples per pixel):

Jittered sampling (64 samples per pixel):

Various sampling method side-by-side comparison (64 samples per pixel)::

Constructive Solid Geometry

Source code: csg.c

Use union operation for creating multiple shapes:

Various CSG operations on two circles:

Shapes

Source code: shapes.c

Examples of various shapes defined by SDF:

Reflection

Source code: reflection.c

Test scene with two boxes:

Visualization of SDF gradient, which is approximated by central difference:

Reflection via recursive tracing:

Concave mirror scene generates caustics effect:

Refraction

Source code: refraction.c

Applying Snell's law to compute refraction direction. Total internal reflection is also handled.

Test scenes:

Fresnel Reflectance

Source code: fresnel.c

Applying Fresnel equation to compute reflectance of dielectric medium.

Without Fresnel:

With Fresnel term:

Beer-Lambert

Source code: beerlambert.c beerlambert_color.c

Applying Beer-Lambert law to simulate absorption of light in medimum.

light2d's People

Contributors

miloyip 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.