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-2009 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 00051 class _OgreRTSSExport PerPixelLighting : public SubRenderState 00052 { 00053 00054 // Interface. 00055 public: 00057 PerPixelLighting(); 00058 00062 virtual const String& getType () const; 00063 00067 virtual int getExecutionOrder () const; 00068 00072 virtual void updateGpuProgramsParams (Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList); 00073 00077 virtual void copyFrom (const SubRenderState& rhs); 00078 00079 00083 virtual bool preAddToRenderState (RenderState* renderState, Pass* srcPass, Pass* dstPass); 00084 00085 00086 00087 static String Type; 00088 00089 // Protected types: 00090 protected: 00091 00092 // Per light parameters. 00093 struct _OgreRTSSExport LightParams 00094 { 00095 Light::LightTypes mType; // Light type. 00096 UniformParameterPtr mPosition; // Light position. 00097 UniformParameterPtr mDirection; // Light direction. 00098 UniformParameterPtr mAttenuatParams; // Attenuation parameters. 00099 UniformParameterPtr mSpotParams; // Spot light parameters. 00100 UniformParameterPtr mDiffuseColour; // Diffuse colour. 00101 UniformParameterPtr mSpecularColour; // Specular colour. 00102 00103 }; 00104 00105 typedef vector<LightParams>::type LightParamsList; 00106 typedef LightParamsList::iterator LightParamsIterator; 00107 typedef LightParamsList::const_iterator LightParamsConstIterator; 00108 00109 // Protected methods 00110 protected: 00111 00117 void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; } 00118 00122 TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; } 00123 00124 00129 void setLightCount (const int lightCount[3]); 00130 00135 void getLightCount (int lightCount[3]) const; 00141 void setSpecularEnable (bool enable) { mSpecularEnable = enable; } 00142 00146 bool getSpecularEnable () const { return mSpecularEnable; } 00147 00148 00152 virtual bool resolveParameters (ProgramSet* programSet); 00153 00155 bool resolveGlobalParameters (ProgramSet* programSet); 00156 00158 bool resolvePerLightParameters (ProgramSet* programSet); 00159 00163 virtual bool resolveDependencies (ProgramSet* programSet); 00164 00168 virtual bool addFunctionInvocations (ProgramSet* programSet); 00169 00170 00174 bool addVSInvocation (Function* vsMain, const int groupOrder, int& internalCounter); 00175 00176 00180 bool addPSGlobalIlluminationInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00181 00185 bool addPSIlluminationInvocation (LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter); 00186 00190 bool addPSFinalAssignmentInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00191 00192 00193 // Attributes. 00194 protected: 00195 TrackVertexColourType mTrackVertexColourType; // Track per vertex colour type. 00196 bool mSpecularEnable; // Specular component enabled/disabled. 00197 LightParamsList mLightParamsList; // Light list. 00198 UniformParameterPtr mWorldViewMatrix; // World view matrix parameter. 00199 UniformParameterPtr mWorldViewITMatrix; // World view matrix inverse transpose parameter. 00200 ParameterPtr mVSInPosition; // Vertex shader input position parameter. 00201 ParameterPtr mVSOutViewPos; // Vertex shader output view position (position in camera space) parameter. 00202 ParameterPtr mPSInViewPos; // Pixel shader input view position (position in camera space) parameter. 00203 ParameterPtr mVSInNormal; // Vertex shader input normal. 00204 ParameterPtr mVSOutNormal; // Vertex shader output normal. 00205 ParameterPtr mPSInNormal; // Pixel shader input normal. 00206 ParameterPtr mPSTempDiffuseColour; // Pixel shader temporary diffuse calculation parameter. 00207 ParameterPtr mPSTempSpecularColour; // Pixel shader temporary specular calculation parameter. 00208 ParameterPtr mPSDiffuse; // Pixel shader input/local diffuse parameter. 00209 ParameterPtr mPSSpecular; // Pixel shader input/local specular parameter. 00210 ParameterPtr mPSOutDiffuse; // Pixel shader output diffuse parameter. 00211 ParameterPtr mPSOutSpecular; // Pixel shader output specular parameter. 00212 UniformParameterPtr mDerivedSceneColour; // Derived scene colour parameter. 00213 UniformParameterPtr mLightAmbientColour; // Ambient light colour parameter. 00214 UniformParameterPtr mDerivedAmbientLightColour; // Derived ambient light colour parameter. 00215 UniformParameterPtr mSurfaceAmbientColour; // Surface ambient colour parameter. 00216 UniformParameterPtr mSurfaceDiffuseColour; // Surface diffuse colour parameter. 00217 UniformParameterPtr mSurfaceSpecularColour; // Surface specular colour parameter. 00218 UniformParameterPtr mSurfaceEmissiveColour; // Surface emissive colour parameter. 00219 UniformParameterPtr mSurfaceShininess; // Surface shininess parameter. 00220 static Light msBlankLight; // Shared blank light. 00221 }; 00222 00223 00228 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory 00229 { 00230 public: 00231 00235 virtual const String& getType () const; 00236 00240 virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass); 00241 00245 virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass); 00246 00247 00248 protected: 00249 00253 virtual SubRenderState* createInstanceImpl (); 00254 00255 00256 }; 00257 00261 } 00262 } 00263 00264 #endif 00265 #endif 00266
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52