Shader.h

Go to the documentation of this file.
00001 /* $Id: Shader.h,v 1.1 2002/12/05 15:08:03 cvs Exp $ */
00002 
00003 #ifndef __SHADER_H
00004 #define __SHADER_H
00005 
00006 #include <gra/GRAObject.h>
00007 #include <gra/reflection/ReflectionModel.h>
00008 #include <esg/SceneGraphObject.h>
00009 #include <gra/scene/Scene.h>
00010 
00011 using namespace esg;
00012 
00013 namespace gra {
00014 
00034 class GRA_EXPORT Shader : public GRAObject {
00035 protected:
00036     ReflectionModel  * _pReflectionModel;
00037     SceneGraphObject * _pShape;    // actually shaded shape
00038     Scene            * _pScene;    // whole scene
00039     DiffuseBRDF      * _pDefaultDiffBRDF;
00040     SpecularBRDF     * _pDefaultSpecBRDF;
00041     
00042 public:
00050         Shader (ReflectionModel * m, DiffuseBRDF * db, SpecularBRDF * sb)
00051             : _pReflectionModel(m),
00052               _pShape(NULL),
00053               _pScene(NULL),
00054               _pDefaultDiffBRDF(db),
00055               _pDefaultSpecBRDF(sb) {}
00056 
00060         virtual ~Shader () {}
00061 
00067         virtual void setScene (Scene * o) {
00068             _pScene = o;
00069             if (_pReflectionModel) _pReflectionModel->setScene(_pScene);
00070         }
00071 
00076         virtual void distributeEnergy (void) = 0;
00077 
00085         virtual bool setRenderedShape (SceneGraphObject * pShape,
00086                                        const Matrix4    * pTrMat) {
00087             _pShape = pShape;
00088             if (!_pShape || !_pReflectionModel) return false;
00089             DiffuseBRDF*  pDiffBRDF = _pShape->diffuseBRDF();
00090             SpecularBRDF* pSpecBRDF = _pShape->specularBRDF();
00091             _pReflectionModel->setDiffuseBRDF((pDiffBRDF)
00092                                               ? pDiffBRDF
00093                                               : _pDefaultDiffBRDF);
00094             _pReflectionModel->setSpecularBRDF((pSpecBRDF)
00095                                                ? pSpecBRDF
00096                                                : _pDefaultSpecBRDF);
00097             _pReflectionModel->setEmittance(_pShape->emittance());
00098             return true;
00099         }
00100 
00117         virtual Color3f* illuminatePoint (const Vector3& location,
00118                                           const Vector3& normal,
00119                                           const Vector3& eyeDir,
00120                                           float          eyeDist,
00121                                           double*        pNV,
00122                                           const Matrix4* pTrMat) = 0;
00123 };
00124     
00125 } // namespace
00126 
00127 #endif // __SHADER_H

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6