blender/source/gameengine/Ketsji/BL_Material.cpp

161 lines
2.8 KiB
C++
Raw Normal View History

// ------------------------------------
#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;
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;
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;
transp = 0;
hard = 50.f;
spec_f = 0.5f;
alpha = 1.f;
emit = 0.f;
mode = 0;
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;
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;
}