OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderExPerPixelLighting.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 _ShaderExPerPixelLighting_
28 #define _ShaderExPerPixelLighting_
29 
31 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS
33 #include "OgreLight.h"
34 #include "OgreCommon.h"
35 
36 namespace Ogre {
37 namespace RTShader {
38 
46 #define SGX_LIB_PERPIXELLIGHTING "SGXLib_PerPixelLighting"
47 #define SGX_FUNC_TRANSFORMNORMAL "SGX_TransformNormal"
48 #define SGX_FUNC_TRANSFORMPOSITION "SGX_TransformPosition"
49 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSE "SGX_Light_Directional_Diffuse"
50 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSESPECULAR "SGX_Light_Directional_DiffuseSpecular"
51 #define SGX_FUNC_LIGHT_POINT_DIFFUSE "SGX_Light_Point_Diffuse"
52 #define SGX_FUNC_LIGHT_POINT_DIFFUSESPECULAR "SGX_Light_Point_DiffuseSpecular"
53 #define SGX_FUNC_LIGHT_SPOT_DIFFUSE "SGX_Light_Spot_Diffuse"
54 #define SGX_FUNC_LIGHT_SPOT_DIFFUSESPECULAR "SGX_Light_Spot_DiffuseSpecular"
55 
59 class _OgreRTSSExport PerPixelLighting : public SubRenderState
60 {
61 
62 // Interface.
63 public:
65  PerPixelLighting();
66 
70  virtual const String& getType() const;
71 
75  virtual int getExecutionOrder() const;
76 
80  virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
81 
85  virtual void copyFrom(const SubRenderState& rhs);
86 
87 
91  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
92 
93 
94 
95  static String Type;
96 
97 // Protected types:
98 protected:
99 
100  // Per light parameters.
101  struct _OgreRTSSExport LightParams
102  {
103  Light::LightTypes mType; // Light type.
104  // Light position.
105  UniformParameterPtr mPosition;
106  // Light direction.
107  UniformParameterPtr mDirection;
108  // Attenuation parameters.
109  UniformParameterPtr mAttenuatParams;
110  // Spot light parameters.
111  UniformParameterPtr mSpotParams;
112  // Diffuse colour.
113  UniformParameterPtr mDiffuseColour;
114  // Specular colour.
115  UniformParameterPtr mSpecularColour;
116 
117  };
118 
119  typedef vector<LightParams>::type LightParamsList;
120  typedef LightParamsList::iterator LightParamsIterator;
121  typedef LightParamsList::const_iterator LightParamsConstIterator;
122 
123 // Protected methods
124 protected:
125 
131  void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
132 
136  TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
137 
138 
143  void setLightCount(const int lightCount[3]);
144 
149  void getLightCount(int lightCount[3]) const;
155  void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
156 
160  bool getSpecularEnable() const { return mSpecularEnable; }
161 
162 
166  virtual bool resolveParameters(ProgramSet* programSet);
167 
169  bool resolveGlobalParameters(ProgramSet* programSet);
170 
172  bool resolvePerLightParameters(ProgramSet* programSet);
173 
177  virtual bool resolveDependencies(ProgramSet* programSet);
178 
182  virtual bool addFunctionInvocations(ProgramSet* programSet);
183 
184 
188  bool addVSInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
189 
190 
194  bool addPSGlobalIlluminationInvocation(Function* psMain, const int groupOrder, int& internalCounter);
195 
199  bool addPSIlluminationInvocation(LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter);
200 
204  bool addPSFinalAssignmentInvocation(Function* psMain, const int groupOrder, int& internalCounter);
205 
206 
207 // Attributes.
208 protected:
209  // Track per vertex colour type.
210  TrackVertexColourType mTrackVertexColourType;
211  // Specular component enabled/disabled.
212  bool mSpecularEnable;
213  // Light list.
214  LightParamsList mLightParamsList;
215  // World view matrix parameter.
216  UniformParameterPtr mWorldViewMatrix;
217  // World view matrix inverse transpose parameter.
218  UniformParameterPtr mWorldViewITMatrix;
219  // Vertex shader input position parameter.
220  ParameterPtr mVSInPosition;
221  // Vertex shader output view position (position in camera space) parameter.
222  ParameterPtr mVSOutViewPos;
223  // Pixel shader input view position (position in camera space) parameter.
224  ParameterPtr mPSInViewPos;
225  // Vertex shader input normal.
226  ParameterPtr mVSInNormal;
227  // Vertex shader output normal.
228  ParameterPtr mVSOutNormal;
229  // Pixel shader input normal.
230  ParameterPtr mPSInNormal;
231  // Pixel shader temporary diffuse calculation parameter.
232  ParameterPtr mPSTempDiffuseColour;
233  // Pixel shader temporary specular calculation parameter.
234  ParameterPtr mPSTempSpecularColour;
235  // Pixel shader input/local diffuse parameter.
236  ParameterPtr mPSDiffuse;
237  // Pixel shader input/local specular parameter.
238  ParameterPtr mPSSpecular;
239  // Pixel shader output diffuse parameter.
240  ParameterPtr mPSOutDiffuse;
241  // Pixel shader output specular parameter.
242  ParameterPtr mPSOutSpecular;
243  // Derived scene colour parameter.
244  UniformParameterPtr mDerivedSceneColour;
245  // Ambient light colour parameter.
246  UniformParameterPtr mLightAmbientColour;
247  // Derived ambient light colour parameter.
248  UniformParameterPtr mDerivedAmbientLightColour;
249  // Surface ambient colour parameter.
250  UniformParameterPtr mSurfaceAmbientColour;
251  // Surface diffuse colour parameter.
252  UniformParameterPtr mSurfaceDiffuseColour;
253  // Surface specular colour parameter.
254  UniformParameterPtr mSurfaceSpecularColour;
255  // Surface emissive colour parameter.
256  UniformParameterPtr mSurfaceEmissiveColour;
257  // Surface shininess parameter.
258  UniformParameterPtr mSurfaceShininess;
259 };
260 
261 
266 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory
267 {
268 public:
269 
273  virtual const String& getType() const;
274 
278  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
279 
283  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
284 
285 
286 protected:
287 
291  virtual SubRenderState* createInstanceImpl();
292 
293 
294 };
295 
299 }
300 }
301 
302 #endif
303 #endif
304 
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