OGRE  2.0
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
33 #include "OgreLight.h"
34 #include "OgreCommon.h"
35 
36 namespace Ogre {
37 namespace RTShader {
38 
39 
51 class _OgreRTSSExport FFPLighting : public SubRenderState
52 {
53 
54 // Interface.
55 public:
56 
58  FFPLighting();
59 
63  virtual const String& getType() const;
64 
68  virtual int getExecutionOrder() const;
69 
73  virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
74 
78  virtual void copyFrom(const SubRenderState& rhs);
79 
83  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
84 
85 
86  static String Type;
87 
88 // Protected types:
89 protected:
90 
91  // Per light parameters.
92  struct _OgreRTSSExport LightParams
93  {
94  Light::LightTypes mType; // Light type.
95  // Light position.
96  UniformParameterPtr mPosition;
97  // Light direction.
98  UniformParameterPtr mDirection;
99  // Attenuation parameters.
100  UniformParameterPtr mAttenuatParams;
101  // Spot light parameters.
102  UniformParameterPtr mSpotParams;
103  // Diffuse colour.
104  UniformParameterPtr mDiffuseColour;
105  // Specular colour.
106  UniformParameterPtr mSpecularColour;
107 
108  };
109 
110  typedef vector<LightParams>::type LightParamsList;
111  typedef LightParamsList::iterator LightParamsIterator;
112  typedef LightParamsList::const_iterator LightParamsConstIterator;
113 
114 // Protected methods
115 protected:
121  void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
122 
126  TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
127 
132  void setLightCount(const int lightCount[3]);
133 
138  void getLightCount(int lightCount[3]) const;
139 
145  void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
146 
150  bool getSpecularEnable() const { return mSpecularEnable; }
151 
155  virtual bool resolveParameters(ProgramSet* programSet);
156 
160  virtual bool resolveDependencies(ProgramSet* programSet);
161 
165  virtual bool addFunctionInvocations(ProgramSet* programSet);
166 
167 
171  bool addGlobalIlluminationInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
172 
176  bool addIlluminationInvocation(LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter);
177 
178 
179 // Attributes.
180 protected:
181  // Track per vertex colour type.
182  TrackVertexColourType mTrackVertexColourType;
183  // Specular component enabled/disabled.
184  bool mSpecularEnable;
185  // Light list.
186  LightParamsList mLightParamsList;
187  // World view matrix parameter.
188  UniformParameterPtr mWorldViewMatrix;
189  // World view matrix inverse transpose parameter.
190  UniformParameterPtr mWorldViewITMatrix;
191  // Vertex shader input position parameter.
192  ParameterPtr mVSInPosition;
193  // Vertex shader input normal.
194  ParameterPtr mVSInNormal;
195  // Vertex shader diffuse.
196  ParameterPtr mVSDiffuse;
197  // Vertex shader output diffuse colour parameter.
198  ParameterPtr mVSOutDiffuse;
199  // Vertex shader output specular colour parameter.
200  ParameterPtr mVSOutSpecular;
201  // Derived scene colour parameter.
202  UniformParameterPtr mDerivedSceneColour;
203  // Ambient light colour parameter.
204  UniformParameterPtr mLightAmbientColour;
205  // Derived ambient light colour parameter.
206  UniformParameterPtr mDerivedAmbientLightColour;
207  // Surface ambient colour parameter.
208  UniformParameterPtr mSurfaceAmbientColour;
209  // Surface diffuse colour parameter.
210  UniformParameterPtr mSurfaceDiffuseColour;
211  // Surface specular colour parameter.
212  UniformParameterPtr mSurfaceSpecularColour;
213  // Surface emissive colour parameter.
214  UniformParameterPtr mSurfaceEmissiveColour;
215  // Surface shininess parameter.
216  UniformParameterPtr mSurfaceShininess;
217 };
218 
219 
224 class _OgreRTSSExport FFPLightingFactory : public SubRenderStateFactory
225 {
226 public:
227 
231  virtual const String& getType() const;
232 
236  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
237 
241  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
242 
243 
244 protected:
245 
249  virtual SubRenderState* createInstanceImpl();
250 
251 
252 };
253 
257 }
258 }
259 
260 #endif
261 #endif
LightTypes
Defines the type of light.
Definition: OgreLight.h:79
#define _OgreRTSSExport
SharedPtr< Parameter > ParameterPtr
HashedVector< LightClosest > LightList
Definition: OgreCommon.h:569
SharedPtr< UniformParameter > UniformParameterPtr
_StringBase String
Definition: OgreCommon.h:53
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:221