Giter Club home page Giter Club logo

dfao-unity's Introduction

DFAO-Unity

Introduction

This project uses two-level hierarchical SDF and ray marching to render AO and soft shadow.

The computation of objects' local SDF depends on SDF baker (SDFr). Beside local SDF's, a global SDF is maintained and lazily updated during runtime, guiding the beginning steps of ray marching, and roughly locating the movable objects.

Usage

This repository is now upgraded to Unity 2021.3 .

Clone the code and open the scene in Example/Scenes/RayMarchExample, hit "Play", the runtime view should look like the screenshot below.

screenshot preview

To play the demo with more custom meshes, you may

  1. Import the mesh as an object first, and then
  2. Add the script component "SDF baker" to the object, which you could find in the project.
  3. Use the SDFr tool, Encapsulate to optimize the bounding box, then bake distance field for the object
  4. Remember to save the SDF data as asset.

Duplicates or instances of the object may be created, for runtime performance, it is recommended to have same or similar objects sharing the same SDF data.

Thoughts

In this demo I use ray marching to create the AO and penumbra effect, casting view rays from the camera to the scene.

The Distance function is represented by a two-level SDF structure, the step lenght of ray marching is first sampled from a Global Distance Field (GDF) and then the local SDF of adjancent objects.

To make smooth the transition between global SDF and local SDF inside object's bounding box, a conservative addition of the distances is introduced, to guarantee that the marching ray hits precisely the closest surface point of the object.

illust01

However, conservative sum of distance is larger than "true" distance, possibly resulting in the extra marching steps, especially when the angle bewteen the view ray and the rim of the object's bounding box is close to 0 degree.

illust02

Regarding the addition of global distance and local distance, we have a few discussions: using Sqrt root of 2-powered is still conservative and more precise, reducing the number of steps.

Stats

The current shadowing pass costs about 4-6ms on my Nvidia GTX 1660Ti, under HD resolution.

Notice: this effect is closely related to screen size, due to the nature of ray marching algorithm. However, custom optimization can be applied for higher resolution, such as:

  • Lower the sample rate,
  • Use adaptive-resolution rendering (start from here if interested), as AO and soft shadowing commonly require less precision.

In general, this method works better with static scene and limited number of moveable objects.

There are some slides with videos for this project here, noting the presentation was in Chinese and then converted into English, feel free to download at your needs.

Discussions are also very welcome, for any thoughts or questions, please post in issues.

screenshot

dfao-unity's People

Contributors

zephyrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dfao-unity's Issues

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.