00001 /* 00002 toxic - A Global Illumination Renderer 00003 Copyright (C) 2003-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of toxic. 00007 00008 toxic is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 toxic is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with toxic; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef TOXIC_RENDERER_PHOTON_H 00024 #define TOXIC_RENDERER_PHOTON_H 00025 00026 #include "common/math/point3.h" 00027 #include "common/math/vector3.h" 00028 #include "common/misc/binarystream.h" 00029 #include "common/misc/types.h" 00030 #include "color3.h" 00031 #include "globals.h" 00032 #include "utilities.h" 00033 00034 #include <cassert> 00035 00036 namespace toxic { 00037 00038 //! The photon map implementation is based on the reference implementation 00039 //! provided by Henrik Wann Jensen in his book "Realistic Image Synthesis 00040 //! Using Photon Mapping". 00041 00042 class Photon { 00043 public: 00044 sheep::float32 m_position[3]; //!< Position (12 bytes). 00045 00046 Photon(); 00047 00048 void SetPosition(const sheep::Point3 &position); 00049 sheep::Point3 GetPosition() const; 00050 00051 void SetPower(const Color3 &power); 00052 void ScalePower(sheep::Real scale); 00053 Color3 GetPower() const; 00054 00055 //! Sets the photon incident direction. The direction vector must be 00056 //! unit-length, must go away from the surface carrying the photon 00057 //! and must be expressed in world space. 00058 void SetIncidentDirection(const sheep::Vector3 &direction); 00059 00060 //! Returns the photon incident direction. The returned direction is 00061 //! a unit-length vector going away from the surface carrying the 00062 //! photon, and is expressed in world space. 00063 sheep::Vector3 GetIncidentDirection() const; 00064 00065 void SetSplittingPlaneAxis(int axis); 00066 int GetSplittingPlaneAxis() const; 00067 00068 #ifdef ENABLE_RADIANCES_PRECOMPUTATION 00069 00070 //! Returns true if this photon carries a precomputed radiance. 00071 bool HasPrecomputedRadiance() const; 00072 00073 //! Radiance is expressed in W.m^-2.sr^-1. 00074 void SetPrecomputedRadiance(const Color3 &radiance); 00075 Color3 GetPrecomputedRadiance() const; 00076 00077 //! Sets the surface normal at the photon position. The normal must be 00078 //! unit-length and must be expressed in world space. 00079 void SetSurfaceNormal(const sheep::Vector3 &normal); 00080 00081 //! Returns the surface normal at the photon position. The returned normal 00082 //! is unit-length and is expressed in world space. 00083 sheep::Vector3 GetSurfaceNormal() const; 00084 00085 #endif // ENABLE_RADIANCES_PRECOMPUTATION 00086 00087 void WriteToStream(sheep::BinaryStream &os) const; 00088 void ReadFromStream(sheep::BinaryStream &is); 00089 00090 private: 00091 #ifdef COMPRESS_PHOTON_POWER 00092 sheep::uint8 m_power[4]; //!< Compressed power (4 bytes). Expressed in W. 00093 #else 00094 sheep::float32 m_power[3]; //!< Full precision power (12 bytes). Expressed in W. 00095 #endif // COMPRESS_PHOTON_POWER 00096 00097 sheep::uint8 m_qphi, m_qtheta; //!< Compressed incident direction (2 bytes). Expressed in world space (away from the surface). 00098 00099 #ifdef ENABLE_RADIANCES_PRECOMPUTATION 00100 #ifdef COMPRESS_PRECOMPUTED_RADIANCES 00101 sheep::uint8 m_radiance[4]; //!< Compressed precomputed radiance (4 bytes). Expressed in W.m^-2.sr^-1. 00102 #else 00103 sheep::float32 m_radiance[3]; //!< Full precision precomputed radiance (12 bytes). Expressed in W.m^-2.sr^-1. 00104 #endif // COMPRESS_PRECOMPUTED_RADIANCES 00105 sheep::uint8 m_qnormal; //!< Normal of the surface at the photon position (1 byte). 00106 #endif // ENABLE_RADIANCES_PRECOMPUTATION 00107 00108 //! Various flags and data (2 bytes). 00109 //! Bits 1-0: splitting plane axis (for kd-tree construction). 00110 //! Bit 2: 1 if the photon carries an irradiance estimate, 0 otherwise. 00111 //! Do not change the size of this member unless you apply the change everywhere. 00112 sheep::uint16 m_flags; 00113 00114 //!\todo Adjust padding according to the various #defines. 00115 sheep::uint8 m_padding[3]; 00116 }; 00117 00118 #include "photon.inl" 00119 00120 } 00121 00122 #endif // !TOXIC_RENDERER_PHOTON_H
1.3.6