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-2014 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 30 #include "OgreShaderPrerequisites.h" 31 #ifdef RTSHADER_SYSTEM_BUILD_EXT_SHADERS 32 #include "OgreShaderFFPLighting.h" 33 #include "OgreLight.h" 34 #include "OgreCommon.h" 35 36 namespace Ogre { 37 namespace RTShader { 38 39 /** \addtogroup Optional 40 * @{ 41 */ 42 /** \addtogroup RTShader 43 * @{ 44 */ 45 46 #define SGX_LIB_PERPIXELLIGHTING "SGXLib_PerPixelLighting" 47 #define SGX_FUNC_TRANSFORMNORMAL "SGX_TransformNormal" 48 #define SGX_FUNC_TRANSFORMPOSITION "SGX_TransformPosition" 49 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSE "SGX_Light_Directional_Diffuse" 50 #define SGX_FUNC_LIGHT_DIRECTIONAL_DIFFUSESPECULAR "SGX_Light_Directional_DiffuseSpecular" 51 #define SGX_FUNC_LIGHT_POINT_DIFFUSE "SGX_Light_Point_Diffuse" 52 #define SGX_FUNC_LIGHT_POINT_DIFFUSESPECULAR "SGX_Light_Point_DiffuseSpecular" 53 #define SGX_FUNC_LIGHT_SPOT_DIFFUSE "SGX_Light_Spot_Diffuse" 54 #define SGX_FUNC_LIGHT_SPOT_DIFFUSESPECULAR "SGX_Light_Spot_DiffuseSpecular" 55 56 /** Per pixel Lighting extension sub render state implementation. 57 Derives from SubRenderState class. 58 */ 59 class _OgreRTSSExport PerPixelLighting : public FFPLighting 60 { 61 62 // Interface. 63 public: 64 /** 65 @see SubRenderState::getType. 66 */ 67 virtual const String& getType() const; 68 69 static String Type; 70 71 // Protected methods 72 protected: 73 /** 74 @see SubRenderState::resolveParameters. 75 */ 76 virtual bool resolveParameters(ProgramSet* programSet); 77 78 /** Resolve global lighting parameters */ 79 virtual bool resolveGlobalParameters(ProgramSet* programSet); 80 81 /** Resolve per light parameters */ 82 virtual bool resolvePerLightParameters(ProgramSet* programSet); 83 84 /** 85 @see SubRenderState::resolveDependencies. 86 */ 87 virtual bool resolveDependencies(ProgramSet* programSet); 88 89 /** 90 @see SubRenderState::addFunctionInvocations. 91 */ 92 virtual bool addFunctionInvocations(ProgramSet* programSet); 93 94 95 /** 96 Internal method that adds related vertex shader functions invocations. 97 */ 98 bool addVSInvocation(Function* vsMain, const int groupOrder); 99 100 101 /** 102 Internal method that adds global illumination component functions invocations. 103 */ 104 bool addPSGlobalIlluminationInvocation(Function* psMain, const int groupOrder); 105 106 /** 107 Internal method that adds the final colour assignments. 108 */ 109 bool addPSFinalAssignmentInvocation(Function* psMain, const int groupOrder); 110 111 112 // Attributes. 113 protected: 114 // Vertex shader output view position (position in camera space) parameter. 115 ParameterPtr mVSOutViewPos; 116 // Vertex shader output normal. 117 ParameterPtr mVSOutNormal; 118 // Pixel shader input/local specular parameter. 119 ParameterPtr mPSSpecular; 120 }; 121 122 123 /** 124 A factory that enables creation of PerPixelLighting instances. 125 @remarks Sub class of SubRenderStateFactory 126 */ 127 class _OgreRTSSExport PerPixelLightingFactory : public SubRenderStateFactory 128 { 129 public: 130 131 /** 132 @see SubRenderStateFactory::getType. 133 */ 134 virtual const String& getType() const; 135 136 /** 137 @see SubRenderStateFactory::createInstance. 138 */ 139 virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator); 140 141 /** 142 @see SubRenderStateFactory::writeInstance. 143 */ 144 virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass); 145 146 147 protected: 148 149 /** 150 @see SubRenderStateFactory::createInstanceImpl. 151 */ 152 virtual SubRenderState* createInstanceImpl(); 153 154 155 }; 156 157 /** @} */ 158 /** @} */ 159 160 } 161 } 162 163 #endif 164 #endif 165 166