OgreShaderExPerPixelLighting.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 _ShaderExPerPixelLighting_
00028 #define _ShaderExPerPixelLighting_
00029 
00030 #include "OgreShaderPrerequisites.h"
00031 #ifdef RTSHADER_SYSTEM_BUILD_EXT_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 
00048 #define SGX_LIB_PERPIXELLIGHTING                    "SGXLib_PerPixelLighting"
00049 #define SGX_FUNC_TRANSFORMNORMAL                    "SGX_TransformNormal"
00050 #define SGX_FUNC_TRANSFORMPOSITION                  "SGX_TransformPosition"
00051 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSE          "SGX_Light_Directional_Diffuse"
00052 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSESPECULAR  "SGX_Light_Directional_DiffuseSpecular"
00053 #define SGX_FUNC_LIGHT_POINT_DIFFUSE                "SGX_Light_Point_Diffuse"
00054 #define SGX_FUNC_LIGHT_POINT_DIFFUSESPECULAR        "SGX_Light_Point_DiffuseSpecular"
00055 #define SGX_FUNC_LIGHT_SPOT_DIFFUSE                 "SGX_Light_Spot_Diffuse"
00056 #define SGX_FUNC_LIGHT_SPOT_DIFFUSESPECULAR         "SGX_Light_Spot_DiffuseSpecular"    
00057 
00061 class _OgreRTSSExport PerPixelLighting : public SubRenderState
00062 {
00063 
00064 // Interface.
00065 public:
00067     PerPixelLighting();
00068 
00072     virtual const String& getType() const;
00073 
00077     virtual int getExecutionOrder() const;
00078 
00082     virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
00083 
00087     virtual void copyFrom(const SubRenderState& rhs);
00088 
00089 
00093     virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
00094 
00095 
00096     
00097     static String Type;
00098 
00099 // Protected types:
00100 protected:
00101     
00102     // Per light parameters.
00103     struct _OgreRTSSExport LightParams
00104     {
00105         Light::LightTypes       mType;              // Light type.      
00106         // Light position.
00107         UniformParameterPtr mPosition;
00108         // Light direction.
00109         UniformParameterPtr mDirection;
00110         // Attenuation parameters.
00111         UniformParameterPtr mAttenuatParams;
00112         // Spot light parameters.
00113         UniformParameterPtr mSpotParams;
00114         // Diffuse colour.
00115         UniformParameterPtr mDiffuseColour;
00116         // Specular colour.
00117         UniformParameterPtr mSpecularColour;
00118 
00119     };
00120 
00121     typedef vector<LightParams>::type LightParamsList;
00122     typedef LightParamsList::iterator LightParamsIterator;
00123     typedef LightParamsList::const_iterator LightParamsConstIterator;
00124 
00125 // Protected methods
00126 protected:
00127 
00133     void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
00134 
00138     TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
00139 
00140 
00145     void setLightCount(const int lightCount[3]);
00146 
00151     void getLightCount(int lightCount[3]) const;
00157     void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
00158 
00162     bool getSpecularEnable() const { return mSpecularEnable; }
00163 
00164 
00168     virtual bool resolveParameters(ProgramSet* programSet);
00169 
00171     bool resolveGlobalParameters(ProgramSet* programSet);
00172 
00174     bool resolvePerLightParameters(ProgramSet* programSet);
00175 
00179     virtual bool resolveDependencies(ProgramSet* programSet);
00180 
00184     virtual bool addFunctionInvocations(ProgramSet* programSet);
00185     
00186 
00190     bool addVSInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
00191 
00192     
00196     bool addPSGlobalIlluminationInvocation(Function* psMain, const int groupOrder, int& internalCounter);
00197 
00201     bool addPSIlluminationInvocation(LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter);
00202 
00206     bool addPSFinalAssignmentInvocation(Function* psMain, const int groupOrder, int& internalCounter);
00207 
00208 
00209 // Attributes.
00210 protected:  
00211     // Track per vertex colour type.
00212     TrackVertexColourType mTrackVertexColourType;
00213     // Specular component enabled/disabled.
00214     bool mSpecularEnable;
00215     // Light list.
00216     LightParamsList mLightParamsList;
00217     // World view matrix parameter.
00218     UniformParameterPtr mWorldViewMatrix;
00219     // World view matrix inverse transpose parameter.
00220     UniformParameterPtr mWorldViewITMatrix;
00221     // Vertex shader input position parameter.
00222     ParameterPtr mVSInPosition;
00223     // Vertex shader output view position (position in camera space) parameter.
00224     ParameterPtr mVSOutViewPos;
00225     // Pixel shader input view position (position in camera space) parameter.
00226     ParameterPtr mPSInViewPos;
00227     // Vertex shader input normal.
00228     ParameterPtr mVSInNormal;
00229     // Vertex shader output normal.
00230     ParameterPtr mVSOutNormal;
00231     // Pixel shader input normal.
00232     ParameterPtr mPSInNormal;
00233     // Pixel shader temporary diffuse calculation parameter.
00234     ParameterPtr mPSTempDiffuseColour;
00235     // Pixel shader temporary specular calculation parameter.
00236     ParameterPtr mPSTempSpecularColour;
00237     // Pixel shader input/local diffuse parameter.  
00238     ParameterPtr mPSDiffuse;
00239     // Pixel shader input/local specular parameter. 
00240     ParameterPtr mPSSpecular;
00241     // Pixel shader output diffuse parameter.   
00242     ParameterPtr mPSOutDiffuse;
00243     // Pixel shader output specular parameter.  
00244     ParameterPtr mPSOutSpecular;
00245     // Derived scene colour parameter.
00246     UniformParameterPtr mDerivedSceneColour;
00247     // Ambient light colour parameter.
00248     UniformParameterPtr mLightAmbientColour;
00249     // Derived ambient light colour parameter.
00250     UniformParameterPtr mDerivedAmbientLightColour;
00251     // Surface ambient colour parameter.
00252     UniformParameterPtr mSurfaceAmbientColour;
00253     // Surface diffuse colour parameter.
00254     UniformParameterPtr mSurfaceDiffuseColour;
00255     // Surface specular colour parameter.
00256     UniformParameterPtr mSurfaceSpecularColour;
00257     // Surface emissive colour parameter.
00258     UniformParameterPtr mSurfaceEmissiveColour;
00259     // Surface shininess parameter.
00260     UniformParameterPtr mSurfaceShininess;
00261     // Shared blank light.
00262     static Light msBlankLight;
00263 };
00264 
00265 
00270 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory
00271 {
00272 public:
00273 
00277     virtual const String& getType() const;
00278 
00282     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
00283 
00287     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
00288 
00289     
00290 protected:
00291 
00295     virtual SubRenderState* createInstanceImpl();
00296 
00297 
00298 };
00299 
00303 }
00304 }
00305 
00306 #endif
00307 #endif
00308 

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 Sun Sep 2 2012 07:27:23