diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-06-14 01:24:21 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-06-14 01:24:21 +0400 |
commit | 6d62a18a51303da845df1c04cd2b357853b7e7ed (patch) | |
tree | dbe5455cf7d57f719b58615c1c40c6a8f2903439 /source/gameengine | |
parent | 9fb4cbc668ad7fc612cbb63206567066e2626173 (diff) |
Apricot Branch: GLSL
====================
* Added support for lamps and shaders. All material diffuse and
specular shaders are supported, for lamps especially area light
support is not there yet.
* Added support for these GLSL shaders in the game engine, though
it is incomplete and somewhat of a hack. Specifically all the
variables are completely static, which means moving lights, or
animating material properties will not work.
* Enabling GLSL shaders is now different. They work in textured
drawmode, and can be enabled in the Game menu with the option
"Blender GLSL Materials"
Known issues:
* The GLSL shaders don't always update correct on light changes.
* The game player appears to crash with these GLSL shaders, while
regular blender works fine.
Diffstat (limited to 'source/gameengine')
24 files changed, 340 insertions, 55 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index fa8409b123e..15dd519aadf 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -81,6 +81,8 @@ #include "DNA_scene_types.h" /***/ +#include "GPU_extensions.h" + #ifdef __cplusplus extern "C" { #endif @@ -156,7 +158,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0); bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0); - bool usemat = false; + bool usemat = false, useglslmat = false; #if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) if (!getenv("WITHOUT_GLEXT")) { @@ -172,6 +174,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, } #endif + if(GPU_extensions_minimum_support()) { + useglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 0) != 0); + } // create the canvas, rasterizer and rendertools RAS_ICanvas* canvas = new KX_BlenderCanvas(area); @@ -338,6 +343,8 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, if(usemat) sceneconverter->SetMaterials(true); + if(useglslmat) + sceneconverter->SetGLSLMaterials(true); KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript index 327f4798e04..3548354c16b 100644 --- a/source/gameengine/BlenderRoutines/SConscript +++ b/source/gameengine/BlenderRoutines/SConscript @@ -15,7 +15,7 @@ incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common' incs += ' #source/gameengine/Physics/Bullet #source/gameengine/Physics/Sumo' incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' incs += ' #intern/SoundSystem #source/blender/misc #source/blender/blenloader' -incs += ' #extern/glew/include' +incs += ' #extern/glew/include #source/blender/gpu' incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_SOLID_INC'] diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 82d16ffa181..1be462c113f 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -509,6 +509,7 @@ BL_Material* ConvertMaterial( } } } + // above one tex the switches here // are not used switch(valid_index) { @@ -829,7 +830,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* } } - meshobj->SetName(mesh->id.name); meshobj->m_xyz_index_to_vertex_index_mapping.resize(mesh->totvert); for (int f=0;f<mesh->totface;f++,mface++) @@ -891,6 +891,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* ma = give_current_material(blenderobj, 1); bl_mat = ConvertMaterial(mesh, ma, tface, mface, mmcol, lightlayer, blenderobj, layers); + bl_mat->glslmat = converter->GetGLSLMaterials(); // set the index were dealing with bl_mat->material_index = (int)mface->mat_nr; diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 8640e69102b..de91bce2ab1 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -100,7 +100,8 @@ KX_BlenderSceneConverter::KX_BlenderSceneConverter( m_sipo(sipo), m_ketsjiEngine(engine), m_alwaysUseExpandFraming(false), - m_usemat(false) + m_usemat(false), + m_useglslmat(false) { m_newfilename = ""; } @@ -449,6 +450,13 @@ void KX_BlenderSceneConverter::RemoveScene(KX_Scene *scene) void KX_BlenderSceneConverter::SetMaterials(bool val) { m_usemat = val; + m_useglslmat = false; +} + +void KX_BlenderSceneConverter::SetGLSLMaterials(bool val) +{ + m_usemat = val; + m_useglslmat = val; } bool KX_BlenderSceneConverter::GetMaterials() @@ -456,6 +464,10 @@ bool KX_BlenderSceneConverter::GetMaterials() return m_usemat; } +bool KX_BlenderSceneConverter::GetGLSLMaterials() +{ + return m_useglslmat; +} void KX_BlenderSceneConverter::RegisterBlenderMaterial(BL_Material *mat) { diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index a45d7396875..e5d6ccc5caf 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -75,6 +75,7 @@ class KX_BlenderSceneConverter : public KX_ISceneConverter class KX_Scene* m_currentScene; // Scene being converted bool m_alwaysUseExpandFraming; bool m_usemat; + bool m_useglslmat; void localDel_ipoCurve ( IpoCurve * icu ,struct SpaceIpo* sipo); // struct Ipo* findIpoForName(char* objName); @@ -146,6 +147,10 @@ public: virtual void SetMaterials(bool val); virtual bool GetMaterials(); + // use blender glsl materials + virtual void SetGLSLMaterials(bool val); + virtual bool GetGLSLMaterials(); + }; #endif //__KX_BLENDERSCENECONVERTER_H diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index f5e382b471e..3be352c568b 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -16,7 +16,7 @@ incs += ' #source/gameengine/Expressions #source/gameengine/Network #source/game incs += ' #source/gameengine/Physics/common #source/gameengine/Physics/Bullet #source/gameengine/Physics/BlOde' incs += ' #source/gameengine/Physics/Dummy #source/gameengine/Physics/Sumo' incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' -incs += ' #source/blender/misc #source/blender/blenloader' +incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu' incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_SOLID_INC'] diff --git a/source/gameengine/GamePlayer/common/SConscript b/source/gameengine/GamePlayer/common/SConscript index 6ff3ae10735..457ee79bb11 100644 --- a/source/gameengine/GamePlayer/common/SConscript +++ b/source/gameengine/GamePlayer/common/SConscript @@ -45,7 +45,8 @@ incs = ['.', '#source/gameengine/Network/LoopBackNetwork', '#source/gameengine/GamePlayer/ghost', '#source/blender/misc', - '#source/blender/blenloader'] + '#source/blender/blenloader', + '#source/blender/gpu'] #This is all plugin stuff! #if sys.platform=='win32': diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index dfd15227501..14a18f6b74d 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -50,6 +50,8 @@ #endif #endif +#include "GPU_extensions.h" + #include "GPG_Application.h" #include <iostream> @@ -134,7 +136,8 @@ GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main* maggie, STR m_sceneconverter(0), m_networkdevice(0), m_audiodevice(0), - m_blendermat(0) + m_blendermat(0), + m_blenderglslmat(0) { fSystem = system; } @@ -528,6 +531,13 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) m_blendermat=0; #endif//GL_ARB_multitexture // ---------------------------------- + + GPU_extensions_init(); + if(GPU_extensions_minimum_support()) { + int gameflag = (G.fileflags & G_FILE_GAME_MAT_GLSL); + + m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", gameflag) != 0); + } // create the canvas, rasterizer and rendertools m_canvas = new GPG_Canvas(window); @@ -655,6 +665,8 @@ bool GPG_Application::startEngine(void) // sceneconverter->SetAlwaysUseExpandFraming(true); if(m_blendermat) m_sceneconverter->SetMaterials(true); + if(m_blenderglslmat) + m_sceneconverter->SetGLSLMaterials(true); KX_Scene* startscene = new KX_Scene(m_keyboard, m_mouse, diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h index 024ca1dbf32..17f5add8b19 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h @@ -141,6 +141,7 @@ protected: SND_IAudioDevice* m_audiodevice; bool m_blendermat; + bool m_blenderglslmat; }; diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript index bd37777031e..70914451338 100644 --- a/source/gameengine/GamePlayer/ghost/SConscript +++ b/source/gameengine/GamePlayer/ghost/SConscript @@ -39,7 +39,8 @@ incs = ['.', '#source/gameengine/Network/LoopBackNetwork', '#source/gameengine/GamePlayer/common', '#source/blender/misc', - '#source/blender/blenloader'] + '#source/blender/blenloader', + '#source/blender/gpu'] incs += Split(env['BF_PYTHON_INC']) incs += Split(env['BF_SOLID_INC']) diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp new file mode 100644 index 00000000000..45e4ca17b1f --- /dev/null +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -0,0 +1,95 @@ + +#include "DNA_customdata_types.h" + +#include "BL_BlenderShader.h" + +#include "GPU_extensions.h" +#include "GPU_material.h" + +#include "RAS_MeshObject.h" +#include "RAS_IRasterizer.h" + +const bool BL_BlenderShader::Ok()const +{ + return (mGPUMat != 0); +} + +BL_BlenderShader::BL_BlenderShader(struct Material *ma) +: + mGPUMat(0), + mBound(false) +{ + if(ma) + mGPUMat = GPU_material_from_blender(ma, GPU_PROFILE_GAME); +} + +BL_BlenderShader::~BL_BlenderShader() +{ + if(mGPUMat) { + GPU_material_unbind(mGPUMat); + GPU_material_free(mGPUMat); + mGPUMat = 0; + } +} + +void BL_BlenderShader::ApplyShader() +{ +} + +void BL_BlenderShader::SetProg(bool enable) +{ + if(mGPUMat) { + if(enable) { + GPU_material_bind(mGPUMat); + mBound = true; + } + else { + GPU_material_unbind(mGPUMat); + mBound = false; + } + } +} + +void BL_BlenderShader::SetTexCoords(RAS_IRasterizer* ras) +{ + GPUVertexAttribs attribs; + int i; + + if(!mGPUMat) + return; + + GPU_material_vertex_attributes(mGPUMat, &attribs); + + for(i = 0; i < attribs.totlayer; i++) { + if(attribs.layer[i].type == CD_MTFACE) + ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_UV1, i); + else if(attribs.layer[i].type == CD_TANGENT) + ras->SetTexCoords(RAS_IRasterizer::RAS_TEXTANGENT, i); + else if(attribs.layer[i].type == CD_ORCO) + ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_ORCO, i); + else if(attribs.layer[i].type == CD_NORMAL) + ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_NORM, i); + else + ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_DISABLE, i); + } +} + +void BL_BlenderShader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty ) +{ + float obmat[4][4], viewmat[4][4]; + + if(!mGPUMat || !mBound) + return; + + MT_Matrix4x4 model; + model.setValue(ms.m_OpenGLMatrix); + MT_Matrix4x4 view; + rasty->GetViewMatrix(view); + + model.getValue((float*)obmat); + view.getValue((float*)viewmat); + + GPU_material_bind_uniforms(mGPUMat, obmat, viewmat); +} + +// eof diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h new file mode 100644 index 00000000000..95f2cfe044d --- /dev/null +++ b/source/gameengine/Ketsji/BL_BlenderShader.h @@ -0,0 +1,37 @@ + +#ifndef __BL_GPUSHADER_H__ +#define __BL_GPUSHADER_H__ + +#include "GPU_material.h" + +#include "MT_Matrix4x4.h" +#include "MT_Matrix3x3.h" +#include "MT_Tuple2.h" +#include "MT_Tuple3.h" +#include "MT_Tuple4.h" + +struct Material; + +/** + * BL_BlenderShader + * Blender GPU shader material + */ +class BL_BlenderShader +{ +private: + GPUMaterial *mGPUMat; + bool mBound; + +public: + BL_BlenderShader(struct Material *ma); + virtual ~BL_BlenderShader(); + + const bool Ok()const; + void SetProg(bool enable); + + void ApplyShader(); + void SetTexCoords(class RAS_IRasterizer* ras); + void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty); +}; + +#endif//__BL_GPUSHADER_H__ diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp index 7ed2da590a9..f5312ccd023 100644 --- a/source/gameengine/Ketsji/BL_Material.cpp +++ b/source/gameengine/Ketsji/BL_Material.cpp @@ -34,6 +34,7 @@ BL_Material::BL_Material() rgb[3] = 0; IdMode = 0; ras_mode = 0; + glslmat = 0; tile = 0; matname = "NoMaterial"; matcolor[0] = 0.5f; diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h index 8be91316237..d4c6db9f598 100644 --- a/source/gameengine/Ketsji/BL_Material.h +++ b/source/gameengine/Ketsji/BL_Material.h @@ -47,6 +47,7 @@ public: int IdMode; unsigned int ras_mode; + bool glslmat; STR_String texname[MAXTEX]; unsigned int flag[MAXTEX]; diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index a10b07ff491..3efa9b73f9d 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -57,6 +57,7 @@ SET(INC ../../../intern/SoundSystem ../../../source/blender/misc ../../../source/blender/blenloader + ../../../source/blender/gpu ../../../extern/bullet2/src ../../../extern/solid ${PYTHON_INC} diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 5efe1ad26ca..903db2592a7 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -81,6 +81,7 @@ KX_BlenderMaterial::KX_BlenderMaterial( ), mMaterial(data), mShader(0), + mBlenderShader(0), mScene(scene), mUserDefBlend(0), mModified(0), @@ -144,25 +145,30 @@ void KX_BlenderMaterial::OnConstruction() if (mConstructed) // when material are reused between objects return; - - // for each unique material... - int i; - for(i=0; i<mMaterial->num_enabled; i++) { - if( mMaterial->mapping[i].mapping & USEENV ) { - if(!RAS_EXT_support._ARB_texture_cube_map) { - spit("CubeMap textures not supported"); - continue; - } - if(!mTextures[i].InitCubeMap(i, mMaterial->cubemap[i] ) ) - spit("unable to initialize image("<<i<<") in "<< - mMaterial->matname<< ", image will not be available"); - } - else { - if( mMaterial->img[i] ) { - if( ! mTextures[i].InitFromImage(i, mMaterial->img[i], (mMaterial->flag[i] &MIPMAP)!=0 )) + if(mMaterial->glslmat) { + SetBlenderGLSLShader(); + } + else { + // for each unique material... + int i; + for(i=0; i<mMaterial->num_enabled; i++) { + if( mMaterial->mapping[i].mapping & USEENV ) { + if(!RAS_EXT_support._ARB_texture_cube_map) { + spit("CubeMap textures not supported"); + continue; + } + if(!mTextures[i].InitCubeMap(i, mMaterial->cubemap[i] ) ) spit("unable to initialize image("<<i<<") in "<< - mMaterial->matname<< ", image will not be available"); + mMaterial->matname<< ", image will not be available"); + } + + else { + if( mMaterial->img[i] ) { + if( ! mTextures[i].InitFromImage(i, mMaterial->img[i], (mMaterial->flag[i] &MIPMAP)!=0 )) + spit("unable to initialize image("<<i<<") in "<< + mMaterial->matname<< ", image will not be available"); + } } } } @@ -176,11 +182,17 @@ void KX_BlenderMaterial::OnExit() if( mShader ) { //note, the shader here is allocated, per unique material //and this function is called per face - mShader->SetProg(0); + mShader->SetProg(false); delete mShader; mShader = 0; } + if( mBlenderShader ) { + mBlenderShader->SetProg(false); + delete mBlenderShader; + mBlenderShader = 0; + } + BL_Texture::ActivateFirst(); for(int i=0; i<mMaterial->num_enabled; i++) { BL_Texture::ActivateUnit(i); @@ -229,6 +241,19 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) } } +void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras) +{ + if( !enable || !mBlenderShader->Ok() ) { + // frame cleanup. + mBlenderShader->SetProg(false); + BL_Texture::DisableAllTextures(); + return; + } + + BL_Texture::DisableAllTextures(); + mBlenderShader->SetProg(true); + mBlenderShader->ApplyShader(); +} void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) { @@ -330,6 +355,51 @@ KX_BlenderMaterial::ActivatShaders( } void +KX_BlenderMaterial::ActivateBlenderShaders( + RAS_IRasterizer* rasty, + TCachingInfo& cachingInfo)const +{ + KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this); + + // reset... + if(tmp->mMaterial->IsShared()) + cachingInfo =0; + + if (GetCachingInfo() != cachingInfo) { + if (!cachingInfo) + tmp->setBlenderShaderData(false, rasty); + + cachingInfo = GetCachingInfo(); + + if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) { + tmp->setBlenderShaderData(true, rasty); + rasty->EnableTextures(true); + } + else { + tmp->setBlenderShaderData(false, rasty); + rasty->EnableTextures(false); + } + + if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) + rasty->SetCullFace(false); + else + rasty->SetCullFace(true); + + if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES) + { + if((mMaterial->ras_mode &WIRE)!=0) + rasty->SetCullFace(false); + rasty->SetLines(true); + } + else + rasty->SetLines(false); + } + + ActivatGLMaterials(rasty); + mBlenderShader->SetTexCoords(rasty); +} + +void KX_BlenderMaterial::ActivateMat( RAS_IRasterizer* rasty, TCachingInfo& cachingInfo @@ -390,6 +460,18 @@ KX_BlenderMaterial::Activate( return dopass; } } + else if( RAS_EXT_support._ARB_shader_objects && ( mBlenderShader && mBlenderShader->Ok() ) ) { + if( (mPass++) == 0 ) { + ActivateBlenderShaders(rasty, cachingInfo); + dopass = true; + return dopass; + } + else { + mPass = 0; + dopass = false; + return dopass; + } + } else { switch (mPass++) { @@ -410,32 +492,37 @@ void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterize { if(mShader && RAS_EXT_support._ARB_shader_objects) mShader->Update(ms, rasty); + if(mBlenderShader && RAS_EXT_support._ARB_shader_objects) + mBlenderShader->Update(ms, rasty); } void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const { - rasty->SetSpecularity( - mMaterial->speccolor[0]*mMaterial->spec_f, - mMaterial->speccolor[1]*mMaterial->spec_f, - mMaterial->speccolor[2]*mMaterial->spec_f, - mMaterial->spec_f - ); + if(!mBlenderShader) { + rasty->SetSpecularity( + mMaterial->speccolor[0]*mMaterial->spec_f, + mMaterial->speccolor[1]*mMaterial->spec_f, + mMaterial->speccolor[2]*mMaterial->spec_f, + mMaterial->spec_f + ); - rasty->SetShinyness( mMaterial->hard ); + rasty->SetShinyness( mMaterial->hard ); - rasty->SetDiffuse( - mMaterial->matcolor[0]*mMaterial->ref+mMaterial->emit, - mMaterial->matcolor[1]*mMaterial->ref+mMaterial->emit, - mMaterial->matcolor[2]*mMaterial->ref+mMaterial->emit, - 1.0f); + rasty->SetDiffuse( + mMaterial->matcolor[0]*mMaterial->ref+mMaterial->emit, + mMaterial->matcolor[1]*mMaterial->ref+mMaterial->emit, + mMaterial->matcolor[2]*mMaterial->ref+mMaterial->emit, + 1.0f); - rasty->SetEmissive( - mMaterial->matcolor[0]*mMaterial->emit, - mMaterial->matcolor[1]*mMaterial->emit, - mMaterial->matcolor[2]*mMaterial->emit, - 1.0 ); + rasty->SetEmissive( + mMaterial->matcolor[0]*mMaterial->emit, + mMaterial->matcolor[1]*mMaterial->emit, + mMaterial->matcolor[2]*mMaterial->emit, + 1.0 ); + + rasty->SetAmbient(mMaterial->amb); + } - rasty->SetAmbient(mMaterial->amb); if (mMaterial->material) rasty->SetPolygonOffset(-mMaterial->material->zoffs, 0.0); } @@ -730,6 +817,17 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") } +void KX_BlenderMaterial::SetBlenderGLSLShader(void) +{ + if(!mBlenderShader) + mBlenderShader = new BL_BlenderShader(mMaterial->material); + + if(!mBlenderShader->Ok()) { + delete mBlenderShader; + mBlenderShader = 0; + } +} + KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()") { return PyInt_FromLong( mMaterial->material_index ); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index b9d48199520..62e96b71937 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -8,6 +8,7 @@ #include "BL_Material.h" #include "BL_Texture.h" #include "BL_Shader.h" +#include "BL_BlenderShader.h" #include "PyObjectPlus.h" @@ -60,6 +61,10 @@ public: TCachingInfo& cachingInfo )const; + void ActivateBlenderShaders( + RAS_IRasterizer* rasty, + TCachingInfo& cachingInfo + )const; MTFace* GetMTFace(void) const; unsigned int* GetMCol(void) const; @@ -86,8 +91,9 @@ public: // pre calculate to avoid pops/lag at startup virtual void OnConstruction( ); private: - BL_Material* mMaterial; - BL_Shader* mShader; + BL_Material* mMaterial; + BL_Shader* mShader; + BL_BlenderShader* mBlenderShader; KX_Scene* mScene; BL_Texture mTextures[MAXTEX]; // texture array bool mUserDefBlend; @@ -95,12 +101,15 @@ private: bool mModified; bool mConstructed; // if false, don't clean on exit + void SetBlenderGLSLShader(); + void ActivatGLMaterials( RAS_IRasterizer* rasty )const; void ActivateTexGen( RAS_IRasterizer *ras ) const; // message centers void setTexData( bool enable,RAS_IRasterizer *ras); + void setBlenderShaderData( bool enable, RAS_IRasterizer *ras); void setShaderData( bool enable, RAS_IRasterizer *ras); bool setDefaultBlending(); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index c192cd01261..05155f7f55d 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -81,8 +81,8 @@ KX_GameObject::KX_GameObject( m_bVisible(true), m_pPhysicsController1(NULL), m_pPhysicsEnvironment(NULL), - m_isDeformable(false), - m_pHitObject(NULL) + m_pHitObject(NULL), + m_isDeformable(false) { m_ignore_activity_culling = false; m_pClient_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR); diff --git a/source/gameengine/Ketsji/KX_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h index bba289bf891..f069048cd3d 100644 --- a/source/gameengine/Ketsji/KX_ISceneConverter.h +++ b/source/gameengine/Ketsji/KX_ISceneConverter.h @@ -74,6 +74,9 @@ public: virtual void SetMaterials(bool val) =0; virtual bool GetMaterials()=0; + // use blender glsl materials + virtual void SetGLSLMaterials(bool val) =0; + virtual bool GetGLSLMaterials()=0; }; #endif //__KX_ISCENECONVERTER_H diff --git a/source/gameengine/Ketsji/Makefile b/source/gameengine/Ketsji/Makefile index e6e541d0931..75d1bb6d714 100644 --- a/source/gameengine/Ketsji/Makefile +++ b/source/gameengine/Ketsji/Makefile @@ -60,6 +60,7 @@ CPPFLAGS += -I../../blender/blenlib CPPFLAGS += -I../../blender/include CPPFLAGS += -I../../blender/makesdna CPPFLAGS += -I../../blender/imbuf +CPPFLAGS += -I../../blender/gpu CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include ifeq ($(WITH_BF_GLEXT),true) diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index c7c80345796..c91e4a34ee4 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -18,7 +18,7 @@ incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common #sourc incs += ' #source/gameengine/Physics/BlOde #source/gameengine/Physics/Dummy' incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include' incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' -incs += ' #source/blender/misc #source/blender/blenloader' +incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu' cflags = [] if env['OURPLATFORM'] == 'win32-vc': diff --git a/source/gameengine/Rasterizer/RAS_CameraData.h b/source/gameengine/Rasterizer/RAS_CameraData.h index 6aa9b34962b..0327a3f4763 100644 --- a/source/gameengine/Rasterizer/RAS_CameraData.h +++ b/source/gameengine/Rasterizer/RAS_CameraData.h @@ -49,12 +49,12 @@ struct RAS_CameraData m_clipstart(clipstart), m_clipend(clipend), m_perspective(perspective), - m_focallength(focallength), m_viewport(viewport), m_viewportleft(viewportleft), m_viewportbottom(viewportbottom), m_viewportright(viewportright), - m_viewporttop(viewporttop) + m_viewporttop(viewporttop), + m_focallength(focallength) { } }; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 96ce220ae4d..01d44245826 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -177,7 +177,6 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I bool dolights = false; const unsigned int flag = m_material->GetFlag(); - if( flag & RAS_BLENDERMAT) dolights = (flag &RAS_MULTILIGHT)!=0; else @@ -316,14 +315,14 @@ void RAS_MaterialBucket::Render(const MT_Transform& cameratrans, //rasty->SetMaterial(*m_material); - int drawmode; for (T_MeshSlotList::const_iterator it = m_meshSlots.begin(); ! (it == m_meshSlots.end()); ++it) { rendertools->SetClientObject((*it).m_clientObj); - while (ActivateMaterial(cameratrans, rasty, rendertools, drawmode)) + while (ActivateMaterial(cameratrans, rasty, rendertools, drawmode)) { RenderMeshSlot(cameratrans, rasty, rendertools, *it, drawmode); + } } // to reset the eventual GL_CW mode rendertools->SetClientObject(NULL); diff --git a/source/gameengine/Rasterizer/SConscript b/source/gameengine/Rasterizer/SConscript index ff79a5d97b8..f077833b850 100644 --- a/source/gameengine/Rasterizer/SConscript +++ b/source/gameengine/Rasterizer/SConscript @@ -7,7 +7,7 @@ if env['WITH_BF_GLEXT'] == 1: env['CPPFLAGS'].append('-DWITH_GLEXT') -incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/BlenderRoutines' +incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/BlenderRoutines #extern/glew/include' if env['OURPLATFORM']=='win32-vc': cflags = [] |