From b263aefb0ec4d6b46b4cd7e4b15ac7f99af4c59e Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Mon, 19 Sep 2011 19:55:59 +0000 Subject: TexFace to Material Settings big patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: ======== The idea here is to move the texface options into the material panel. For images with the change please visit: http://code.blender.org/index.php/2011/09/bge-material-texface-changes 1 - Some of the legacy problems 2.49 and 2.5x has with the texface system: ========================================================================== 1.1) Shadow, Bilboard and Halo are mutual exclusive (in the code), yet you can select a face to be more than one mode. 1.2) Sort only works for blend Alpha yet it's an option regardless of the Transparency Blend you pick. 1.3) Shared doesn't affect anything in BGE. 1.4) ObColor only works for Text objects (old bitmap texts) when using Texture Face Materials. (not address yet, I so far ignored obcolor) 2 - Notes: ============ 2.1) Now "Use Face Textures" in material Option panel will work in Multitexture even if there is no texture channel. 2.2) In FaceTexture mode it will use TexFace all the time, even if you don't check the "Use Texture Face" option in the UI. It's a matter of decision, since the code for either way is there. I decided by the solution that makes the creation of a material fast - in this mode the user doesn't need to mess with textures or this "Use Texture Face" option at all. I'm not strong in my opinion here. But I think if we don't have this then what is the point of the Texture Face mode? 2.3) I kept references for tface only when we need the image, UV or the tiling setting. It should help later when/if we split the Image and UV layers from the tface struct (Campbell and Brecht proposal). 3 - Changes in a Nutshell: ========================== 3.1) "Texture Face" panel (in the Mesh/Object Data panel) no longer exists. Those settings are all part of the material properties, visible when Game Render is set. 3.2) "Texture Face" Shading mode (in the Render panel) is now called “Single Texture”, it needs a material for special settings (e.g. Billboard, Alpha Sort, …). 3.3) New options in the Material Panel * Shadeless option in the Material panel is now supported for all three Shading modes. * Physics is now toggleable, this is the old Collision option. * Two Side (on) is now called Back Culling (off). * Alpha Sort is one of the Alpha options, together (and mutually exclusive) to Alpha Blend, Alpha Clip, Add and Opaque (i.e. solid). * Shadow, Billboard and Halo are grouped in the “Face Orientation” property. * "Face Textures" and "Face Textures Alpha" (under Options) can be used for all but GLSL shading mode (to be supported in GLSL eventually). * The backend in the game engine is still the same as before. The only changes are in the interface and in the way you need to think your materials. The bottomline is: It’s no longer possible to share materials between faces that do not share the same game properties. 4 - Acknowledgment: ================== Mike Pan for the design discussions, and testing along the whole development process. Vitor Balbio for the first hands-on code with the interface changes. That helped me a lot to push me into work on that. Benoit Bolsee and Brecht van Lommel for patch review (* no one reviewed the whole patch, or the latest iteractions, so I still hold liability for any problems). Blender artists that gave feedback and helped testing the patch. Patch review and original documentation can be found here: http://wiki.blender.org/index.php/User:Dfelinto/TexFace http://codereview.appspot.com/4289041/ --- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'source/gameengine/Ketsji/KX_BlenderMaterial.cpp') 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; inum_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); } } -- cgit v1.2.3