Git Product home page Git Product logo

crystal-caustics's Introduction

Crystal Caustics

This project approximate caustics of crystal in real-time using the physically-based caustics rendered offline.

thumbnail

thumbnail

Caustics is a common optical phenomenon that light ray reflected or refracted by an object and created a pattern of light. It usually required track the path of light ray go through the object. However ray tracing is too computationally expensive and can't be done in real-time. This project use pre-render caustics map and light cookie to achieve the approximated effects. See the demo here.

Getting started

  1. Install High Definition Render Pipeline.

  2. Change the setting in the HDRP asset: Lighting > Cookies > Point light cookie size > Resolution 256.

setting

  1. (Optional) Install Unity HDRI pack.

Idea

For each object that has caustics when illuminated, surround it with a mesh bounding box. In the demo I used a icosahedron, but it can be alter to any convex shape. Each vertices of the bounding mesh mapping to one cubemap storing the caustics light.

  1. Render the caustics of target object using photon mapping. To reduce complexity, the light source is limited to one single directional light. Then for each light directions, store the caustics light into a cubemap. The direction is determined by the bounding mesh.

  2. In the real-time rendering, for each light sources calculate the caustics light by interpolate between the caustics cubemap. The interpolatation weight is determined by the barycentric coordinate of the triangle on the bounding mesh hit by the light ray.

Create your own caustics

1. Render caustics map

Use 3ds Max with VRay to render the caustics map to a sphere. You can use spherify modifier on a cube to generate your baking sphere, or simply download my max file (for 3ds Max 2020). The light cookie guide by Pierre desribed the detail about generating Unity ready cubemap in 3ds Max.

Apply VRay material on your object. I suggest using the physical attribute in the real-world for your material. Lookup the index of refraction and abbe number of a material in here.

mlt

An example VRay material setting of Sapphire.

Adjust the VRay rendering setting, including the caustics subdivisions of your light source, max photon number in the global caustics render setting until you satify with the outcome. Add VRayCaustics to render output, use render to texture on each face of the baking sphere to get the caustics.

2. Import into Unity

Assemble each side of the cubemap into one single texture in order. You can use the smart object in Photoshop linking to the rendering outcome to make your life easier.

Import the caustics map into Unity. Change the import setting of Texture Shape to Cube, Format to RGBA 32 bit.

texture import setting

3. Setup caustics

Create a child gameObject for your object. Adding a point light, a mesh collider and the Caustics script to the child gameObject, or your can simply copy the one in the example scene. Apply the caustics map to the cookie cubemap, and then select the light source that affect the caustics.

Requirements

Unity 2019.1.0

  • HD Render Pipeline

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.