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 _ShaderExNormalMapLighting_ 00028 #define _ShaderExNormalMapLighting_ 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 NormalMapLighting : public SubRenderState 00052 { 00053 00054 // Interface. 00055 public: 00057 NormalMapLighting(); 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 00088 void setTexCoordIndex (unsigned int index) { mVSTexCoordSetIndex = index;} 00089 00093 unsigned int getTexCoordIndex () const { return mVSTexCoordSetIndex; } 00094 00095 // Type of this render state. 00096 static String Type; 00097 00098 // Normal map space definition. 00099 enum NormalMapSpace 00100 { 00101 NMS_TANGENT, // Normal map contains normal data in tangent space. 00102 // This is the default normal mapping behavior and it requires that the 00103 // target mesh will have valid tangents within its vertex data. 00104 00105 NMS_OBJECT // Normal map contains normal data in object local space. 00106 // This normal mapping technique has the advantages of better visualization results, 00107 // lack of artifacts that comes from texture mirroring usage, it doesn't requires tangent 00108 // and it also saves some instruction in the vertex shader stage. 00109 // The main drawback of using this kind of normal map is that the target object must be static 00110 // in terms of local space rotations and translations. 00111 }; 00112 00117 void setNormalMapSpace (NormalMapSpace normalMapSpace) { mNormalMapSpace = normalMapSpace; } 00118 00120 NormalMapSpace getNormalMapSpace () const { return mNormalMapSpace; } 00121 00125 void setNormalMapTextureName (const String& textureName) { mNormalMapTextureName = textureName; } 00126 00130 const String& getNormalMapTextureName () const { return mNormalMapTextureName; } 00131 00138 void setNormalMapFiltering (const FilterOptions minFilter, const FilterOptions magFilter, const FilterOptions mipFilter) 00139 { mNormalMapMinFilter = minFilter; mNormalMapMagFilter = magFilter; mNormalMapMipFilter = mipFilter; } 00140 00147 void getNormalMapFiltering (FilterOptions& minFilter, FilterOptions& magFilter, FilterOptions& mipFilter) const 00148 { minFilter = mNormalMapMinFilter; magFilter = mNormalMapMagFilter ; mipFilter = mNormalMapMipFilter; } 00149 00153 void setNormalMapAnisotropy (unsigned int anisotropy) { mNormalMapAnisotropy = anisotropy; } 00154 00155 00157 unsigned int getNormalMapAnisotropy () const { return mNormalMapAnisotropy; } 00158 00159 00163 void setNormalMapMipBias (Real mipBias) { mNormalMapMipBias = mipBias; } 00164 00165 00167 Real getNormalMapMipBias () const { return mNormalMapMipBias; } 00168 00169 00170 00171 // Protected types: 00172 protected: 00173 00174 // Per light parameters. 00175 struct _OgreRTSSExport LightParams 00176 { 00177 Light::LightTypes mType; // Light type. 00178 UniformParameterPtr mPosition; // Light position. 00179 ParameterPtr mVSOutToLightDir; // Vertex shader output vertex position to light position direction (texture space). 00180 ParameterPtr mPSInToLightDir; // Pixel shader input vertex position to light position direction (texture space). 00181 UniformParameterPtr mDirection; // Light direction. 00182 ParameterPtr mVSOutDirection; // Vertex shader output light direction (texture space). 00183 ParameterPtr mPSInDirection; // Pixel shader input light direction (texture space). 00184 UniformParameterPtr mAttenuatParams; // Attenuation parameters. 00185 UniformParameterPtr mSpotParams; // Spot light parameters. 00186 UniformParameterPtr mDiffuseColour; // Diffuse colour. 00187 UniformParameterPtr mSpecularColour; // Specular colour. 00188 00189 }; 00190 00191 typedef vector<LightParams>::type LightParamsList; 00192 typedef LightParamsList::iterator LightParamsIterator; 00193 typedef LightParamsList::const_iterator LightParamsConstIterator; 00194 00195 // Protected methods 00196 protected: 00197 00203 void setTrackVertexColourType(TrackVertexColourType type) { mTrackVertexColourType = type; } 00204 00208 TrackVertexColourType getTrackVertexColourType() const { return mTrackVertexColourType; } 00209 00210 00215 void setLightCount (const int lightCount[3]); 00216 00221 void getLightCount (int lightCount[3]) const; 00227 void setSpecularEnable (bool enable) { mSpecularEnable = enable; } 00228 00232 bool getSpecularEnable () const { return mSpecularEnable; } 00233 00234 00238 virtual bool resolveParameters (ProgramSet* programSet); 00239 00241 bool resolveGlobalParameters (ProgramSet* programSet); 00242 00244 bool resolvePerLightParameters (ProgramSet* programSet); 00245 00249 virtual bool resolveDependencies (ProgramSet* programSet); 00250 00254 virtual bool addFunctionInvocations (ProgramSet* programSet); 00255 00256 00260 bool addVSInvocation (Function* vsMain, const int groupOrder, int& internalCounter); 00261 00265 bool addVSIlluminationInvocation (LightParams* curLightParams, Function* vsMain, const int groupOrder, int& internalCounter); 00266 00270 bool addPSNormalFetchInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00271 00272 00276 bool addPSGlobalIlluminationInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00277 00281 bool addPSIlluminationInvocation (LightParams* curLightParams, Function* psMain, const int groupOrder, int& internalCounter); 00282 00286 bool addPSFinalAssignmentInvocation (Function* psMain, const int groupOrder, int& internalCounter); 00287 00288 00289 // Attributes. 00290 protected: 00291 String mNormalMapTextureName; // The normal map texture name. 00292 TrackVertexColourType mTrackVertexColourType; // Track per vertex colour type. 00293 bool mSpecularEnable; // Specular component enabled/disabled. 00294 LightParamsList mLightParamsList; // Light list. 00295 unsigned short mNormalMapSamplerIndex; // Normal map texture sampler index. 00296 unsigned int mVSTexCoordSetIndex; // Vertex shader input texture coordinate set index. 00297 FilterOptions mNormalMapMinFilter; // The normal map min filter. 00298 FilterOptions mNormalMapMagFilter; // The normal map mag filter. 00299 FilterOptions mNormalMapMipFilter; // The normal map mip filter. 00300 unsigned int mNormalMapAnisotropy; // The normal map max anisotropy value. 00301 Real mNormalMapMipBias; // The normal map mip map bias. 00302 NormalMapSpace mNormalMapSpace; // The normal map space. 00303 UniformParameterPtr mWorldMatrix; // World matrix parameter. 00304 UniformParameterPtr mWorldInvRotMatrix; // World matrix inverse rotation matrix parameter. 00305 UniformParameterPtr mCamPosWorldSpace; // Camera position in world space parameter. 00306 ParameterPtr mVSInPosition; // Vertex shader input position parameter. 00307 ParameterPtr mVSWorldPosition; // Vertex shader world position parameter. 00308 ParameterPtr mVSOutView; // Vertex shader output view vector (position in camera space) parameter. 00309 ParameterPtr mPSInView; // Pixel shader input view position (position in camera space) parameter. 00310 ParameterPtr mVSInNormal; // Vertex shader input normal. 00311 ParameterPtr mVSInTangent; // Vertex shader input tangent. 00312 ParameterPtr mVSTBNMatrix; // Vertex shader local TNB matrix. 00313 ParameterPtr mVSLocalDir; // Vertex shader local light direction. 00314 UniformParameterPtr mNormalMapSampler; // Normal map texture sampler parameter. 00315 ParameterPtr mPSNormal; // Pixel shader normal parameter. 00316 ParameterPtr mVSInTexcoord; // Vertex shader input texture coordinates. 00317 ParameterPtr mVSOutTexcoord; // Vertex shader output texture coordinates. 00318 ParameterPtr mPSInTexcoord; // Pixel shader input texture coordinates. 00319 ParameterPtr mPSTempDiffuseColour; // Pixel shader temporary diffuse calculation parameter. 00320 ParameterPtr mPSTempSpecularColour; // Pixel shader temporary specular calculation parameter. 00321 ParameterPtr mPSDiffuse; // Pixel shader input/local diffuse parameter. 00322 ParameterPtr mPSSpecular; // Pixel shader input/local specular parameter. 00323 ParameterPtr mPSOutDiffuse; // Pixel shader output diffuse parameter. 00324 ParameterPtr mPSOutSpecular; // Pixel shader output specular parameter. 00325 UniformParameterPtr mDerivedSceneColour; // Derived scene colour parameter. 00326 UniformParameterPtr mLightAmbientColour; // Ambient light colour parameter. 00327 UniformParameterPtr mDerivedAmbientLightColour; // Derived ambient light colour parameter. 00328 UniformParameterPtr mSurfaceAmbientColour; // Surface ambient colour parameter. 00329 UniformParameterPtr mSurfaceDiffuseColour; // Surface diffuse colour parameter. 00330 UniformParameterPtr mSurfaceSpecularColour; // Surface specular colour parameter. 00331 UniformParameterPtr mSurfaceEmissiveColour; // Surface emissive colour parameter. 00332 UniformParameterPtr mSurfaceShininess; // Surface shininess parameter. 00333 static Light msBlankLight; // Shared blank light. 00334 }; 00335 00336 00341 class _OgreRTSSExport NormalMapLightingFactory : public SubRenderStateFactory 00342 { 00343 public: 00344 00348 virtual const String& getType () const; 00349 00353 virtual SubRenderState* createInstance (ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass); 00354 00358 virtual void writeInstance (MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass); 00359 00360 00361 protected: 00362 00366 virtual SubRenderState* createInstanceImpl (); 00367 00368 00369 }; 00370 00374 } 00375 } 00376 00377 #endif 00378 #endif 00379
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