00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * 基本シェーダ固定パイプライン実装 00022 * @author Junpee 00023 */ 00024 00025 #include "LampBasic.h" 00026 #include "Graphics/Shader/BasicShaderFixed.h" 00027 #include "Graphics/Renderer/RenderingDevice.h" 00028 #include "Graphics/Material/Material.h" 00029 00030 #include "Graphics/Texture/Texture.h" 00031 00032 namespace Lamp{ 00033 00034 //------------------------------------------------------------------------------ 00035 // コンストラクタ 00036 BasicShaderFixed::BasicShaderFixed(){ 00037 } 00038 //------------------------------------------------------------------------------ 00039 // デストラクタ 00040 BasicShaderFixed::~BasicShaderFixed(){ 00041 } 00042 //------------------------------------------------------------------------------ 00043 // ステートブロックの構築 00044 void BasicShaderFixed::buildStateBlock( 00045 Direct3DStateBlock** startBlock, Direct3DStateBlock** endBlock, 00046 Material* material, Texture* baseTexture, int baseUVIndex, 00047 Texture* lightTexture, int lightUVIndex, Texture* stainTexture, 00048 int stainUVIndex, const Color3f& diffuseColor, 00049 const Color3f& specularColor, const Color3f& ambientColor, 00050 const Color3f& emissiveColor, float specularPower){ 00051 // 前処理 00052 Assert((startBlock != NULL) && (endBlock != NULL)); 00053 Assert(((*startBlock) == NULL) && ((*endBlock) == NULL)); 00054 00055 //-------------------------------------------------------------------------- 00056 // 描画開始ステートブロックの構築 00057 //-------------------------------------------------------------------------- 00058 device_->beginStateBlock(); 00059 // マテリアルの設定 00060 buildMaterialStart(material); 00061 // 固定機能ライティングのマテリアル設定 00062 device_->setMaterial(diffuseColor, specularColor, ambientColor, 00063 emissiveColor, specularPower, material->getAlpha()); 00064 00065 //-------------------------------------------------------------------------- 00066 // カラーテクスチャステージの設定 00067 // スペキュラ項がテクスチャステージ後に足される為、GlossMapが行えない 00068 // Color = (Diffuse + light) * base * stain + Specular 00069 int colorStage = 0; 00070 // ライトテクスチャ、ライトUVインデックス 00071 colorStage = setFixedLightTexture(colorStage, lightTexture, lightUVIndex); 00072 00073 // ベーステクスチャ、ベースUVインデックス 00074 int baseTextureStage = colorStage; 00075 if(baseTexture == NULL){ baseTextureStage = -1; } 00076 colorStage = setFixedBaseTexture(colorStage, baseTexture, baseUVIndex); 00077 00078 // 汚れテクスチャ、汚れUVインデックス 00079 colorStage = setFixedStainTexture(colorStage, stainTexture, stainUVIndex); 00080 00081 // カラーテクスチャステージを閉じる 00082 device_->closeColorTextureStage(colorStage); 00083 00084 //-------------------------------------------------------------------------- 00085 // アルファステクスチャテージの設定 00086 // Alpha = Diffuse.a * base 00087 device_->setAlphaTextureStage(baseTextureStage); 00088 00089 //-------------------------------------------------------------------------- 00090 // ステートブロックを閉じる 00091 (*startBlock) = device_->endStateBlock(); 00092 00093 //-------------------------------------------------------------------------- 00094 // 描画終了ステートブロックの構築 00095 //-------------------------------------------------------------------------- 00096 // 終了ステートブロック無し 00097 // device_->beginStateBlock(); 00098 // マテリアルの設定 00099 // buildMaterialEnd(material); 00100 // (*endBlock) = device_->endStateBlock(); 00101 00102 } 00103 //------------------------------------------------------------------------------ 00104 // 描画 00105 void BasicShaderFixed::draw(DrawRequest* request){ 00106 // 描画のセットアップ 00107 setupFixedDraw(request); 00108 // 描画 00109 drawFixed(request); 00110 // 描画のリセット 00111 resetFixedDraw(request); 00112 } 00113 //------------------------------------------------------------------------------ 00114 } // End of namespace Lamp 00115 //------------------------------------------------------------------------------