Git Product home page Git Product logo

triplesphere's Introduction

Spherical Light Integration over Spherical Caps via Spherical Harmonics

Reference implementation of the paper Spherical Light Integration over Spherical Caps via Spherical Harmonics.

Build

The project relies on cmake to construct and a modern C++ compiler with C++11 support. Code for building:

git clone https://github.com/Hearwindsaying/TripleSphere.git
mkdir build
cd build
cmake ..
make

Structure

The project consists of several headers, testing and selected precomputation data. Core functions in include/TripleSphere.h directly compute sphere light SH coefficients on the fly, without depending on a concrete renderer. Incoporate these functions into a renderer (either PRT interactive or offline physically based) should be easy, since there are no external dependencies for the implementation.

  • include/Serialize.h,include/SHUtils.h,include/VecType.h provide utilities for reading/saving matrix, fundamental types, SH/ZH evaluations and helper functions for projecting BRDF to SH.
  • include/TripleSphere.h provides core implementation on computing light SH coefficients.
  • tests/TestMC.cpp tests our recurrence formulae and compares with Monte-Carlo method.
  • tests/BRDF.h,tests/ProjectBRDF.cpp give a sample code for computing BRDF matrix. It is straightforward to extend to other types of BRDF by adding classes with Eval_f(wo,wi) implementation.
  • data/ has a few sample for BRDF matrix, weighting coefficients and lobe directions for ZHF. Note that for high orders (such as order 16), the matrix conditioning could have an impact on the results. Take care of numerical issues.

Usage

Preparation:

  const float3 lobeDirs[2 * 15 + 1]{#include "15order_bluenoise_lobe_dirs.csv"};
  const float alphaCoeff[256][31]{#include "15order_bluenoise_a_matrix.csv"};
  const float diffuseCoeff[(15 + 1)*(15 + 1)]{#include "15order_diffuse.csv"};

Assuming it is time for shading BRDF with sphere lights, first figure out the parametrization:

  // Convert light direction to TBN.
  float3 L_TBN = normalize(frame.toLocal(normalize(sphereLight.center - p));
  // Compute Light parameters, aperture angle for spherical light cap
  float sinSigma = sqrt(sphereLight.radius * sphereLight.radius / sqr_length(sphereLight.center - p));
  float cosSigma = sqrt(1 - sinSigma * sinSigma);

We could now compute the light SH coefficients:

  // Allocate space for storage
  float3 ylmCoeff[(SHIOrder + 1)*(SHIOrder + 1)];
  for (int i = 0; i < (SHIOrder + 1)*(SHIOrder + 1); ++i)
      ylmCoeff[i] = make_float3(0.0f);

  Sphere_computeCoeff<SHIOrder>(L_TBN, sinSigma, cosSigma, ylmCoeff, make_float3(sphereLight.intensity), lobeDirs, alphaCoeff);

After getting BRDF coefficients (through BRDF matrix or analytical formulae), the magic happens here via a simple dot product:

  L += (diffuseCoeff[i] * ylmCoeff[i]);

Acknowledgement

We would like to thanks the authors of IntegralSH for the implementation of Integrating Clipped Spherical Harmonics Expansions.

Contact

Feel free to contact [email protected] if you have any questions.

triplesphere's People

Contributors

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