00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 Permission is hereby granted, free of charge, to any person obtaining a copy 00009 of this software and associated documentation files (the "Software"), to deal 00010 in the Software without restriction, including without limitation the rights 00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 copies of the Software, and to permit persons to whom the Software is 00013 furnished to do so, subject to the following conditions: 00014 00015 The above copyright notice and this permission notice shall be included in 00016 all copies or substantial portions of the Software. 00017 00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 THE SOFTWARE. 00025 ----------------------------------------------------------------------------- 00026 */ 00027 #ifndef _ShaderExPerPixelLighting_ 00028 #define _ShaderExPerPixelLighting_ 00029 00030 #include "OgreShaderPrerequisites.h" 00031 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS 00032 #include "OgreShaderParameter.h" 00033 #include "OgreShaderSubRenderState.h" 00034 #include "OgreVector4.h" 00035 #include "OgreLight.h" 00036 #include "OgreCommon.h" 00037 00038 namespace Ogre { 00039 namespace RTShader { 00040 00048 #define SGX_LIB_PERPIXELLIGHTING "SGXLib_PerPixelLighting" 00049 #define SGX_FUNC_TRANSFORMNORMAL "SGX_TransformNormal" 00050 #define SGX_FUNC_TRANSFORMPOSITION "SGX_TransformPosition" 00051 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSE "SGX_Light_Directional_Diffuse" 00052 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSESPECULAR "SGX_Light_Directional_DiffuseSpecular" 00053 #define SGX_FUNC_LIGHT_POINT_DIFFUSE "SGX_Light_Point_Diffuse" 00054 #define SGX_FUNC_LIGHT_POINT_DIFFUSESPECULAR "SGX_Light_Point_DiffuseSpecular" 00055 #define SGX_FUNC_LIGHT_SPOT_DIFFUSE "SGX_Light_Spot_Diffuse" 00056 #define SGX_FUNC_LIGHT_SPOT_DIFFUSESPECULAR "SGX_Light_Spot_DiffuseSpecular" 00057 00061 class _OgreRTSSExport PerPixelLighting : public SubRenderState 00062 { 00063 00064 // Interface. 00065 public: 00067 PerPixelLighting(); 00068 00072 virtual const String& getType () const; 00073 00077 virtual int getExecutionOrder () const; 00078 00082 virtual void updateGpuProgramsParams (Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList); 00083 00087 virtual void copyFrom (const SubRenderState& rhs); 00088 00089 00093 virtual bool preAddToRenderState (const RenderState* renderState, Pass* srcPass, Pass* dstPass); 00094 00095 00096 00097 static String Type; 00098 00099 // Protected types: 00100 protected: 00101 00102 // Per light parameters. 00103 struct _OgreRTSSExport LightParams 00104 { 00105 Light::LightTypes mType; // Light type. 00106 UniformParameterPtr mPosition; // Light position. 00107 UniformParameterPtr mDirection; // Light direction. 00108 UniformParameterPtr mAttenuatParams; // Attenuation parameters. 00109 UniformParameterPtr mSpotParams; // Spot light parameters. 00110 UniformParameterPtr mDiffuseColour; // Diffuse colour. 00111 UniformParameterPtr mSpecularColour; // Specular colour. 00112 00113 }; 00114 00115 typedef vector<LightParams>::type LightParamsList; 00116 typedef LightParamsList::iterator LightParamsIterator; 00117 typedef LightParamsList::const_iterator LightParamsConstIterator; 00118 00119 // Protected methods 00120 protected: 00121 00127 void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; } 00128 00132 TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; } 00133 00134 00139 void setLightCount (const int lightCount[3]); 00140 00145 void getLightCount (int lightCount[3]) const; 00151 void setSpecularEnable (bool enable) { mSpecularEnable = enable; } 00152 00156 bool getSpecularEnable () const { return mSpecularEnable; } 00157 00158 00162 virtual bool resolveParameters (ProgramSet* programSet); 00163 00165 bool resolveGlobalParameters (ProgramSet* programSet); 00166 00168 bool resolvePerLightParameters (ProgramSet* programSet); 00169 00173 virtual bool resolveDependencies (ProgramSet* programSet); 00174 00178 virtual bool addFunctionInvocations (ProgramSet* programSet); 00179 00180 00184 bool addVSInvocation (Function* vsMain, const int groupOrder, int& internalCounter); 00185 00186 00190 bool addPSGlobalIlluminationInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00191 00195 bool addPSIlluminationInvocation (LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter); 00196 00200 bool addPSFinalAssignmentInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00201 00202 00203 // Attributes. 00204 protected: 00205 TrackVertexColourType mTrackVertexColourType; // Track per vertex colour type. 00206 bool mSpecularEnable; // Specular component enabled/disabled. 00207 LightParamsList mLightParamsList; // Light list. 00208 UniformParameterPtr mWorldViewMatrix; // World view matrix parameter. 00209 UniformParameterPtr mWorldViewITMatrix; // World view matrix inverse transpose parameter. 00210 ParameterPtr mVSInPosition; // Vertex shader input position parameter. 00211 ParameterPtr mVSOutViewPos; // Vertex shader output view position (position in camera space) parameter. 00212 ParameterPtr mPSInViewPos; // Pixel shader input view position (position in camera space) parameter. 00213 ParameterPtr mVSInNormal; // Vertex shader input normal. 00214 ParameterPtr mVSOutNormal; // Vertex shader output normal. 00215 ParameterPtr mPSInNormal; // Pixel shader input normal. 00216 ParameterPtr mPSTempDiffuseColour; // Pixel shader temporary diffuse calculation parameter. 00217 ParameterPtr mPSTempSpecularColour; // Pixel shader temporary specular calculation parameter. 00218 ParameterPtr mPSDiffuse; // Pixel shader input/local diffuse parameter. 00219 ParameterPtr mPSSpecular; // Pixel shader input/local specular parameter. 00220 ParameterPtr mPSOutDiffuse; // Pixel shader output diffuse parameter. 00221 ParameterPtr mPSOutSpecular; // Pixel shader output specular parameter. 00222 UniformParameterPtr mDerivedSceneColour; // Derived scene colour parameter. 00223 UniformParameterPtr mLightAmbientColour; // Ambient light colour parameter. 00224 UniformParameterPtr mDerivedAmbientLightColour; // Derived ambient light colour parameter. 00225 UniformParameterPtr mSurfaceAmbientColour; // Surface ambient colour parameter. 00226 UniformParameterPtr mSurfaceDiffuseColour; // Surface diffuse colour parameter. 00227 UniformParameterPtr mSurfaceSpecularColour; // Surface specular colour parameter. 00228 UniformParameterPtr mSurfaceEmissiveColour; // Surface emissive colour parameter. 00229 UniformParameterPtr mSurfaceShininess; // Surface shininess parameter. 00230 static Light msBlankLight; // Shared blank light. 00231 }; 00232 00233 00238 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory 00239 { 00240 public: 00241 00245 virtual const String& getType () const; 00246 00250 virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator); 00251 00255 virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass); 00256 00257 00258 protected: 00259 00263 virtual SubRenderState* createInstanceImpl (); 00264 00265 00266 }; 00267 00271 } 00272 } 00273 00274 #endif 00275 #endif 00276
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:26 2012