OGRE  1.9.0
OgreShaderExPerPixelLighting.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE 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
38namespace Ogre {
39namespace RTShader {
40
48#define SGX_LIB_PERPIXELLIGHTING "SGXLib_PerPixelLighting"
49#define SGX_FUNC_TRANSFORMNORMAL "SGX_TransformNormal"
50#define SGX_FUNC_TRANSFORMPOSITION "SGX_TransformPosition"
51#define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSE "SGX_Light_Directional_Diffuse"
52#define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSESPECULAR "SGX_Light_Directional_DiffuseSpecular"
53#define SGX_FUNC_LIGHT_POINT_DIFFUSE "SGX_Light_Point_Diffuse"
54#define SGX_FUNC_LIGHT_POINT_DIFFUSESPECULAR "SGX_Light_Point_DiffuseSpecular"
55#define SGX_FUNC_LIGHT_SPOT_DIFFUSE "SGX_Light_Spot_Diffuse"
56#define SGX_FUNC_LIGHT_SPOT_DIFFUSESPECULAR "SGX_Light_Spot_DiffuseSpecular"
57
61class _OgreRTSSExport PerPixelLighting : public SubRenderState
62{
63
64// Interface.
65public:
67 PerPixelLighting();
68
72 virtual const String& getType() const;
73
77 virtual int getExecutionOrder() const;
78
82 virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
83
87 virtual void copyFrom(const SubRenderState& rhs);
88
89
93 virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
94
95
96
97 static String Type;
98
99// Protected types:
100protected:
101
102 // Per light parameters.
103 struct _OgreRTSSExport LightParams
104 {
105 Light::LightTypes mType; // Light type.
106 // Light position.
107 UniformParameterPtr mPosition;
108 // Light direction.
109 UniformParameterPtr mDirection;
110 // Attenuation parameters.
111 UniformParameterPtr mAttenuatParams;
112 // Spot light parameters.
113 UniformParameterPtr mSpotParams;
114 // Diffuse colour.
115 UniformParameterPtr mDiffuseColour;
116 // Specular colour.
117 UniformParameterPtr mSpecularColour;
118
119 };
120
121 typedef vector<LightParams>::type LightParamsList;
122 typedef LightParamsList::iterator LightParamsIterator;
123 typedef LightParamsList::const_iterator LightParamsConstIterator;
124
125// Protected methods
126protected:
127
133 void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; }
134
138 TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; }
139
140
145 void setLightCount(const int lightCount[3]);
146
151 void getLightCount(int lightCount[3]) const;
157 void setSpecularEnable(bool enable) { mSpecularEnable = enable; }
158
162 bool getSpecularEnable() const { return mSpecularEnable; }
163
164
168 virtual bool resolveParameters(ProgramSet* programSet);
169
171 bool resolveGlobalParameters(ProgramSet* programSet);
172
174 bool resolvePerLightParameters(ProgramSet* programSet);
175
179 virtual bool resolveDependencies(ProgramSet* programSet);
180
184 virtual bool addFunctionInvocations(ProgramSet* programSet);
185
186
190 bool addVSInvocation(Function* vsMain, const int groupOrder, int& internalCounter);
191
192
196 bool addPSGlobalIlluminationInvocation(Function* psMain, const int groupOrder, int& internalCounter);
197
201 bool addPSIlluminationInvocation(LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter);
202
206 bool addPSFinalAssignmentInvocation(Function* psMain, const int groupOrder, int& internalCounter);
207
208
209// Attributes.
210protected:
211 // Track per vertex colour type.
212 TrackVertexColourType mTrackVertexColourType;
213 // Specular component enabled/disabled.
214 bool mSpecularEnable;
215 // Light list.
216 LightParamsList mLightParamsList;
217 // World view matrix parameter.
218 UniformParameterPtr mWorldViewMatrix;
219 // World view matrix inverse transpose parameter.
220 UniformParameterPtr mWorldViewITMatrix;
221 // Vertex shader input position parameter.
222 ParameterPtr mVSInPosition;
223 // Vertex shader output view position (position in camera space) parameter.
224 ParameterPtr mVSOutViewPos;
225 // Pixel shader input view position (position in camera space) parameter.
226 ParameterPtr mPSInViewPos;
227 // Vertex shader input normal.
228 ParameterPtr mVSInNormal;
229 // Vertex shader output normal.
230 ParameterPtr mVSOutNormal;
231 // Pixel shader input normal.
232 ParameterPtr mPSInNormal;
233 // Pixel shader temporary diffuse calculation parameter.
234 ParameterPtr mPSTempDiffuseColour;
235 // Pixel shader temporary specular calculation parameter.
236 ParameterPtr mPSTempSpecularColour;
237 // Pixel shader input/local diffuse parameter.
238 ParameterPtr mPSDiffuse;
239 // Pixel shader input/local specular parameter.
240 ParameterPtr mPSSpecular;
241 // Pixel shader output diffuse parameter.
242 ParameterPtr mPSOutDiffuse;
243 // Pixel shader output specular parameter.
244 ParameterPtr mPSOutSpecular;
245 // Derived scene colour parameter.
246 UniformParameterPtr mDerivedSceneColour;
247 // Ambient light colour parameter.
248 UniformParameterPtr mLightAmbientColour;
249 // Derived ambient light colour parameter.
250 UniformParameterPtr mDerivedAmbientLightColour;
251 // Surface ambient colour parameter.
252 UniformParameterPtr mSurfaceAmbientColour;
253 // Surface diffuse colour parameter.
254 UniformParameterPtr mSurfaceDiffuseColour;
255 // Surface specular colour parameter.
256 UniformParameterPtr mSurfaceSpecularColour;
257 // Surface emissive colour parameter.
258 UniformParameterPtr mSurfaceEmissiveColour;
259 // Surface shininess parameter.
260 UniformParameterPtr mSurfaceShininess;
261 // Shared blank light.
262 static Light msBlankLight;
263};
264
265
270class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory
271{
272public:
273
277 virtual const String& getType() const;
278
282 virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
283
287 virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
288
289
290protected:
291
295 virtual SubRenderState* createInstanceImpl();
296
297
298};
299
303}
304}
305
306#endif
307#endif
308
#define _OgreRTSSExport
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:276
SharedPtr< Parameter > ParameterPtr
SharedPtr< UniformParameter > UniformParameterPtr
_StringBase String