diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-09-20 16:01:16 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-09-20 16:01:16 +0400 |
commit | 7172316b945c62797e6beba953ff203766614531 (patch) | |
tree | 640ac56fadded9c7686399b5a1f1c64f1a135700 /source/gameengine | |
parent | 2015eefef70350382931881dd65ed2da09f8f2cd (diff) | |
parent | 78d4260144dbf01166fac8bc9303e6d5aa022f71 (diff) |
Merging r40366 through r40392 from trunk into soc-2011-garlicsoc-2011-garlic
Diffstat (limited to 'source/gameengine')
14 files changed, 260 insertions, 195 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index d4b43cd7ac1..2c2fd052b5d 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -144,6 +144,8 @@ extern "C" { #include "BKE_cdderivedmesh.h" #include "BKE_DerivedMesh.h" #include "BKE_material.h" /* give_current_material */ +#include "BKE_image.h" +#include "IMB_imbuf_types.h" extern Material defmaterial; /* material.c */ } @@ -195,7 +197,7 @@ extern "C" { } #endif -static int default_face_mode = TF_DYNAMIC; +static bool default_light_mode = 0; static unsigned int KX_rgbaint2uint_new(unsigned int icol) { @@ -234,9 +236,9 @@ static unsigned int KX_Mcol2uint_new(MCol col) return out_color.integer; } -static void SetDefaultFaceType(Scene* scene) +static void SetDefaultLightMode(Scene* scene) { - default_face_mode = TF_DYNAMIC; + default_light_mode = false; Scene *sce_iter; Base *base; @@ -244,7 +246,7 @@ static void SetDefaultFaceType(Scene* scene) { if (base->object->type == OB_LAMP) { - default_face_mode = TF_DYNAMIC|TF_LIGHT; + default_light_mode = true; return; } } @@ -353,41 +355,41 @@ bool ConvertMaterial( // use lighting? material->ras_mode |= ( mat->mode & MA_SHLESS )?0:USE_LIGHT; + material->ras_mode |= ( mat->game.flag & GEMAT_BACKCULL )?0:TWOSIDED; + // cast shadows? material->ras_mode |= ( mat->mode & MA_SHADBUF )?CAST_SHADOW:0; MTex *mttmp = 0; numchan = getNumTexChannels(mat); int valid_index = 0; - // use the face texture if - // 1) it is set in the buttons - // 2) we have a face texture and a material but no valid texture in slot 1 + /* In Multitexture use the face texture if and only if + * it is set in the buttons + * In GLSL is not working yet :/ 3.2011 */ bool facetex = false; if(validface && mat->mode &MA_FACETEXTURE) facetex = true; - if(validface && !mat->mtex[0]) - facetex = true; - if(validface && mat->mtex[0]) { - MTex *tmp = mat->mtex[0]; - if(!tmp->tex || (tmp->tex && !tmp->tex->ima)) - facetex = true; - } + numchan = numchan>MAXTEX?MAXTEX:numchan; + if (facetex && numchan == 0) numchan = 1; // foreach MTex for(int i=0; i<numchan; i++) { // use face tex if(i==0 && facetex ) { + facetex = false; Image*tmp = (Image*)(tface->tpage); if(tmp) { material->img[i] = tmp; material->texname[i] = material->img[i]->id.name; - material->flag[i] |= ( tface->transp &TF_ALPHA )?USEALPHA:0; - material->flag[i] |= ( tface->transp &TF_ADD )?CALCALPHA:0; material->flag[i] |= MIPMAP; + material->flag[i] |= ( mat->game.alpha_blend & GEMAT_ALPHA_SORT )?USEALPHA:0; + material->flag[i] |= ( mat->game.alpha_blend & GEMAT_ALPHA )?USEALPHA:0; + material->flag[i] |= ( mat->game.alpha_blend & GEMAT_ADD )?CALCALPHA:0; + if(material->img[i]->flag & IMA_REFLECT) material->mapping[i].mapping |= USEREFL; else @@ -405,11 +407,6 @@ bool ConvertMaterial( material->mapping[i].mapping |= USEUV; } - if(material->ras_mode & USE_LIGHT) - material->ras_mode &= ~USE_LIGHT; - if(tface->mode & TF_LIGHT) - material->ras_mode |= USE_LIGHT; - valid_index++; } else { @@ -567,25 +564,31 @@ bool ConvertMaterial( material->ras_mode |= (mat->material_type == MA_TYPE_WIRE)? WIRE: 0; } - else { + else { // No Material int valid = 0; // check for tface tex to fallback on if( validface ){ - - // no light bugfix - if(tface->mode) material->ras_mode |= USE_LIGHT; - material->img[0] = (Image*)(tface->tpage); // ------------------------ if(material->img[0]) { material->texname[0] = material->img[0]->id.name; material->mapping[0].mapping |= ( (material->img[0]->flag & IMA_REFLECT)!=0 )?USEREFL:0; - material->flag[0] |= ( tface->transp &TF_ALPHA )?USEALPHA:0; - material->flag[0] |= ( tface->transp &TF_ADD )?CALCALPHA:0; + + /* see if depth of the image is 32bits */ + if(BKE_image_has_alpha(material->img[0])) { + material->flag[0] |= USEALPHA; + material->alphablend = GEMAT_ALPHA; + } + else + material->alphablend = GEMAT_SOLID; + valid++; } } + else + material->alphablend = GEMAT_SOLID; + material->SetUsers(-1); material->num_enabled = valid; material->IdMode = TEXFACE; @@ -598,6 +601,9 @@ bool ConvertMaterial( material->matcolor[2] = 0.5f; material->spec_f = 0.5f; material->ref = 0.8f; + + // No material - old default TexFace properties + material->ras_mode |= USE_LIGHT; } MT_Point2 uv[4]; MT_Point2 uv2[4]; @@ -606,13 +612,10 @@ bool ConvertMaterial( uv2[0]= uv2[1]= uv2[2]= uv2[3]= MT_Point2(0.0f, 0.0f); + /* No material, what to do? let's see what is in the UV and set the material accordingly + light and visible is always on */ if( validface ) { - - material->ras_mode |= (tface->mode & TF_INVISIBLE)?0:POLY_VIS; - - material->transp = tface->transp; material->tile = tface->tile; - material->mode = tface->mode; uv[0].setValue(tface->uv[0]); uv[1].setValue(tface->uv[1]); @@ -625,31 +628,26 @@ bool ConvertMaterial( } else { // nothing at all - material->ras_mode |= (POLY_VIS| (validmat?0:USE_LIGHT)); - material->mode = default_face_mode; - material->transp = TF_SOLID; + material->alphablend = GEMAT_SOLID; material->tile = 0; uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f); } + if (validmat && validface) { + material->alphablend = mat->game.alpha_blend; + } + // with ztransp enabled, enforce alpha blending mode - if(validmat && (mat->mode & MA_TRANSP) && (mat->mode & MA_ZTRANSP) && (material->transp == TF_SOLID)) - material->transp = TF_ALPHA; + if(validmat && (mat->mode & MA_TRANSP) && (mat->mode & MA_ZTRANSP) && (material->alphablend == GEMAT_SOLID)) + material->alphablend = GEMAT_ALPHA; // always zsort alpha + add - if((material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha) && (material->transp != TF_CLIP)) { + if((ELEM3(material->alphablend, GEMAT_ALPHA, GEMAT_ALPHA_SORT, GEMAT_ADD) || texalpha) && (material->alphablend != GEMAT_CLIP )) { material->ras_mode |= ALPHA; - material->ras_mode |= (material->mode & TF_ALPHASORT)? ZSORT: 0; + material->ras_mode |= (mat && (mat->game.alpha_blend & GEMAT_ALPHA_SORT))? ZSORT: 0; } - // collider or not? - material->ras_mode |= (material->mode & TF_DYNAMIC)? COLLIDER: 0; - - // these flags are irrelevant at this point, remove so they - // don't hurt material bucketing - material->mode &= ~(TF_DYNAMIC|TF_ALPHASORT|TF_TEX); - // get uv sets if(validmat) { @@ -706,8 +704,8 @@ bool ConvertMaterial( unsigned int rgb[4]; GetRGB(type,mface,mmcol,mat,rgb[0],rgb[1],rgb[2], rgb[3]); - // swap the material color, so MCol on TF_BMFONT works - if (validmat && type==1 && (tface && tface->mode & TF_BMFONT)) + // swap the material color, so MCol on bitmap font works + if (validmat && type==1 && (mat->game.flag & GEMAT_TEXT)) { rgb[0] = KX_rgbaint2uint_new(rgb[0]); rgb[1] = KX_rgbaint2uint_new(rgb[1]); @@ -864,10 +862,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol, layers, converter->GetGLSLMaterials()); - visible = ((bl_mat->ras_mode & POLY_VIS)!=0); - collider = ((bl_mat->ras_mode & COLLIDER)!=0); - twoside = ((bl_mat->mode & TF_TWOSIDE)!=0); - /* vertex colors and uv's were stored in bl_mat temporarily */ bl_mat->GetConversionRGB(rgb); rgb0 = rgb[0]; rgb1 = rgb[1]; @@ -885,7 +879,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, if (kx_blmat == NULL) kx_blmat = new KX_BlenderMaterial(); - kx_blmat->Initialize(scene, bl_mat); + kx_blmat->Initialize(scene, bl_mat, (ma?&ma->game:NULL)); polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat); } else { @@ -893,37 +887,59 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, Image* bima = (tface)? (Image*)tface->tpage: NULL; imastr = (tface)? (bima? (bima)->id.name : "" ) : ""; - char transp=0; - short mode=0, tile=0; + char alpha_blend=0; + short tile=0; int tilexrep=4,tileyrep = 4; - + + /* set material properties - old TexFace */ + if (ma) { + alpha_blend = ma->game.alpha_blend; + /* Commented out for now. If we ever get rid of + * "Texture Face/Singletexture" we can then think about it */ + + /* Texture Face mode ignores texture but requires "Face Textures to be True "*/ + /** + if ((ma->mode &MA_FACETEXTURE)==0 && (ma->game.flag &GEMAT_TEXT)==0) { + bima = NULL; + imastr = ""; + alpha_blend = GEMAT_SOLID; + } + else + alpha_blend = ma->game.alpha_blend; + */ + } + /* check for tface tex to fallback on */ + else { + if (bima) { + /* see if depth of the image is 32 */ + if (BKE_image_has_alpha(bima)) + alpha_blend = GEMAT_ALPHA; + else + alpha_blend = GEMAT_SOLID; + } + else { + alpha_blend = GEMAT_SOLID; + } + } + if (bima) { tilexrep = bima->xrep; tileyrep = bima->yrep; } - /* get tface properties if available */ + /* set UV properties */ if(tface) { - /* TF_DYNAMIC means the polygon is a collision face */ - collider = ((tface->mode & TF_DYNAMIC) != 0); - transp = tface->transp; - tile = tface->tile; - mode = tface->mode; - - visible = !(tface->mode & TF_INVISIBLE); - twoside = ((tface->mode & TF_TWOSIDE)!=0); - uv0.setValue(tface->uv[0]); uv1.setValue(tface->uv[1]); uv2.setValue(tface->uv[2]); if (mface->v4) uv3.setValue(tface->uv[3]); + + tile = tface->tile; } else { - /* no texfaces, set COLLSION true and everything else FALSE */ - mode = default_face_mode; - transp = TF_SOLID; + /* no texfaces */ tile = 0; } @@ -964,16 +980,20 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, if (mface->v4) rgb3 = KX_rgbaint2uint_new(color); } - + // only zsort alpha + add - bool alpha = (transp == TF_ALPHA || transp == TF_ADD); - bool zsort = (mode & TF_ALPHASORT)? alpha: 0; + bool alpha = ELEM3(alpha_blend, GEMAT_ALPHA, GEMAT_ADD, GEMAT_ALPHA_SORT); + bool zsort = (alpha_blend == GEMAT_ALPHA_SORT); + bool light = (ma)?(ma->mode & MA_SHLESS)==0:default_light_mode; + + // don't need zort anymore, deal as if it it's alpha blend + if (alpha_blend == GEMAT_ALPHA_SORT) alpha_blend = GEMAT_ALPHA; if (kx_polymat == NULL) kx_polymat = new KX_PolygonMaterial(); kx_polymat->Initialize(imastr, ma, (int)mface->mat_nr, tile, tilexrep, tileyrep, - mode, transp, alpha, zsort, lightlayer, tface, (unsigned int*)mcol); + alpha_blend, alpha, zsort, light, lightlayer, tface, (unsigned int*)mcol); polymat = static_cast<RAS_IPolyMaterial*>(kx_polymat); if (ma) { @@ -987,6 +1007,19 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, } } + // set render flags + if (ma) + { + visible = ((ma->game.flag & GEMAT_INVISIBLE)==0); + twoside = ((ma->game.flag & GEMAT_BACKCULL)==0); + collider = ((ma->game.flag & GEMAT_NOPHYSICS)==0); + } + else{ + visible = true; + twoside = false; + collider = true; + } + /* mark face as flat, so vertices are split */ bool flat = (mface->flag & ME_SMOOTH) == 0; @@ -2035,7 +2068,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, logicmgr->RegisterActionName(curAct->id.name + 2, curAct); } - SetDefaultFaceType(blenderscene); + SetDefaultLightMode(blenderscene); // Let's support scene set. // Beware of name conflict in linked data, it will not crash but will create confusion // in Python scripting and in certain actuators (replace mesh). Linked scene *should* have diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp index 4ae937cdcd6..6680e9556b9 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.cpp +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -27,7 +27,7 @@ BL_BlenderShader::BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lig mGPUMat(NULL) { mBlenderScene = scene->GetBlenderScene(); - mBlendMode = GPU_BLEND_SOLID; + mAlphaBlend = GPU_BLEND_SOLID; ReloadMaterial(); } @@ -148,12 +148,12 @@ void BL_BlenderShader::Update(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty ) GPU_material_bind_uniforms(gpumat, obmat, viewmat, viewinvmat, obcol); - mBlendMode = GPU_material_blend_mode(gpumat, obcol); + mAlphaBlend = GPU_material_alpha_blend(gpumat, obcol); } -int BL_BlenderShader::GetBlendMode() +int BL_BlenderShader::GetAlphaBlend() { - return mBlendMode; + return mAlphaBlend; } bool BL_BlenderShader::Equals(BL_BlenderShader *blshader) diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h index 2f22e121b8c..f187d93d648 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.h +++ b/source/gameengine/Ketsji/BL_BlenderShader.h @@ -63,7 +63,7 @@ private: struct Scene *mBlenderScene; struct Material *mMat; int mLightLayer; - int mBlendMode; + int mAlphaBlend; GPUMaterial *mGPUMat; bool VerifyShader() @@ -86,7 +86,7 @@ public: void SetAttribs(class RAS_IRasterizer* ras, const BL_Material *mat); void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty); void ReloadMaterial(); - int GetBlendMode(); + int GetAlphaBlend(); void SetScene(KX_Scene *scene) { diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp index 25fd5467e93..fd0756d067d 100644 --- a/source/gameengine/Ketsji/BL_Material.cpp +++ b/source/gameengine/Ketsji/BL_Material.cpp @@ -52,12 +52,11 @@ void BL_Material::Initialize() speccolor[0] = 1.f; speccolor[1] = 1.f; speccolor[2] = 1.f; - transp = 0; + alphablend = 0; hard = 50.f; spec_f = 0.5f; alpha = 1.f; emit = 0.f; - mode = 0; material = 0; tface = 0; materialindex = 0; diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h index c0440e66501..2c6316ea32b 100644 --- a/source/gameengine/Ketsji/BL_Material.h +++ b/source/gameengine/Ketsji/BL_Material.h @@ -68,7 +68,7 @@ public: float matcolor[4]; float speccolor[3]; - short transp, pad; + short alphablend, pad; float hard, spec_f; float alpha, emit, color_blend[MAXTEX], ref; @@ -76,7 +76,6 @@ public: int blend_mode[MAXTEX]; - int mode; int num_enabled; BL_Mapping mapping[MAXTEX]; @@ -151,14 +150,16 @@ enum BL_flag // BL_Material::ras_mode enum BL_ras_mode { - POLY_VIS=1, + // POLY_VIS=1, COLLIDER=2, ZSORT=4, ALPHA=8, // TRIANGLE=16, USE_LIGHT=32, WIRE=64, - CAST_SHADOW=128 + CAST_SHADOW=128, + TEX=256, + TWOSIDED=512 }; // ------------------------------------- diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 33da17cc505..1a1e046f54c 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -34,6 +34,8 @@ #include "DNA_meshdata_types.h" #include "BKE_mesh.h" // ------------------------------------ +#include "BLI_utildefines.h" + #define spit(x) std::cout << x << std::endl; BL_Shader *KX_BlenderMaterial::mLastShader = NULL; @@ -56,21 +58,24 @@ KX_BlenderMaterial::KX_BlenderMaterial() } void KX_BlenderMaterial::Initialize( - KX_Scene *scene, - BL_Material *data) + KX_Scene *scene, + BL_Material *data, + GameSettings *game) { RAS_IPolyMaterial::Initialize( - data->texname[0], - data->matname, - data->materialindex, - data->tile, - data->tilexrep[0], - data->tileyrep[0], - data->mode, - data->transp, - ((data->ras_mode &ALPHA)!=0), - ((data->ras_mode &ZSORT)!=0) - ); + data->texname[0], + data->matname, + data->materialindex, + data->tile, + data->tilexrep[0], + data->tileyrep[0], + data->alphablend, + ((data->ras_mode &ALPHA)!=0), + ((data->ras_mode &ZSORT)!=0), + ((data->ras_mode &USE_LIGHT)!=0), + ((data->ras_mode &TEX)), + game + ); mMaterial = data; mShader = 0; mBlenderShader = 0; @@ -99,7 +104,7 @@ void KX_BlenderMaterial::Initialize( for(int i=0; i<mMaterial->num_enabled; i++) { m_multimode += (mMaterial->flag[i] + mMaterial->blend_mode[i]); } - m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(COLLIDER|USE_LIGHT)); + m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(USE_LIGHT)); } KX_BlenderMaterial::~KX_BlenderMaterial() @@ -231,7 +236,7 @@ void KX_BlenderMaterial::OnExit() } if( mMaterial->tface ) - GPU_set_tpage(mMaterial->tface, 1); + GPU_set_tpage(mMaterial->tface, 1, mMaterial->alphablend); } @@ -247,7 +252,7 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) mLastShader = NULL; } - ras->SetBlendingMode(TF_SOLID); + ras->SetAlphaBlend(TF_SOLID); BL_Texture::DisableAllTextures(); return; } @@ -268,11 +273,11 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - ras->SetBlendingMode(mMaterial->transp); + ras->SetAlphaBlend(mMaterial->alphablend); } else { - ras->SetBlendingMode(TF_SOLID); - ras->SetBlendingMode(-1); // indicates custom mode + ras->SetAlphaBlend(TF_SOLID); + ras->SetAlphaBlend(-1); // indicates custom mode // tested to be valid enums glEnable(GL_BLEND); @@ -283,7 +288,7 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras) { if( !enable || !mBlenderShader->Ok() ) { - ras->SetBlendingMode(TF_SOLID); + ras->SetAlphaBlend(TF_SOLID); // frame cleanup. if(mLastBlenderShader) { @@ -297,7 +302,7 @@ void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras } if(!mBlenderShader->Equals(mLastBlenderShader)) { - ras->SetBlendingMode(mMaterial->transp); + ras->SetAlphaBlend(mMaterial->alphablend); if(mLastBlenderShader) mLastBlenderShader->SetProg(false); @@ -314,14 +319,14 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) BL_Texture::DisableAllTextures(); if( !enable ) { - ras->SetBlendingMode(TF_SOLID); + ras->SetAlphaBlend(TF_SOLID); return; } BL_Texture::ActivateFirst(); if( mMaterial->IdMode == DEFAULT_BLENDER ) { - ras->SetBlendingMode(mMaterial->transp); + ras->SetAlphaBlend(mMaterial->alphablend); return; } @@ -331,7 +336,7 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) mTextures[0].ActivateTexture(); mTextures[0].setTexEnv(0, true); mTextures[0].SetMapping(mMaterial->mapping[0].mapping); - ras->SetBlendingMode(mMaterial->transp); + ras->SetAlphaBlend(mMaterial->alphablend); } return; } @@ -354,11 +359,11 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - ras->SetBlendingMode(mMaterial->transp); + ras->SetAlphaBlend(mMaterial->alphablend); } else { - ras->SetBlendingMode(TF_SOLID); - ras->SetBlendingMode(-1); // indicates custom mode + ras->SetAlphaBlend(TF_SOLID); + ras->SetAlphaBlend(-1); // indicates custom mode glEnable(GL_BLEND); glBlendFunc(mBlendFunc[0], mBlendFunc[1]); @@ -393,15 +398,15 @@ KX_BlenderMaterial::ActivatShaders( else tmp->setShaderData(false, rasty); - if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) + if (mMaterial->ras_mode &TWOSIDED) rasty->SetCullFace(false); else rasty->SetCullFace(true); - if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + if ((mMaterial->ras_mode &WIRE) || (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) { - if((mMaterial->ras_mode &WIRE)!=0) + if (mMaterial->ras_mode &WIRE) rasty->SetCullFace(false); rasty->SetLines(true); } @@ -438,15 +443,15 @@ KX_BlenderMaterial::ActivateBlenderShaders( else tmp->setBlenderShaderData(false, rasty); - if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) + if (mMaterial->ras_mode &TWOSIDED) rasty->SetCullFace(false); else rasty->SetCullFace(true); - if (((mMaterial->ras_mode & WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + if ((mMaterial->ras_mode &WIRE) || (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) { - if((mMaterial->ras_mode &WIRE)!=0) + if (mMaterial->ras_mode &WIRE) rasty->SetCullFace(false); rasty->SetLines(true); } @@ -487,15 +492,15 @@ KX_BlenderMaterial::ActivateMat( else tmp->setTexData( false,rasty); - if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) + if (mMaterial->ras_mode &TWOSIDED) rasty->SetCullFace(false); else rasty->SetCullFace(true); - if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + if ((mMaterial->ras_mode &WIRE) || (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) { - if((mMaterial->ras_mode &WIRE)!=0) + if (mMaterial->ras_mode &WIRE) rasty->SetCullFace(false); rasty->SetLines(true); } @@ -570,17 +575,17 @@ void KX_BlenderMaterial::ActivateMeshSlot(const RAS_MeshSlot & ms, RAS_IRasteriz mShader->Update(ms, rasty); } else if(mBlenderShader && GLEW_ARB_shader_objects) { - int blendmode; + int alphablend; mBlenderShader->Update(ms, rasty); /* we do blend modes here, because they can change per object * with the same material due to obcolor/obalpha */ - blendmode = mBlenderShader->GetBlendMode(); - if((blendmode == TF_SOLID || blendmode == TF_ALPHA) && mMaterial->transp != TF_SOLID) - blendmode = mMaterial->transp; + alphablend = mBlenderShader->GetAlphaBlend(); + if(ELEM3(alphablend, GEMAT_SOLID, GEMAT_ALPHA, GEMAT_ALPHA_SORT) && mMaterial->alphablend != GEMAT_SOLID) + alphablend = mMaterial->alphablend; - rasty->SetBlendingMode(blendmode); + rasty->SetAlphaBlend(alphablend); } } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 766e20be825..236bd6afdc8 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -38,7 +38,8 @@ public: KX_BlenderMaterial(); void Initialize( class KX_Scene* scene, - BL_Material* mat + BL_Material* mat, + GameSettings* game ); virtual ~KX_BlenderMaterial(); diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index d32f267f0e0..098c136bfa3 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -78,10 +78,10 @@ void KX_PolygonMaterial::Initialize( int tile, int tilexrep, int tileyrep, - int mode, - int transp, + int alphablend, bool alpha, bool zsort, + bool light, int lightlayer, struct MTFace* tface, unsigned int* mcol) @@ -93,10 +93,12 @@ void KX_PolygonMaterial::Initialize( tile, tilexrep, tileyrep, - mode, - transp, + alphablend, alpha, - zsort); + zsort, + light, + (texname && texname != ""?true:false), /* if we have a texture we have image */ + ma?&ma->game:NULL); m_tface = tface; m_mcol = mcol; m_material = ma; @@ -168,7 +170,7 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c if (GetCachingInfo() != cachingInfo) { if (!cachingInfo) - GPU_set_tpage(NULL, 0); + GPU_set_tpage(NULL, 0, 0); cachingInfo = GetCachingInfo(); @@ -176,15 +178,15 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c { Image *ima = (Image*)m_tface->tpage; GPU_update_image_time(ima, rasty->GetTime()); - GPU_set_tpage(m_tface, 1); + GPU_set_tpage(m_tface, 1, m_alphablend); } else - GPU_set_tpage(NULL, 0); + GPU_set_tpage(NULL, 0, 0); - if(m_drawingmode & RAS_IRasterizer::KX_TWOSIDE) - rasty->SetCullFace(false); - else + if(m_drawingmode & RAS_IRasterizer::KX_BACKCULL) rasty->SetCullFace(true); + else + rasty->SetCullFace(false); if ((m_drawingmode & RAS_IRasterizer::KX_LINES) || (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) @@ -318,7 +320,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)") if (PyArg_ParseTuple(args, "O!:setTexture", &PyCapsule_Type, &pytface)) { MTFace *tface = (MTFace*) PyCapsule_GetPointer(pytface, KX_POLYGONMATERIAL_CAPSULE_ID); - GPU_set_tpage(tface, 1); + GPU_set_tpage(tface, 1, m_alphablend); Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index 3520995def3..b09ddd39141 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -78,10 +78,10 @@ public: int tile, int tilexrep, int tileyrep, - int mode, - int transp, + int alphablend, bool alpha, bool zsort, + bool light, int lightlayer, struct MTFace* tface, unsigned int* mcol); diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index 5a1b52489b4..9948f48d7f3 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -36,6 +36,7 @@ #include "DNA_image_types.h" #include "DNA_meshdata_types.h" +#include "DNA_material_types.h" void RAS_IPolyMaterial::Initialize( const STR_String& texname, @@ -44,10 +45,12 @@ void RAS_IPolyMaterial::Initialize( int tile, int tilexrep, int tileyrep, - int mode, - int transp, + int alphablend, bool alpha, - bool zsort) + bool zsort, + bool light, + bool image, + struct GameSettings* game) { m_texturename = texname; m_materialname = matname; @@ -55,10 +58,10 @@ void RAS_IPolyMaterial::Initialize( m_tile = tile; m_tilexrep = tilexrep; m_tileyrep = tileyrep; - m_drawingmode = mode; - m_transp = transp; + m_alphablend = alphablend; m_alpha = alpha; m_zsort = zsort; + m_light = light; m_polymatid = m_newpolymatid++; m_flag = 0; m_multimode = 0; @@ -66,6 +69,7 @@ void RAS_IPolyMaterial::Initialize( m_specular.setValue(0.5,0.5,0.5); m_specularity = 1.0; m_diffuse.setValue(0.5,0.5,0.5); + m_drawingmode = ConvertFaceMode(game, image); } RAS_IPolyMaterial::RAS_IPolyMaterial() @@ -75,9 +79,10 @@ RAS_IPolyMaterial::RAS_IPolyMaterial() m_tilexrep(0), m_tileyrep(0), m_drawingmode (0), - m_transp(0), + m_alphablend(0), m_alpha(false), m_zsort(false), + m_light(false), m_materialindex(0), m_polymatid(0), m_flag(0), @@ -95,8 +100,7 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, int tile, int tilexrep, int tileyrep, - int mode, - int transp, + int alphablend, bool alpha, bool zsort) : m_texturename(texname), @@ -104,8 +108,7 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, m_tile(tile), m_tilexrep(tilexrep), m_tileyrep(tileyrep), - m_drawingmode (mode), - m_transp(transp), + m_alphablend(alphablend), m_alpha(alpha), m_zsort(zsort), m_materialindex(materialindex), @@ -128,9 +131,9 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const this->m_multimode == lhs.m_multimode && this->m_flag == lhs.m_flag && this->m_drawingmode == lhs.m_drawingmode && - this->m_transp == lhs.m_transp && - this->m_texturename.hash() == lhs.m_texturename.hash() && - this->m_materialname.hash() == lhs.m_materialname.hash() + this->m_alphablend == lhs.m_alphablend && + this->m_texturename.hash() == lhs.m_texturename.hash() && + this->m_materialname.hash() == lhs.m_materialname.hash() ); return test; @@ -141,9 +144,10 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const this->m_tile == lhs.m_tile && this->m_tilexrep == lhs.m_tilexrep && this->m_tileyrep == lhs.m_tileyrep && - this->m_transp == lhs.m_transp && + this->m_alphablend == lhs.m_alphablend && this->m_alpha == lhs.m_alpha && this->m_zsort == lhs.m_zsort && + this->m_light == lhs.m_light && this->m_drawingmode == lhs.m_drawingmode && this->m_texturename.hash() == lhs.m_texturename.hash() && this->m_materialname.hash() == lhs.m_materialname.hash() @@ -151,6 +155,21 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const } } +int RAS_IPolyMaterial::ConvertFaceMode(struct GameSettings *game, bool image) const +{ + if (!game) return (image?GEMAT_TEX:0); + + int modefinal = 0; + + int orimode = game->face_orientation; + int alpha_blend = game->alpha_blend; + int flags = game->flag & (GEMAT_TEXT | GEMAT_BACKCULL); + + modefinal = orimode | alpha_blend | flags; + modefinal |= (image ? GEMAT_TEX : 0); + + return modefinal; +} void RAS_IPolyMaterial::GetMaterialRGBAColor(unsigned char *rgba) const { @@ -241,7 +260,7 @@ bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID); else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW); else - dolights = (m_drawingmode & RAS_IRasterizer::KX_LIGHT)!=0; + dolights = m_light; return dolights; } diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index 2a5c6a179b6..69d07713c49 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -49,6 +49,7 @@ struct Material; struct Image; struct Scene; class SCA_IScene; +struct GameSettings; enum MaterialProps { @@ -78,10 +79,11 @@ protected: STR_HashedString m_materialname; //also needed for touchsensor int m_tile; int m_tilexrep,m_tileyrep; - int m_drawingmode; // tface->mode - int m_transp; + int m_drawingmode; + int m_alphablend; bool m_alpha; bool m_zsort; + bool m_light; int m_materialindex; unsigned int m_polymatid; @@ -102,9 +104,9 @@ public: // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc. enum MaterialFlags { - BILLBOARD_SCREENALIGNED = 256, - BILLBOARD_AXISALIGNED = 4096, - SHADOW =8192 + BILLBOARD_SCREENALIGNED = 512, /* GEMAT_HALO */ + BILLBOARD_AXISALIGNED = 1024, /* GEMAT_BILLBOARD */ + SHADOW =2048 /* GEMAT_SHADOW */ }; RAS_IPolyMaterial(); @@ -114,7 +116,6 @@ public: int tile, int tilexrep, int tileyrep, - int mode, int transp, bool alpha, bool zsort); @@ -124,10 +125,13 @@ public: int tile, int tilexrep, int tileyrep, - int mode, int transp, bool alpha, - bool zsort); + bool zsort, + bool light, + bool image, + struct GameSettings* game); + virtual ~RAS_IPolyMaterial() {}; /** @@ -174,6 +178,11 @@ public: virtual void Replace_IScene(SCA_IScene *val) {}; /* overridden by KX_BlenderMaterial */ + /** + * @return the equivalent drawing mode for the material settings (equivalent to old TexFace tface->mode). + */ + int ConvertFaceMode(struct GameSettings *game, bool image) const; + /* * PreCalculate texture gen */ diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 877a7219a1c..2988aa4effb 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -68,11 +68,7 @@ class RAS_IRasterizer public: RAS_IRasterizer(RAS_ICanvas* canv){}; virtual ~RAS_IRasterizer(){}; - /** - */ - enum { - RAS_RENDER_3DPOLYGON_TEXT = 16384 /* TF_BMFONT */ - }; + /** * Drawing types */ @@ -106,9 +102,9 @@ public: /** */ enum { - KX_TEX = 4, /* TF_TEX */ - KX_LIGHT = 16, /* TF_LIGHT */ - KX_TWOSIDE = 512, /* TF_TWOSIDE */ + RAS_RENDER_3DPOLYGON_TEXT = 64, /* GEMAT_TEXT */ + KX_BACKCULL = 16, /* GEMAT_BACKCULL */ + KX_TEX = 4096, /* GEMAT_TEX */ KX_LINES = 32768 }; @@ -417,7 +413,7 @@ public: virtual int GetMotionBlurState()=0; virtual void SetMotionBlurState(int newstate)=0; - virtual void SetBlendingMode(int blendmode)=0; + virtual void SetAlphaBlend(int alphablend)=0; virtual void SetFrontFace(bool ccw)=0; virtual void SetAnisotropicFiltering(short level)=0; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 6ad9e591474..d9039a2a68d 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -89,7 +89,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) m_motionblurvalue(-1.0), m_texco_num(0), m_attrib_num(0), - //m_last_blendmode(GPU_BLEND_SOLID), + //m_last_alphablend(GPU_BLEND_SOLID), m_last_frontface(true), m_materialCachingInfo(0) { @@ -126,8 +126,8 @@ bool RAS_OpenGLRasterizer::Init() glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); - //m_last_blendmode = GPU_BLEND_SOLID; - GPU_set_material_blend_mode(GPU_BLEND_SOLID); + //m_last_alphablend = GPU_BLEND_SOLID; + GPU_set_material_alpha_blend(GPU_BLEND_SOLID); glFrontFace(GL_CCW); m_last_frontface = true; @@ -303,8 +303,8 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time) glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); - //m_last_blendmode = GPU_BLEND_SOLID; - GPU_set_material_blend_mode(GPU_BLEND_SOLID); + //m_last_alphablend = GPU_BLEND_SOLID; + GPU_set_material_alpha_blend(GPU_BLEND_SOLID); glFrontFace(GL_CCW); m_last_frontface = true; @@ -873,10 +873,10 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) // MCol *mcol = (MCol*)ms.m_pDerivedMesh->getFaceDataArray(ms.m_pDerivedMesh, CD_MCOL); /* UNUSED */ // handle two-side - if (current_polymat->GetDrawingMode() & RAS_IRasterizer::KX_TWOSIDE) - this->SetCullFace(false); - else + if (current_polymat->GetDrawingMode() & RAS_IRasterizer::KX_BACKCULL) this->SetCullFace(true); + else + this->SetCullFace(false); if (current_polymat->GetFlag() & RAS_BLENDERGLSL) { // GetMaterialIndex return the original mface material index, @@ -890,9 +890,9 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) else memset(¤t_gpu_attribs, 0, sizeof(current_gpu_attribs)); // DM draw can mess up blending mode, restore at the end - int current_blend_mode = GPU_get_material_blend_mode(); + int current_blend_mode = GPU_get_material_alpha_blend(); ms.m_pDerivedMesh->drawFacesGLSL(ms.m_pDerivedMesh, CheckMaterialDM); - GPU_set_material_blend_mode(current_blend_mode); + GPU_set_material_alpha_blend(current_blend_mode); } else { //ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol); current_blmat_nr = current_polymat->GetMaterialIndex(); @@ -1204,36 +1204,36 @@ void RAS_OpenGLRasterizer::DisableMotionBlur() m_motionblurvalue = -1.0; } -void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode) +void RAS_OpenGLRasterizer::SetAlphaBlend(int alphablend) { - GPU_set_material_blend_mode(blendmode); + GPU_set_material_alpha_blend(alphablend); /* - if(blendmode == m_last_blendmode) + if(alphablend == m_last_alphablend) return; - if(blendmode == GPU_BLEND_SOLID) { + if(alphablend == GPU_BLEND_SOLID) { glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - else if(blendmode == GPU_BLEND_ADD) { + else if(alphablend == GPU_BLEND_ADD) { glBlendFunc(GL_ONE, GL_ONE); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); } - else if(blendmode == GPU_BLEND_ALPHA) { + else if(alphablend == GPU_BLEND_ALPHA) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); } - else if(blendmode == GPU_BLEND_CLIP) { + else if(alphablend == GPU_BLEND_CLIP) { glDisable(GL_BLEND); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); } - m_last_blendmode = blendmode; + m_last_alphablend = alphablend; */ } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index c0e02f6df77..cbfa49510a5 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -111,7 +111,7 @@ protected: TexCoGen m_attrib[RAS_MAX_ATTRIB]; int m_texco_num; int m_attrib_num; - //int m_last_blendmode; + //int m_last_alphablend; bool m_last_frontface; /** Stores the caching information for the last material activated. */ @@ -312,7 +312,7 @@ public: m_motionblur = newstate; }; - virtual void SetBlendingMode(int blendmode); + virtual void SetAlphaBlend(int alphablend); virtual void SetFrontFace(bool ccw); virtual void SetAnisotropicFiltering(short level); |