OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2014 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(const 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  // Light position.
98  UniformParameterPtr mPosition;
99  // Light direction.
100  UniformParameterPtr mDirection;
101  // Attenuation parameters.
102  UniformParameterPtr mAttenuatParams;
103  // Spot light parameters.
104  UniformParameterPtr mSpotParams;
105  // Diffuse colour.
106  UniformParameterPtr mDiffuseColour;
107  // Specular colour.
108  UniformParameterPtr mSpecularColour;
109 
110  };
111 
112  typedef vector<LightParams>::type LightParamsList;
113  typedef LightParamsList::iterator LightParamsIterator;
114  typedef LightParamsList::const_iterator LightParamsConstIterator;
115 
116 // Protected methods
117 protected:
123  void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
124 
128  TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
129 
134  void setLightCount(const int lightCount[3]);
135 
140  void getLightCount(int lightCount[3]) const;
141 
147  void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
148 
152  bool getSpecularEnable() const { return mSpecularEnable; }
153 
157  virtual bool resolveParameters(ProgramSet* programSet);
158 
162  virtual bool resolveDependencies(ProgramSet* programSet);
163 
167  virtual bool addFunctionInvocations(ProgramSet* programSet);
168 
169 
173  bool addGlobalIlluminationInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
174 
178  bool addIlluminationInvocation(LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter);
179 
180 
181 // Attributes.
182 protected:
183  // Track per vertex colour type.
184  TrackVertexColourType mTrackVertexColourType;
185  // Specular component enabled/disabled.
186  bool mSpecularEnable;
187  // Light list.
188  LightParamsList mLightParamsList;
189  // World view matrix parameter.
190  UniformParameterPtr mWorldViewMatrix;
191  // World view matrix inverse transpose parameter.
192  UniformParameterPtr mWorldViewITMatrix;
193  // Vertex shader input position parameter.
194  ParameterPtr mVSInPosition;
195  // Vertex shader input normal.
196  ParameterPtr mVSInNormal;
197  // Vertex shader diffuse.
198  ParameterPtr mVSDiffuse;
199  // Vertex shader output diffuse colour parameter.
200  ParameterPtr mVSOutDiffuse;
201  // Vertex shader output specular colour parameter.
202  ParameterPtr mVSOutSpecular;
203  // Derived scene colour parameter.
204  UniformParameterPtr mDerivedSceneColour;
205  // Ambient light colour parameter.
206  UniformParameterPtr mLightAmbientColour;
207  // Derived ambient light colour parameter.
208  UniformParameterPtr mDerivedAmbientLightColour;
209  // Surface ambient colour parameter.
210  UniformParameterPtr mSurfaceAmbientColour;
211  // Surface diffuse colour parameter.
212  UniformParameterPtr mSurfaceDiffuseColour;
213  // Surface specular colour parameter.
214  UniformParameterPtr mSurfaceSpecularColour;
215  // Surface emissive colour parameter.
216  UniformParameterPtr mSurfaceEmissiveColour;
217  // Surface shininess parameter.
218  UniformParameterPtr mSurfaceShininess;
219  // Shared blank light.
220  static Light msBlankLight;
221 
222 };
223 
224 
229 class _OgreRTSSExport FFPLightingFactory : public SubRenderStateFactory
230 {
231 public:
232 
236  virtual const String& getType() const;
237 
241  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
242 
246  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
247 
248 
249 protected:
250 
254  virtual SubRenderState* createInstanceImpl();
255 
256 
257 };
258 
262 }
263 }
264 
265 #endif
266 #endif
HashedVector< Light * > LightList
Definition: OgreCommon.h:541
LightTypes
Defines the type of light.
Definition: OgreLight.h:82
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:276