OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-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 _ShaderExPerPixelLighting_
28 #define _ShaderExPerPixelLighting_
29 
31 #ifdef RTSHADER_SYSTEM_BUILD_EXT_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 
51 class _OgreRTSSExport PerPixelLighting : public SubRenderState
52 {
53 
54 // Interface.
55 public:
57  PerPixelLighting();
58 
62  virtual const String& getType () const;
63 
67  virtual int getExecutionOrder () const;
68 
72  virtual void updateGpuProgramsParams (Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
73 
77  virtual void copyFrom (const SubRenderState& rhs);
78 
79 
83  virtual bool preAddToRenderState (RenderState* renderState, Pass* srcPass, Pass* dstPass);
84 
85 
86 
87  static String Type;
88 
89 // Protected types:
90 protected:
91 
92  // Per light parameters.
93  struct _OgreRTSSExport LightParams
94  {
95  Light::LightTypes mType; // Light type.
96  UniformParameterPtr mPosition; // Light position.
97  UniformParameterPtr mDirection; // Light direction.
98  UniformParameterPtr mAttenuatParams; // Attenuation parameters.
99  UniformParameterPtr mSpotParams; // Spot light parameters.
100  UniformParameterPtr mDiffuseColour; // Diffuse colour.
101  UniformParameterPtr mSpecularColour; // Specular colour.
102 
103  };
104 
105  typedef vector<LightParams>::type LightParamsList;
106  typedef LightParamsList::iterator LightParamsIterator;
107  typedef LightParamsList::const_iterator LightParamsConstIterator;
108 
109 // Protected methods
110 protected:
111 
117  void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
118 
122  TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
123 
124 
129  void setLightCount (const int lightCount[3]);
130 
135  void getLightCount (int lightCount[3]) const;
141  void setSpecularEnable (bool enable) { mSpecularEnable = enable; }
142 
146  bool getSpecularEnable () const { return mSpecularEnable; }
147 
148 
152  virtual bool resolveParameters (ProgramSet* programSet);
153 
155  bool resolveGlobalParameters (ProgramSet* programSet);
156 
158  bool resolvePerLightParameters (ProgramSet* programSet);
159 
163  virtual bool resolveDependencies (ProgramSet* programSet);
164 
168  virtual bool addFunctionInvocations (ProgramSet* programSet);
169 
170 
174  bool addVSInvocation (Function* vsMain, const int groupOrder, int& internalCounter);
175 
176 
180  bool addPSGlobalIlluminationInvocation (Function* psMain, const int groupOrder, int& internalCounter);
181 
185  bool addPSIlluminationInvocation (LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter);
186 
190  bool addPSFinalAssignmentInvocation (Function* psMain, const int groupOrder, int& internalCounter);
191 
192 
193 // Attributes.
194 protected:
195  TrackVertexColourType mTrackVertexColourType; // Track per vertex colour type.
196  bool mSpecularEnable; // Specular component enabled/disabled.
197  LightParamsList mLightParamsList; // Light list.
198  UniformParameterPtr mWorldViewMatrix; // World view matrix parameter.
199  UniformParameterPtr mWorldViewITMatrix; // World view matrix inverse transpose parameter.
200  ParameterPtr mVSInPosition; // Vertex shader input position parameter.
201  ParameterPtr mVSOutViewPos; // Vertex shader output view position (position in camera space) parameter.
202  ParameterPtr mPSInViewPos; // Pixel shader input view position (position in camera space) parameter.
203  ParameterPtr mVSInNormal; // Vertex shader input normal.
204  ParameterPtr mVSOutNormal; // Vertex shader output normal.
205  ParameterPtr mPSInNormal; // Pixel shader input normal.
206  ParameterPtr mPSTempDiffuseColour; // Pixel shader temporary diffuse calculation parameter.
207  ParameterPtr mPSTempSpecularColour; // Pixel shader temporary specular calculation parameter.
208  ParameterPtr mPSDiffuse; // Pixel shader input/local diffuse parameter.
209  ParameterPtr mPSSpecular; // Pixel shader input/local specular parameter.
210  ParameterPtr mPSOutDiffuse; // Pixel shader output diffuse parameter.
211  ParameterPtr mPSOutSpecular; // Pixel shader output specular parameter.
212  UniformParameterPtr mDerivedSceneColour; // Derived scene colour parameter.
213  UniformParameterPtr mLightAmbientColour; // Ambient light colour parameter.
214  UniformParameterPtr mDerivedAmbientLightColour; // Derived ambient light colour parameter.
215  UniformParameterPtr mSurfaceAmbientColour; // Surface ambient colour parameter.
216  UniformParameterPtr mSurfaceDiffuseColour; // Surface diffuse colour parameter.
217  UniformParameterPtr mSurfaceSpecularColour; // Surface specular colour parameter.
218  UniformParameterPtr mSurfaceEmissiveColour; // Surface emissive colour parameter.
219  UniformParameterPtr mSurfaceShininess; // Surface shininess parameter.
220  static Light msBlankLight; // Shared blank light.
221 };
222 
223 
228 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory
229 {
230 public:
231 
235  virtual const String& getType () const;
236 
240  virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass);
241 
245  virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
246 
247 
248 protected:
249 
253  virtual SubRenderState* createInstanceImpl ();
254 
255 
256 };
257 
261 }
262 }
263 
264 #endif
265 #endif
266 
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