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         // Light position.
    00098         UniformParameterPtr mPosition;
    00099         // Light direction.
    00100         UniformParameterPtr mDirection;
    00101         // Attenuation parameters.
    00102         UniformParameterPtr mAttenuatParams;
    00103         // Spot light parameters.
    00104         UniformParameterPtr mSpotParams;
    00105         // Diffuse colour.
    00106         UniformParameterPtr mDiffuseColour;
    00107         // Specular colour.
    00108         UniformParameterPtr mSpecularColour;
    00109
    00110     };
    00111
    00112     typedef vector<LightParams>::type               LightParamsList;
    00113     typedef LightParamsList::iterator               LightParamsIterator;
    00114     typedef LightParamsList::const_iterator         LightParamsConstIterator;
    00115
    00116 // Protected methods
    00117 protected:
    00123     void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
    00124
    00128     TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
    00129
    00134     void setLightCount(const int lightCount[3]);
    00135
    00140     void getLightCount(int lightCount[3]) const;
    00141
    00147     void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
    00148
    00152     bool getSpecularEnable() const    { return mSpecularEnable; }
    00153
    00157     virtual bool resolveParameters(ProgramSet* programSet);
    00158
    00162     virtual bool resolveDependencies(ProgramSet* programSet);
    00163
    00167     virtual bool addFunctionInvocations(ProgramSet* programSet);
    00168
    00169
    00173     bool addGlobalIlluminationInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
    00174
    00178     bool addIlluminationInvocation(LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter);
    00179
    00180
    00181 // Attributes.
    00182 protected:
    00183     // Track per vertex colour type.
    00184     TrackVertexColourType mTrackVertexColourType;
    00185     // Specular component enabled/disabled.
    00186     bool mSpecularEnable;
    00187     // Light list.
    00188     LightParamsList mLightParamsList;
    00189     // World view matrix parameter.
    00190     UniformParameterPtr mWorldViewMatrix;
    00191     // World view matrix inverse transpose parameter.
    00192     UniformParameterPtr mWorldViewITMatrix;
    00193     // Vertex shader input position parameter.
    00194     ParameterPtr mVSInPosition;
    00195     // Vertex shader input normal.
    00196     ParameterPtr mVSInNormal;
    00197     // Vertex shader diffuse.
    00198     ParameterPtr mVSDiffuse;
    00199     // Vertex shader output diffuse colour parameter.
    00200     ParameterPtr mVSOutDiffuse;
    00201     // Vertex shader output specular colour parameter.
    00202     ParameterPtr mVSOutSpecular;
    00203     // Derived scene colour parameter.
    00204     UniformParameterPtr mDerivedSceneColour;
    00205     // Ambient light colour parameter.
    00206     UniformParameterPtr mLightAmbientColour;
    00207     // Derived ambient light colour parameter.
    00208     UniformParameterPtr mDerivedAmbientLightColour;
    00209     // Surface ambient colour parameter.
    00210     UniformParameterPtr mSurfaceAmbientColour;
    00211     // Surface diffuse colour parameter.
    00212     UniformParameterPtr mSurfaceDiffuseColour;
    00213     // Surface specular colour parameter.
    00214     UniformParameterPtr mSurfaceSpecularColour;
    00215     // Surface emissive colour parameter.
    00216     UniformParameterPtr mSurfaceEmissiveColour;
    00217     // Surface shininess parameter.
    00218     UniformParameterPtr mSurfaceShininess;
    00219     // Shared blank light.
    00220     static Light msBlankLight;
    00221
    00222 };
    00223
    00224
    00229 class _OgreRTSSExport FFPLightingFactory : public SubRenderStateFactory
    00230 {
    00231 public:
    00232
    00236     virtual const String& getType() const;
    00237
    00241     virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
    00242
    00246     virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
    00247
    00248
    00249 protected:
    00250
    00254     virtual SubRenderState* createInstanceImpl();
    00255
    00256
    00257 };
    00258
    00262 }
    00263 }
    00264
    00265 #endif
    00266 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23