Git Product home page Git Product logo

brdfgenerator's Introduction

BRDF Generator

This is a simple program that generates Smith GGX BRDF lookup tables for the split sum approximation of the UE4-based PBR pipeline. These lookup tables are stored in KTX or DDS texture. The program generates two channel(RG) images using either 16 bit or 32 bit floating point precision.

Note: It is important to use a floating point image to prevent clamping of values in your PBR pipeline.  
For most applications 16 bits is sufficient.  

Since this table is used for an approximation, some errors are introduced into the final renderings. The top image shows the reference path traced rendering, the middle shows a split sum approximation and the bottom shows the full approximation where N=V.

When loading the texture into OpenGL, use the following filters to ensure that values are read correctly.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

More Reading:

Usage

BRDFGenerator -f [filename] -s [size] -n [samples] -b [bits]

Options:

-f [filename] The location and filename of the output image.  Must have an extension of ktx or dds.
-s [size] The size of the image in pixels per side. i.e. 512 will generate a 512x512 image. 
-n [samples] The number of BRDF samples per pixel. 
-b [bits]  The number of floating point bits used to store the data.  Can be either 16 or 32.

Algorithm

For each pixel (x, y):
   Compute roughness (0 to 1.0) based on pixel x coordinate.
   Compute NoV (0 to 1.0) based on pixel y coordinate.
   Set view as float3(sqrt(1.0 - NoV * NoV), 0, NoV).
   Set normal as float3(0, 0, 1). 
   For each sample:
        Compute a Hammersely coordinate.
        Integrate number of importance samples for (roughness and NoV).
        Compute reflection vector L
        Compute NoL (normal dot light)
        Compute NoH (normal dot half)
        Compute VoH (view dot half)
        
        If NoL > 0
          Compute the geometry term for the BRDF given roughness squared, NoV, NoL
          Compute the visibility term given G, VoH, NoH, NoV, NoL
          Compute the fresnel term given VoH.
          Sum the result given fresnel, geoemtry, visibility.
   Average result over number of samples.

Built With

The project has two header based dependencies, GLI and GLM, they are currently stored in the ext folder.

  • GLM - Math Functions
  • GLI - Image Saving

License

This project is licensed under the MIT License - see the LICENSE file for details

brdfgenerator's People

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.