OgreShaderFFPLighting.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 Permission is hereby granted, free of charge, to any person obtaining a copy
00009 of this software and associated documentation files (the "Software"), to deal
00010 in the Software without restriction, including without limitation the rights
00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012 copies of the Software, and to permit persons to whom the Software is
00013 furnished to do so, subject to the following conditions:
00014 
00015 The above copyright notice and this permission notice shall be included in
00016 all copies or substantial portions of the Software.
00017 
00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024 THE SOFTWARE.
00025 -----------------------------------------------------------------------------
00026 */
00027 #ifndef _ShaderFFPLighting_
00028 #define _ShaderFFPLighting_
00029 
00030 #include "OgreShaderPrerequisites.h"
00031 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
00032 #include "OgreShaderParameter.h"
00033 #include "OgreShaderSubRenderState.h"
00034 #include "OgreVector4.h"
00035 #include "OgreLight.h"
00036 #include "OgreCommon.h"
00037 
00038 namespace Ogre {
00039 namespace RTShader {
00040 
00041 
00053 class _OgreRTSSExport FFPLighting : public SubRenderState
00054 {
00055 
00056 // Interface.
00057 public:
00058     
00060     FFPLighting();
00061 
00065     virtual const String&   getType                 () const;
00066 
00070     virtual int             getExecutionOrder       () const;
00071 
00075     virtual void            updateGpuProgramsParams (Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
00076 
00080     virtual void            copyFrom                (const SubRenderState& rhs);
00081 
00085     virtual bool            preAddToRenderState     (const RenderState* renderState, Pass* srcPass, Pass* dstPass);
00086 
00087 
00088     static String Type;
00089 
00090 // Protected types:
00091 protected:
00092 
00093     // Per light parameters.
00094     struct _OgreRTSSExport LightParams
00095     {
00096         Light::LightTypes       mType;              // Light type.      
00097         UniformParameterPtr     mPosition;          // Light position.
00098         UniformParameterPtr     mDirection;         // Light direction.
00099         UniformParameterPtr     mAttenuatParams;    // Attenuation parameters.
00100         UniformParameterPtr     mSpotParams;        // Spot light parameters.
00101         UniformParameterPtr     mDiffuseColour;     // Diffuse colour.
00102         UniformParameterPtr     mSpecularColour;    // Specular colour.
00103 
00104     };
00105 
00106     typedef vector<LightParams>::type               LightParamsList;
00107     typedef LightParamsList::iterator               LightParamsIterator;
00108     typedef LightParamsList::const_iterator         LightParamsConstIterator;
00109 
00110 // Protected methods
00111 protected:
00117     void                    setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
00118 
00122     TrackVertexColourType   getTrackVertexColourType() const { return mTrackVertexColourType; }
00123 
00128     void                    setLightCount           (const int lightCount[3]);
00129 
00134     void                    getLightCount           (int lightCount[3]) const;
00135 
00141     void                    setSpecularEnable       (bool enable) { mSpecularEnable = enable; }
00142 
00146     bool                    getSpecularEnable       () const      { return mSpecularEnable; }
00147 
00151     virtual bool            resolveParameters       (ProgramSet* programSet);
00152 
00156     virtual bool            resolveDependencies     (ProgramSet* programSet);
00157 
00161     virtual bool            addFunctionInvocations  (ProgramSet* programSet);
00162 
00163 
00167     bool            addGlobalIlluminationInvocation (Function* vsMain, const int groupOrder, int& internalCounter);
00168             
00172     bool            addIlluminationInvocation       (LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter);
00173 
00174 
00175 // Attributes.
00176 protected:  
00177     TrackVertexColourType   mTrackVertexColourType;         // Track per vertex colour type.
00178     bool                    mSpecularEnable;                // Specular component enabled/disabled.
00179     LightParamsList         mLightParamsList;               // Light list.
00180     UniformParameterPtr     mWorldViewMatrix;               // World view matrix parameter.
00181     UniformParameterPtr     mWorldViewITMatrix;             // World view matrix inverse transpose parameter.
00182     ParameterPtr            mVSInPosition;                  // Vertex shader input position parameter.
00183     ParameterPtr            mVSInNormal;                    // Vertex shader input normal.
00184     ParameterPtr            mVSDiffuse;                     // Vertex shader diffuse.
00185     ParameterPtr            mVSOutDiffuse;                  // Vertex shader output diffuse colour parameter.
00186     ParameterPtr            mVSOutSpecular;                 // Vertex shader output specular colour parameter.
00187     UniformParameterPtr     mDerivedSceneColour;            // Derived scene colour parameter.
00188     UniformParameterPtr     mLightAmbientColour;            // Ambient light colour parameter.
00189     UniformParameterPtr     mDerivedAmbientLightColour;     // Derived ambient light colour parameter.
00190     UniformParameterPtr     mSurfaceAmbientColour;          // Surface ambient colour parameter.
00191     UniformParameterPtr     mSurfaceDiffuseColour;          // Surface diffuse colour parameter.
00192     UniformParameterPtr     mSurfaceSpecularColour;         // Surface specular colour parameter.
00193     UniformParameterPtr     mSurfaceEmissiveColour;         // Surface emissive colour parameter.
00194     UniformParameterPtr     mSurfaceShininess;              // Surface shininess parameter.
00195     static Light            msBlankLight;                   // Shared blank light.
00196 
00197 };
00198 
00199 
00204 class _OgreRTSSExport FFPLightingFactory : public SubRenderStateFactory
00205 {
00206 public:
00207 
00211     virtual const String&   getType             () const;
00212 
00216     virtual SubRenderState* createInstance      (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
00217 
00221     virtual void            writeInstance       (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
00222 
00223     
00224 protected:
00225 
00229     virtual SubRenderState* createInstanceImpl  ();
00230 
00231 
00232 };
00233 
00237 }
00238 }
00239 
00240 #endif
00241 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:26 2012