2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/BL_Material.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
2006-01-06 03:46:54 +00:00
|
|
|
// ------------------------------------
|
|
|
|
#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;
|
|
|
|
|
2007-01-21 04:45:44 +00:00
|
|
|
if(!(index >=0 && index < MAX_MTEX) ) return 0;
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
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()
|
2009-04-29 10:06:38 +00:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BL_Material::Initialize()
|
2006-01-06 03:46:54 +00:00
|
|
|
{
|
|
|
|
rgb[0] = 0;
|
|
|
|
rgb[1] = 0;
|
|
|
|
rgb[2] = 0;
|
|
|
|
rgb[3] = 0;
|
|
|
|
IdMode = 0;
|
|
|
|
ras_mode = 0;
|
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
|
|
|
glslmat = 0;
|
2006-01-06 03:46:54 +00:00
|
|
|
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;
|
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
|
|
|
alphablend = 0;
|
2006-01-06 03:46:54 +00:00
|
|
|
hard = 50.f;
|
|
|
|
spec_f = 0.5f;
|
|
|
|
alpha = 1.f;
|
|
|
|
emit = 0.f;
|
|
|
|
material = 0;
|
|
|
|
tface = 0;
|
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in
the game engine with the following limitations:
- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported:
armature, curve, lattice. You can still use these modifiers
(armature is really not recommended) but in non parent mode.
The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
stack).
- Modifiers are statically evaluated: any possible time dependency
in the modifiers is not supported (don't know enough about
modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
due to shape action or armature action. Beware that this is
very CPU intensive; modifiers should really be used for static
objects only.
- Physics is still based on the original mesh: if you have a
mirror modifier, the physic shape will be limited to one half
of the resulting object. Therefore, the modifiers should
preferably be used on graphic objects.
- Scripts have no access to the modified mesh.
- Modifiers that are based on objects interaction (boolean,..)
will not be dependent on the objects position in the GE.
What you see in the 3D view is what you get in the GE regardless
on the object position, velocity, etc.
Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh,
VideoTexture, add object, dupligroup.
Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw
functions to display the object. This drawing method is a
bit slow and is not 100% compatible with the BGE. There may
be some problems in multi-texture mode: the multi-texture
coordinates are not sent to the GPU.
Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh.
If you have a modifer that extends the size of the mesh,
the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
The derived mesh is allocated and computed for each object
with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.
MSVC, scons, Cmake, makefile updated.
Enjoy
/benoit
2009-04-21 11:01:09 +00:00
|
|
|
materialindex = 0;
|
2006-01-06 03:46:54 +00:00
|
|
|
amb=0.5f;
|
|
|
|
num_enabled = 0;
|
2006-02-13 05:45:32 +00:00
|
|
|
num_users = 1;
|
|
|
|
share = false;
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i=0; i<4; i++)
|
2007-01-07 04:39:39 +00:00
|
|
|
{
|
2006-01-06 03:46:54 +00:00
|
|
|
uv[i] = MT_Point2(0.f,1.f);
|
2007-01-07 04:39:39 +00:00
|
|
|
uv2[i] = MT_Point2(0.f, 1.f);
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) {
|
|
|
|
uvName = name;
|
2006-01-06 03:46:54 +00:00
|
|
|
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];
|
|
|
|
}
|
2008-07-10 12:47:20 +00:00
|
|
|
void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) {
|
|
|
|
uv2Name = name;
|
2007-01-07 04:39:39 +00:00
|
|
|
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];
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
|
2006-02-13 05:45:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|