BSDF.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   BSDF.h
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Abstract representation of a BSDF defined at a single point on a 
00009    surface in 3-space.
00010    
00011       A BSDF (or Bidirectional Scattering Distribution Function) is a function 
00012    defining the fraction of light propagated after hitting a surface in a 
00013    given exitent direction, wo, from a given incident direction, wi. It 
00014    represents the observed radiance leaving in direction wo, per unit of 
00015    irradiance arriving from wi. A BSDF is commonly denoted by the notation 
00016    fs(wi->wo).
00017       It is much more common in computer graphics to hear one speak about 
00018    BRDFs (or Bidirectional Reflectance Distribution Functions), the difference 
00019    being that BSDFs are defined over the entire sphere of solid angles and 
00020    therefore include transmission (transparency), whereas BRDFs are defined 
00021    only on the positive hemisphere at a surface point with respect to its 
00022    local geometric normal.  BRDFs represent a subset of allowable BSDFs, and 
00023    they suffice in simulating the majority of real world materials. The 
00024    added complexity / generality of BSDFs, however, is important to any 
00025    physically based rendering engine such as Milton. A BRDF is commonly 
00026    denoted by fr(wi->wo).
00027    
00028       Physically valid BRDFs have several basic properties or consraints, 
00029    namely reciprocity and conservation of energy.
00030       Reciprocity means that BRDFs are symmetric: fr(wi->wo) = fr(wo->wi). 
00031    For this reason, it is common to make the symmetric explicit in the notation
00032    by instead writing fr(wi<->wo) in the case of BRDFs or fs(wi<->wo) in the 
00033    case of BSDFs.
00034       Conservation of energy states that a surface should not reflect more 
00035    energy than it receives. Formally this can be stated as the integral of 
00036    fr(wi->wo) over the positive hemisphere at any point with respect to a 
00037    projected solid angle measure has to be less than or equal to one for 
00038    all possible incident vectors, wi.
00039    
00040    @htmlonly
00041    Example usage:
00042    <pre><code>
00043       SurfacePoint pt;
00044       const real_t t = m_scene->getIntersection(ray, pt);
00045       
00046       // lazily initialize SurfacePoint and return if no intersection
00047       if (!pt.init(ray, t))
00048          return; // ray didn't hit anything (t == INFINITY)
00049       
00050       // sample the BSDF for an exitant direction
00051       const Event &event = pt.bsdf->sample();
00052       const Vector3 &wo  = event;
00053       
00054       if (wo == Vector3::zero())
00055          return; // invalid exitant direction
00056       
00057       // evaluate BSDF in the given exitant direction and divide by probability
00058       // with which we sampled that direction
00059       const real_t pdf = pt.bsdf->getPdf(event);
00060       const SpectralSampleSet &fs = pt.bsdf->getBSDF(wo) / pdf;
00061       
00062       // ... trace another ray in direction 'wo' ...
00063    </code></pre>
00064    @endhtmlonly
00065    <!-------------------------------------------------------------------->**/
00066 
00067 #include "BSDF.h"
00068 #include <materials.h>
00069 
00070 #include <GL/gl.h>
00071 
00072 void BSDF::preview(Shape *) {
00073    SpectralSampleSet spectrum;
00074    
00075    // be careful; we don't want to add any keys to the PropertyMap here
00076    if (m_parent->contains("glColor"))
00077       spectrum = m_parent->getSpectralSampleSet("glColor", m_pt);
00078    else if (m_parent->contains("kd"))
00079       spectrum = m_parent->getSpectralSampleSet("kd", m_pt);
00080    else 
00081       spectrum = SpectralSampleSet(0.8, 0.8, 0.8);
00082    
00083    if (spectrum == SpectralSampleSet::black())
00084       spectrum = SpectralSampleSet(0.8, 0.8, 0.8);
00085    
00086    glColor3real_tv(spectrum.getRGB().data);
00087 }
00088 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6