OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreShaderFFPLighting.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderFFPLighting_
28 #define _ShaderFFPLighting_
29 
31 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
32 #include "OgreShaderParameter.h"
34 #include "OgreVector4.h"
35 #include "OgreLight.h"
36 #include "OgreCommon.h"
37 
38 namespace Ogre {
39 namespace RTShader {
40 
41 
53 class _OgreRTSSExport FFPLighting : public SubRenderState
54 {
55 
56 // Interface.
57 public:
58 
60  FFPLighting();
61 
65  virtual const String& getType () const;
66 
70  virtual int getExecutionOrder () const;
71 
75  virtual void updateGpuProgramsParams (Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
76 
80  virtual void copyFrom (const SubRenderState& rhs);
81 
85  virtual bool preAddToRenderState (RenderState* renderState, Pass* srcPass, Pass* dstPass);
86 
87 
88  static String Type;
89 
90 // Protected types:
91 protected:
92 
93  // Per light parameters.
94  struct _OgreRTSSExport LightParams
95  {
96  Light::LightTypes mType; // Light type.
97  UniformParameterPtr mPosition; // Light position.
98  UniformParameterPtr mDirection; // Light direction.
99  UniformParameterPtr mAttenuatParams; // Attenuation parameters.
100  UniformParameterPtr mSpotParams; // Spot light parameters.
101  UniformParameterPtr mDiffuseColour; // Diffuse colour.
102  UniformParameterPtr mSpecularColour; // Specular colour.
103 
104  };
105 
106  typedef vector<LightParams>::type LightParamsList;
107  typedef LightParamsList::iterator LightParamsIterator;
108  typedef LightParamsList::const_iterator LightParamsConstIterator;
109 
110 // Protected methods
111 protected:
117  void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
118 
122  TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
123 
128  void setLightCount (const int lightCount[3]);
129 
134  void getLightCount (int lightCount[3]) const;
135 
141  void setSpecularEnable (bool enable) { mSpecularEnable = enable; }
142 
146  bool getSpecularEnable () const { return mSpecularEnable; }
147 
151  virtual bool resolveParameters (ProgramSet* programSet);
152 
156  virtual bool resolveDependencies (ProgramSet* programSet);
157 
161  virtual bool addFunctionInvocations (ProgramSet* programSet);
162 
163 
167  bool addGlobalIlluminationInvocation (Function* vsMain, const int groupOrder, int& internalCounter);
168 
172  bool addIlluminationInvocation (LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter);
173 
174 
175 // Attributes.
176 protected:
177  TrackVertexColourType mTrackVertexColourType; // Track per vertex colour type.
178  bool mSpecularEnable; // Specular component enabled/disabled.
179  LightParamsList mLightParamsList; // Light list.
180  UniformParameterPtr mWorldViewMatrix; // World view matrix parameter.
181  UniformParameterPtr mWorldViewITMatrix; // World view matrix inverse transpose parameter.
182  ParameterPtr mVSInPosition; // Vertex shader input position parameter.
183  ParameterPtr mVSInNormal; // Vertex shader input normal.
184  ParameterPtr mVSDiffuse; // Vertex shader diffuse.
185  ParameterPtr mVSOutDiffuse; // Vertex shader output diffuse colour parameter.
186  ParameterPtr mVSOutSpecular; // Vertex shader output specular colour parameter.
187  UniformParameterPtr mDerivedSceneColour; // Derived scene colour parameter.
188  UniformParameterPtr mLightAmbientColour; // Ambient light colour parameter.
189  UniformParameterPtr mDerivedAmbientLightColour; // Derived ambient light colour parameter.
190  UniformParameterPtr mSurfaceAmbientColour; // Surface ambient colour parameter.
191  UniformParameterPtr mSurfaceDiffuseColour; // Surface diffuse colour parameter.
192  UniformParameterPtr mSurfaceSpecularColour; // Surface specular colour parameter.
193  UniformParameterPtr mSurfaceEmissiveColour; // Surface emissive colour parameter.
194  UniformParameterPtr mSurfaceShininess; // Surface shininess parameter.
195  static Light msBlankLight; // Shared blank light.
196 
197 };
198 
199 
204 class _OgreRTSSExport FFPLightingFactory : public SubRenderStateFactory
205 {
206 public:
207 
211  virtual const String& getType () const;
212 
216  virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass);
217 
221  virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
222 
223 
224 protected:
225 
229  virtual SubRenderState* createInstanceImpl ();
230 
231 
232 };
233 
237 }
238 }
239 
240 #endif
241 #endif
HashedVector< Light * > LightList
Definition: OgreCommon.h:515
LightTypes
Defines the type of light.
Definition: OgreLight.h:81
SharedPtr< Parameter > ParameterPtr
#define _OgreRTSSExport
_StringBase String
SharedPtr< UniformParameter > UniformParameterPtr
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:277