blender/source/gameengine/Ketsji/BL_Material.cpp
Dalai Felinto b263aefb0e TexFace to Material Settings big patch
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/
2011-09-19 19:55:59 +00:00

163 lines
2.9 KiB
C++

/** \file gameengine/Ketsji/BL_Material.cpp
* \ingroup ketsji
*/
// ------------------------------------
#include "BL_Material.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_image_types.h"
#include "DNA_mesh_types.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
MTex* getImageFromMaterial(Material *mat, int index)
{
if(!mat) return 0;
if(!(index >=0 && index < MAX_MTEX) ) return 0;
MTex *m = mat->mtex[index];
return m?m:0;
}
int getNumTexChannels( Material *mat )
{
int count = -1;
if(!mat) return -1;
for(count =0; (count < 10) && mat->mtex[count] != 0; count++) {}
return count;
}
BL_Material::BL_Material()
{
Initialize();
}
void BL_Material::Initialize()
{
rgb[0] = 0;
rgb[1] = 0;
rgb[2] = 0;
rgb[3] = 0;
IdMode = 0;
ras_mode = 0;
glslmat = 0;
tile = 0;
matname = "NoMaterial";
matcolor[0] = 0.5f;
matcolor[1] = 0.5f;
matcolor[2] = 0.5f;
matcolor[3] = 0.5f;
speccolor[0] = 1.f;
speccolor[1] = 1.f;
speccolor[2] = 1.f;
alphablend = 0;
hard = 50.f;
spec_f = 0.5f;
alpha = 1.f;
emit = 0.f;
material = 0;
tface = 0;
materialindex = 0;
amb=0.5f;
num_enabled = 0;
num_users = 1;
share = false;
int i;
for(i=0; i<4; i++)
{
uv[i] = MT_Point2(0.f,1.f);
uv2[i] = MT_Point2(0.f, 1.f);
}
for(i=0; i<MAXTEX; i++) // :(
{
mapping[i].mapping = 0;
mapping[i].offsets[0] = 0.f;
mapping[i].offsets[1] = 0.f;
mapping[i].offsets[2] = 0.f;
mapping[i].scale[0] = 1.f;
mapping[i].scale[1] = 1.f;
mapping[i].scale[2] = 1.f;
mapping[i].projplane[0] = PROJX;
mapping[i].projplane[1] = PROJY;
mapping[i].projplane[2] = PROJZ;
mapping[i].objconame = "";
mtexname[i] = "NULL";
imageId[i]="NULL";
flag[i] = 0;
texname[i] = "NULL";
tilexrep[i] = 1;
tileyrep[i] = 1;
color_blend[i] = 1.f;
blend_mode[i] = 0;
img[i] = 0;
cubemap[i] = 0;
}
}
void BL_Material::SetConversionRGB(unsigned int *nrgb) {
rgb[0]=*nrgb++;
rgb[1]=*nrgb++;
rgb[2]=*nrgb++;
rgb[3]=*nrgb;
}
void BL_Material::GetConversionRGB(unsigned int *nrgb) {
*nrgb++ = rgb[0];
*nrgb++ = rgb[1];
*nrgb++ = rgb[2];
*nrgb = rgb[3];
}
void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) {
uvName = name;
uv[0] = *nuv++;
uv[1] = *nuv++;
uv[2] = *nuv++;
uv[3] = *nuv;
}
void BL_Material::GetConversionUV(MT_Point2 *nuv){
*nuv++ = uv[0];
*nuv++ = uv[1];
*nuv++ = uv[2];
*nuv = uv[3];
}
void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) {
uv2Name = name;
uv2[0] = *nuv++;
uv2[1] = *nuv++;
uv2[2] = *nuv++;
uv2[3] = *nuv;
}
void BL_Material::GetConversionUV2(MT_Point2 *nuv){
*nuv++ = uv2[0];
*nuv++ = uv2[1];
*nuv++ = uv2[2];
*nuv = uv2[3];
}
void BL_Material::SetSharedMaterial(bool v)
{
if((v && num_users == -1) || num_users > 1 )
share = true;
else
share = false;
}
bool BL_Material::IsShared()
{
return share;
}
void BL_Material::SetUsers(int num)
{
num_users = num;
}