2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* material.c
|
|
|
|
*
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
* about this.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_meta_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
|
|
#include "BKE_bad_level_calls.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_displist.h"
|
|
|
|
#include "BKE_material.h"
|
|
|
|
|
2003-11-23 14:28:46 +00:00
|
|
|
#include "BPY_extern.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
void free_material(Material *ma)
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
MTex *mtex;
|
|
|
|
|
|
|
|
BPY_free_scriptlink(&ma->scriptlink);
|
|
|
|
|
2004-12-04 21:49:02 +00:00
|
|
|
for(a=0; a<MAX_MTEX; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
mtex= ma->mtex[a];
|
|
|
|
if(mtex && mtex->tex) mtex->tex->id.us--;
|
|
|
|
if(mtex) MEM_freeN(mtex);
|
|
|
|
}
|
2004-06-30 18:54:09 +00:00
|
|
|
|
|
|
|
if(ma->ramp_col) MEM_freeN(ma->ramp_col);
|
|
|
|
if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_material(Material *ma)
|
|
|
|
{
|
|
|
|
ma->lay= 1;
|
2003-07-19 20:31:29 +00:00
|
|
|
ma->r= ma->g= ma->b= ma->ref= 0.8;
|
|
|
|
ma->specr= ma->specg= ma->specb= 1.0;
|
|
|
|
ma->mirr= ma->mirg= ma->mirb= 1.0;
|
2003-12-16 14:12:01 +00:00
|
|
|
ma->spectra= 1.0;
|
2003-07-19 20:31:29 +00:00
|
|
|
ma->amb= 0.5;
|
|
|
|
ma->alpha= 1.0;
|
|
|
|
ma->spec= ma->hasize= 0.5;
|
2002-10-12 11:37:38 +00:00
|
|
|
ma->har= 50;
|
|
|
|
ma->starc= ma->ringc= 4;
|
|
|
|
ma->linec= 12;
|
|
|
|
ma->flarec= 1;
|
2003-07-19 20:31:29 +00:00
|
|
|
ma->flaresize= ma->subsize= 1.0;
|
2003-10-11 22:00:30 +00:00
|
|
|
ma->flareboost= 1;
|
|
|
|
ma->seed2= 6;
|
2003-07-19 20:31:29 +00:00
|
|
|
ma->friction= 0.5;
|
|
|
|
ma->refrac= 4.0;
|
|
|
|
ma->roughness= 0.5;
|
|
|
|
ma->param[0]= 0.5;
|
|
|
|
ma->param[1]= 0.1;
|
|
|
|
ma->param[2]= 0.5;
|
|
|
|
ma->param[3]= 0.1;
|
2005-04-17 17:43:07 +00:00
|
|
|
ma->rms=0.1;
|
|
|
|
ma->darkness=1.0;
|
2003-07-19 20:31:29 +00:00
|
|
|
|
2003-12-16 14:12:01 +00:00
|
|
|
ma->ang= 1.0;
|
|
|
|
ma->ray_depth= 2;
|
|
|
|
ma->ray_depth_tra= 2;
|
2003-12-23 22:31:48 +00:00
|
|
|
ma->fresnel_mir= 0.0;
|
|
|
|
ma->fresnel_tra= 0.0;
|
|
|
|
ma->fresnel_tra_i= 1.25;
|
|
|
|
ma->fresnel_mir_i= 1.25;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-06-30 18:54:09 +00:00
|
|
|
ma->rampfac_col= 1.0;
|
|
|
|
ma->rampfac_spec= 1.0;
|
|
|
|
ma->pr_lamp= 3; // two lamps, is bits
|
|
|
|
|
So, for the platform managers to check:
- the link order for Blender has changed, the libradiosity.a has to be moved after the librender.a (obviously for a new dependency!). Check blender/source/Makefile
- there's a new file: blender/source/radiosity/intern/source/radrender.c
Here's what the new code does:
Using the core routines of the Radiosity tool, each renderface with 'emit material' and each renderface with 'radio material flag' set will be used to itterate to a global illumination solution. Per face with high energy (emit) little images are rendered (hemicubes) which makes up lookup tables to 'shoot' its energy to other faces.
In the end this energy - color - then is directly added to the pixel colors while rendering, Gouraud shaded.
Since it's done with renderfaces, it works for all primitives in Blender.
What is doesn't do yet:
- take into account textured color of faces. Currently it uses the material RGB color for filtering distributed energy.
- do some smart pre-subdividing. I don't know yet if this is useful... Right now it means that you'll have to balance the models yourself, to deliver small faces where you want a high accuracy for shadowing.
- unified render (is at my todo list)
User notes:
- per Material you want to have included in radiosity render: set the 'radio' flag. For newly added Materials it is ON by default now.
- the Ambient slider in Material controls the amount of radiosity color.
- for enabling radiosity rendering, set the F10 "Radio" button.
- the Radiosity buttons now only show the relevant radiosity rendering options. Pressing "collect meshes" will show all buttons again.
- for meshes, the faces who use Radio material always call the 'autosmooth' routine, this to make sure sharp angles (like corners in a room) do not have shared vertices. For some smooth models (like the raptor example) you might increase the standard smoothing angle from 30 to 45 degree.
Technical notes:
- I had to expand the renderface and rendervertices for it... shame on me! Faces have one pointer extra, render vertices four floats...
- The size of the hemicubes is now based at the boundbox of the entire scene (0.002 of it). This should be more reliable... to be done
- I fixed a bug in radiosity render, where sometimes backfaces where lit
In general:
I'd like everyone to play a bit with this system. It's not easy to get good results with it. A simple "hit and go" isn't there... maybe some good suggestions?
2003-08-31 20:33:46 +00:00
|
|
|
ma->mode= MA_TRACEBLE+MA_SHADOW+MA_RADIO;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Material *add_material(char *name)
|
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
|
|
|
ma= alloc_libblock(&G.main->mat, ID_MA, name);
|
|
|
|
|
|
|
|
init_material(ma);
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *copy_material(Material *ma)
|
|
|
|
{
|
|
|
|
Material *man;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
man= copy_libblock(ma);
|
|
|
|
|
|
|
|
id_us_plus((ID *)man->ipo);
|
|
|
|
|
2004-12-04 21:49:02 +00:00
|
|
|
for(a=0; a<MAX_MTEX; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ma->mtex[a]) {
|
|
|
|
man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
|
|
|
|
memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
|
|
|
|
id_us_plus((ID *)man->mtex[a]->tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BPY_copy_scriptlink(&ma->scriptlink);
|
2004-06-30 18:54:09 +00:00
|
|
|
if(ma->ramp_col) man->ramp_col= MEM_dupallocN(ma->ramp_col);
|
|
|
|
if(ma->ramp_spec) man->ramp_spec= MEM_dupallocN(ma->ramp_spec);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return man;
|
|
|
|
}
|
|
|
|
|
|
|
|
void make_local_material(Material *ma)
|
|
|
|
{
|
|
|
|
Object *ob;
|
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
Material *man;
|
|
|
|
int a, local=0, lib=0;
|
2003-04-26 11:56:44 +00:00
|
|
|
|
|
|
|
/* - only lib users: do nothing
|
|
|
|
* - only local users: set flag
|
|
|
|
* - mixed: make copy
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if(ma->id.lib==0) return;
|
|
|
|
if(ma->id.us==1) {
|
|
|
|
ma->id.lib= 0;
|
|
|
|
ma->id.flag= LIB_LOCAL;
|
|
|
|
new_id(0, (ID *)ma, 0);
|
2004-12-04 21:49:02 +00:00
|
|
|
for(a=0; a<MAX_MTEX; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test objects */
|
|
|
|
ob= G.main->object.first;
|
|
|
|
while(ob) {
|
|
|
|
if(ob->mat) {
|
|
|
|
for(a=0; a<ob->totcol; a++) {
|
|
|
|
if(ob->mat[a]==ma) {
|
|
|
|
if(ob->id.lib) lib= 1;
|
|
|
|
else local= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ob= ob->id.next;
|
|
|
|
}
|
|
|
|
/* test meshes */
|
|
|
|
me= G.main->mesh.first;
|
|
|
|
while(me) {
|
|
|
|
if(me->mat) {
|
|
|
|
for(a=0; a<me->totcol; a++) {
|
|
|
|
if(me->mat[a]==ma) {
|
|
|
|
if(me->id.lib) lib= 1;
|
|
|
|
else local= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me= me->id.next;
|
|
|
|
}
|
|
|
|
/* test curves */
|
|
|
|
cu= G.main->curve.first;
|
|
|
|
while(cu) {
|
|
|
|
if(cu->mat) {
|
|
|
|
for(a=0; a<cu->totcol; a++) {
|
|
|
|
if(cu->mat[a]==ma) {
|
|
|
|
if(cu->id.lib) lib= 1;
|
|
|
|
else local= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cu= cu->id.next;
|
|
|
|
}
|
|
|
|
/* test mballs */
|
|
|
|
mb= G.main->mball.first;
|
|
|
|
while(mb) {
|
|
|
|
if(mb->mat) {
|
|
|
|
for(a=0; a<mb->totcol; a++) {
|
|
|
|
if(mb->mat[a]==ma) {
|
|
|
|
if(mb->id.lib) lib= 1;
|
|
|
|
else local= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mb= mb->id.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(local && lib==0) {
|
|
|
|
ma->id.lib= 0;
|
|
|
|
ma->id.flag= LIB_LOCAL;
|
|
|
|
|
2004-12-04 21:49:02 +00:00
|
|
|
for(a=0; a<MAX_MTEX; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_id(0, (ID *)ma, 0);
|
|
|
|
}
|
|
|
|
else if(local && lib) {
|
|
|
|
man= copy_material(ma);
|
|
|
|
man->id.us= 0;
|
|
|
|
|
|
|
|
/* do objects */
|
|
|
|
ob= G.main->object.first;
|
|
|
|
while(ob) {
|
|
|
|
if(ob->mat) {
|
|
|
|
for(a=0; a<ob->totcol; a++) {
|
|
|
|
if(ob->mat[a]==ma) {
|
|
|
|
if(ob->id.lib==0) {
|
|
|
|
ob->mat[a]= man;
|
|
|
|
man->id.us++;
|
|
|
|
ma->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ob= ob->id.next;
|
|
|
|
}
|
|
|
|
/* do meshes */
|
|
|
|
me= G.main->mesh.first;
|
|
|
|
while(me) {
|
|
|
|
if(me->mat) {
|
|
|
|
for(a=0; a<me->totcol; a++) {
|
|
|
|
if(me->mat[a]==ma) {
|
|
|
|
if(me->id.lib==0) {
|
|
|
|
me->mat[a]= man;
|
|
|
|
man->id.us++;
|
|
|
|
ma->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me= me->id.next;
|
|
|
|
}
|
|
|
|
/* do curves */
|
|
|
|
cu= G.main->curve.first;
|
|
|
|
while(cu) {
|
|
|
|
if(cu->mat) {
|
|
|
|
for(a=0; a<cu->totcol; a++) {
|
|
|
|
if(cu->mat[a]==ma) {
|
|
|
|
if(cu->id.lib==0) {
|
|
|
|
cu->mat[a]= man;
|
|
|
|
man->id.us++;
|
|
|
|
ma->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cu= cu->id.next;
|
|
|
|
}
|
|
|
|
/* do mballs */
|
|
|
|
mb= G.main->mball.first;
|
|
|
|
while(mb) {
|
|
|
|
if(mb->mat) {
|
|
|
|
for(a=0; a<mb->totcol; a++) {
|
|
|
|
if(mb->mat[a]==ma) {
|
|
|
|
if(mb->id.lib==0) {
|
|
|
|
mb->mat[a]= man;
|
|
|
|
man->id.us++;
|
|
|
|
ma->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mb= mb->id.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Material ***give_matarar(Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
|
|
|
|
if(ob->type==OB_MESH) {
|
|
|
|
me= ob->data;
|
|
|
|
return &(me->mat);
|
|
|
|
}
|
|
|
|
else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
|
|
|
|
cu= ob->data;
|
|
|
|
return &(cu->mat);
|
|
|
|
}
|
|
|
|
else if(ob->type==OB_MBALL) {
|
|
|
|
mb= ob->data;
|
|
|
|
return &(mb->mat);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
short *give_totcolp(Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
|
|
|
|
if(ob->type==OB_MESH) {
|
|
|
|
me= ob->data;
|
|
|
|
return &(me->totcol);
|
|
|
|
}
|
|
|
|
else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
|
|
|
|
cu= ob->data;
|
|
|
|
return &(cu->totcol);
|
|
|
|
}
|
|
|
|
else if(ob->type==OB_MBALL) {
|
|
|
|
mb= ob->data;
|
|
|
|
return &(mb->totcol);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *give_current_material(Object *ob, int act)
|
|
|
|
{
|
|
|
|
Material ***matarar, *ma;
|
|
|
|
|
|
|
|
if(ob==0) return 0;
|
|
|
|
if(ob->totcol==0) return 0;
|
|
|
|
|
|
|
|
if(act>ob->totcol) act= ob->totcol;
|
|
|
|
else if(act==0) act= 1;
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
if( BTST(ob->colbits, act-1) ) { /* in object */
|
2002-10-12 11:37:38 +00:00
|
|
|
ma= ob->mat[act-1];
|
|
|
|
}
|
2003-04-26 11:56:44 +00:00
|
|
|
else { /* in data */
|
2002-10-12 11:37:38 +00:00
|
|
|
matarar= give_matarar(ob);
|
|
|
|
|
|
|
|
if(matarar && *matarar) ma= (*matarar)[act-1];
|
|
|
|
else ma= 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID *material_from(Object *ob, int act)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(ob==0) return 0;
|
|
|
|
|
|
|
|
if(ob->totcol==0) return ob->data;
|
|
|
|
if(act==0) act= 1;
|
|
|
|
|
|
|
|
if( BTST(ob->colbits, act-1) ) return (ID *)ob;
|
|
|
|
else return ob->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GS reads the memory pointed at in a specific ordering. There are,
|
|
|
|
* however two definitions for it. I have jotted them down here, both,
|
|
|
|
* but I think the first one is actually used. The thing is that
|
|
|
|
* big-endian systems might read this the wrong way round. OTOH, we
|
|
|
|
* constructed the IDs that are read out with this macro explicitly as
|
|
|
|
* well. I expect we'll sort it out soon... */
|
|
|
|
|
|
|
|
/* from blendef: */
|
|
|
|
#define GS(a) (*((short *)(a)))
|
|
|
|
|
|
|
|
/* from misc_util: flip the bytes from x */
|
|
|
|
/* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
|
|
|
|
|
|
|
|
void test_object_materials(ID *id)
|
|
|
|
{
|
2003-04-26 11:56:44 +00:00
|
|
|
/* make the ob mat-array same size as 'ob->data' mat-array */
|
2002-10-12 11:37:38 +00:00
|
|
|
Object *ob;
|
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
Material **newmatar;
|
|
|
|
int totcol=0;
|
|
|
|
|
|
|
|
if(id==0) return;
|
|
|
|
|
|
|
|
if( GS(id->name)==ID_ME ) {
|
|
|
|
me= (Mesh *)id;
|
|
|
|
totcol= me->totcol;
|
|
|
|
}
|
|
|
|
else if( GS(id->name)==ID_CU ) {
|
|
|
|
cu= (Curve *)id;
|
|
|
|
totcol= cu->totcol;
|
|
|
|
}
|
|
|
|
else if( GS(id->name)==ID_MB ) {
|
|
|
|
mb= (MetaBall *)id;
|
|
|
|
totcol= mb->totcol;
|
|
|
|
}
|
|
|
|
else return;
|
|
|
|
|
|
|
|
ob= G.main->object.first;
|
|
|
|
while(ob) {
|
|
|
|
|
|
|
|
if(ob->data==id) {
|
|
|
|
|
|
|
|
if(totcol==0) {
|
|
|
|
if(ob->totcol) {
|
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
ob->mat= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(ob->totcol<totcol) {
|
|
|
|
newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar");
|
|
|
|
if(ob->totcol) {
|
|
|
|
memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol);
|
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
}
|
|
|
|
ob->mat= newmatar;
|
|
|
|
}
|
|
|
|
ob->totcol= totcol;
|
|
|
|
if(ob->totcol && ob->actcol==0) ob->actcol= 1;
|
|
|
|
if(ob->actcol>ob->totcol) ob->actcol= ob->totcol;
|
|
|
|
}
|
|
|
|
ob= ob->id.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void assign_material(Object *ob, Material *ma, int act)
|
|
|
|
{
|
|
|
|
Material *mao, **matar, ***matarar;
|
|
|
|
short *totcolp;
|
|
|
|
|
|
|
|
if(act>MAXMAT) return;
|
|
|
|
if(act<1) act= 1;
|
|
|
|
|
|
|
|
/* test arraylens */
|
|
|
|
|
|
|
|
totcolp= give_totcolp(ob);
|
|
|
|
matarar= give_matarar(ob);
|
|
|
|
|
|
|
|
if(totcolp==0 || matarar==0) return;
|
|
|
|
|
|
|
|
if( act > *totcolp) {
|
|
|
|
matar= MEM_callocN(sizeof(void *)*act, "matarray1");
|
|
|
|
if( *totcolp) {
|
|
|
|
memcpy(matar, *matarar, sizeof(void *)*( *totcolp ));
|
|
|
|
MEM_freeN(*matarar);
|
|
|
|
}
|
|
|
|
*matarar= matar;
|
|
|
|
*totcolp= act;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(act > ob->totcol) {
|
|
|
|
matar= MEM_callocN(sizeof(void *)*act, "matarray2");
|
|
|
|
if( ob->totcol) {
|
|
|
|
memcpy(matar, ob->mat, sizeof(void *)*( ob->totcol ));
|
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
}
|
|
|
|
ob->mat= matar;
|
|
|
|
ob->totcol= act;
|
|
|
|
}
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* do it */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
if( BTST(ob->colbits, act-1) ) { /* in object */
|
2002-10-12 11:37:38 +00:00
|
|
|
mao= ob->mat[act-1];
|
|
|
|
if(mao) mao->id.us--;
|
|
|
|
ob->mat[act-1]= ma;
|
|
|
|
}
|
2003-04-26 11:56:44 +00:00
|
|
|
else { /* in data */
|
2002-10-12 11:37:38 +00:00
|
|
|
mao= (*matarar)[act-1];
|
|
|
|
if(mao) mao->id.us--;
|
|
|
|
(*matarar)[act-1]= ma;
|
|
|
|
}
|
|
|
|
id_us_plus((ID *)ma);
|
|
|
|
test_object_materials(ob->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void new_material_to_objectdata(Object *ob)
|
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
|
|
|
if(ob==0) return;
|
|
|
|
if(ob->totcol>=MAXMAT) return;
|
|
|
|
|
|
|
|
ma= give_current_material(ob, ob->actcol);
|
|
|
|
if(ma==0) {
|
|
|
|
ma= add_material("Material");
|
|
|
|
ma->id.us= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ob->actcol) {
|
|
|
|
if( BTST(ob->colbits, ob->actcol-1) ) {
|
|
|
|
ob->colbits= BSET(ob->colbits, ob->totcol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assign_material(ob, ma, ob->totcol+1);
|
|
|
|
ob->actcol= ob->totcol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init_render_material(Material *ma)
|
|
|
|
{
|
|
|
|
MTex *mtex;
|
|
|
|
int a, needuv=0;
|
|
|
|
|
|
|
|
if(ma->flarec==0) ma->flarec= 1;
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* add all texcoflags from mtex */
|
2002-10-12 11:37:38 +00:00
|
|
|
ma->texco= 0;
|
|
|
|
ma->mapto= 0;
|
2004-12-04 21:49:02 +00:00
|
|
|
for(a=0; a<MAX_MTEX; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
mtex= ma->mtex[a];
|
|
|
|
if(mtex && mtex->tex) {
|
|
|
|
|
|
|
|
ma->texco |= mtex->texco;
|
|
|
|
ma->mapto |= mtex->mapto;
|
|
|
|
if(R.osa) {
|
|
|
|
if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ma->texco & (511)) needuv= 1;
|
|
|
|
|
|
|
|
if(mtex->object) mtex->object->flag |= OB_DO_IMAT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ma->mode & MA_ZTRA) {
|
|
|
|
/* if(ma->alpha==0.0 || ma->alpha==1.0) */
|
2005-03-23 12:47:23 +00:00
|
|
|
if(R.flag & R_RENDERING) R.flag |= R_ZTRA;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
if(ma->mode & MA_VERTEXCOLP) ma->mode |= MA_VERTEXCOL;
|
|
|
|
|
So, for the platform managers to check:
- the link order for Blender has changed, the libradiosity.a has to be moved after the librender.a (obviously for a new dependency!). Check blender/source/Makefile
- there's a new file: blender/source/radiosity/intern/source/radrender.c
Here's what the new code does:
Using the core routines of the Radiosity tool, each renderface with 'emit material' and each renderface with 'radio material flag' set will be used to itterate to a global illumination solution. Per face with high energy (emit) little images are rendered (hemicubes) which makes up lookup tables to 'shoot' its energy to other faces.
In the end this energy - color - then is directly added to the pixel colors while rendering, Gouraud shaded.
Since it's done with renderfaces, it works for all primitives in Blender.
What is doesn't do yet:
- take into account textured color of faces. Currently it uses the material RGB color for filtering distributed energy.
- do some smart pre-subdividing. I don't know yet if this is useful... Right now it means that you'll have to balance the models yourself, to deliver small faces where you want a high accuracy for shadowing.
- unified render (is at my todo list)
User notes:
- per Material you want to have included in radiosity render: set the 'radio' flag. For newly added Materials it is ON by default now.
- the Ambient slider in Material controls the amount of radiosity color.
- for enabling radiosity rendering, set the F10 "Radio" button.
- the Radiosity buttons now only show the relevant radiosity rendering options. Pressing "collect meshes" will show all buttons again.
- for meshes, the faces who use Radio material always call the 'autosmooth' routine, this to make sure sharp angles (like corners in a room) do not have shared vertices. For some smooth models (like the raptor example) you might increase the standard smoothing angle from 30 to 45 degree.
Technical notes:
- I had to expand the renderface and rendervertices for it... shame on me! Faces have one pointer extra, render vertices four floats...
- The size of the hemicubes is now based at the boundbox of the entire scene (0.002 of it). This should be more reliable... to be done
- I fixed a bug in radiosity render, where sometimes backfaces where lit
In general:
I'd like everyone to play a bit with this system. It's not easy to get good results with it. A simple "hit and go" isn't there... maybe some good suggestions?
2003-08-31 20:33:46 +00:00
|
|
|
if(ma->mode & MA_RADIO) needuv= 1;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ma->mode & (MA_VERTEXCOL|MA_FACETEXTURE)) {
|
|
|
|
needuv= 1;
|
|
|
|
if(R.osa) ma->texco |= TEXCO_OSA; /* for texfaces */
|
|
|
|
}
|
|
|
|
if(needuv) ma->texco |= NEED_UV;
|
2004-12-03 10:16:29 +00:00
|
|
|
|
2004-01-23 21:58:19 +00:00
|
|
|
// since the raytracer doesnt recalc O structs for each ray, we have to preset them all
|
2004-11-24 18:53:45 +00:00
|
|
|
if(ma->mode & (MA_RAYMIRROR|MA_RAYTRANSP|MA_SHADOW_TRA)) {
|
2004-01-23 21:58:19 +00:00
|
|
|
ma->texco |= NEED_UV|TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM;
|
2003-12-16 14:12:01 +00:00
|
|
|
if(R.osa) ma->texco |= TEXCO_OSA;
|
2003-12-10 20:41:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
ma->ambr= ma->amb*R.wrld.ambr;
|
|
|
|
ma->ambg= ma->amb*R.wrld.ambg;
|
|
|
|
ma->ambb= ma->amb*R.wrld.ambb;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_render_materials()
|
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
|
|
|
ma= G.main->mat.first;
|
|
|
|
while(ma) {
|
|
|
|
if(ma->id.us) init_render_material(ma);
|
|
|
|
ma= ma->id.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void end_render_material(Material *ma)
|
|
|
|
{
|
Biiig commit! Thanks to 2-3 weeks of cvs freeze...
Render:
- New; support for dual CPU render (SDL thread)
Currently only works with alternating scanlines, but gives excellent
performance. For both normal render as unified implemented.
Note the "mutex" locks on z-transp buffer render and imbuf loads.
- This has been made possible by major cleanups in render code, especially
getting rid of globals (example Tin Tr Tg Tb Ta for textures) or struct
OSA or using Materials or Texture data to write to.
- Made normal render fully 4x32 floats too, and removed all old optimizes
with chars or shorts.
- Made normal render and unified render use same code for sky and halo
render, giving equal (and better) results for halo render. Old render
now also uses PostProcess options (brightness, mul, gamma)
- Added option ("FBuf") in F10 Output Panel, this keeps a 4x32 bits buffer
after render. Using PostProcess menu you will note an immediate re-
display of image too (32 bits RGBA)
- Added "Hue" and "Saturation" sliders to PostProcess options
- Render module is still not having a "nice" API, but amount of dependencies
went down a lot. Next todo: remove abusive "previewrender" code.
The last main global in Render (struct Render) now can be re-used for fully
controlling a render, to allow multiple "instances" of render to open.
- Renderwindow now displays a smal bar on top with the stats, and keeps the
stats after render too. Including "spare" page support.
Not only easier visible that way, but also to remove the awkward code that
was drawing stats in the Info header (extreme slow on some ATIs too)
- Cleaned up blendef.h and BKE_utildefines.h, these two had overlapping
defines.
- I might have forgotten stuff... and will write a nice doc on the architecture!
2004-12-27 19:28:52 +00:00
|
|
|
/* XXXX obsolete? check! */
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) {
|
|
|
|
if( !(ma->mode & MA_HALO) ) {
|
|
|
|
ma->r= ma->g= ma->b= 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void end_render_materials()
|
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
|
|
|
ma= G.main->mat.first;
|
|
|
|
while(ma) {
|
|
|
|
if(ma->id.us) end_render_material(ma);
|
|
|
|
ma= ma->id.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ****************** */
|
|
|
|
|
|
|
|
char colname_array[125][20]= {
|
|
|
|
"Black","DarkRed","HalveRed","Red","Red",
|
|
|
|
"DarkGreen","DarkOlive","Brown","Chocolate","OrangeRed",
|
|
|
|
"HalveGreen","GreenOlive","DryOlive","Goldenrod","DarkOrange",
|
|
|
|
"LightGreen","Chartreuse","YellowGreen","Yellow","Gold",
|
|
|
|
"Green","LawnGreen","GreenYellow","LightOlive","Yellow",
|
|
|
|
"DarkBlue","DarkPurple","HotPink","VioletPink","RedPink",
|
|
|
|
"SlateGray","DarkGrey","PalePurple","IndianRed","Tomato",
|
|
|
|
"SeaGreen","PaleGreen","GreenKhaki","LightBrown","LightSalmon",
|
|
|
|
"SpringGreen","PaleGreen","MediumOlive","YellowBrown","LightGold",
|
|
|
|
"LightGreen","LightGreen","LightGreen","GreenYellow","PaleYellow",
|
|
|
|
"HalveBlue","DarkSky","HalveMagenta","VioletRed","DeepPink",
|
|
|
|
"SteelBlue","SkyBlue","Orchid","LightHotPink","HotPink",
|
|
|
|
"SeaGreen","SlateGray","MediumGrey","Burlywood","LightPink",
|
|
|
|
"SpringGreen","Aquamarine","PaleGreen","Khaki","PaleOrange",
|
|
|
|
"SpringGreen","SeaGreen","PaleGreen","PaleWhite","YellowWhite",
|
|
|
|
"LightBlue","Purple","MediumOrchid","Magenta","Magenta",
|
|
|
|
"RoyalBlue","SlateBlue","MediumOrchid","Orchid","Magenta",
|
|
|
|
"DeepSkyBlue","LightSteelBlue","LightSkyBlue","Violet","LightPink",
|
|
|
|
"Cyaan","DarkTurquoise","SkyBlue","Grey","Snow",
|
|
|
|
"Mint","Mint","Aquamarine","MintCream","Ivory",
|
|
|
|
"Blue","Blue","DarkMagenta","DarkOrchid","Magenta",
|
|
|
|
"SkyBlue","RoyalBlue","LightSlateBlue","MediumOrchid","Magenta",
|
|
|
|
"DodgerBlue","SteelBlue","MediumPurple","PalePurple","Plum",
|
|
|
|
"DeepSkyBlue","PaleBlue","LightSkyBlue","PalePurple","Thistle",
|
|
|
|
"Cyan","ColdBlue","PaleTurquoise","GhostWhite","White"
|
|
|
|
};
|
|
|
|
|
|
|
|
void automatname(Material *ma)
|
|
|
|
{
|
|
|
|
int nr, r, g, b;
|
|
|
|
float ref;
|
|
|
|
|
|
|
|
if(ma==0) return;
|
|
|
|
if(ma->mode & MA_SHLESS) ref= 1.0;
|
|
|
|
else ref= ma->ref;
|
|
|
|
|
|
|
|
r= (int)(4.99*(ref*ma->r));
|
|
|
|
g= (int)(4.99*(ref*ma->g));
|
|
|
|
b= (int)(4.99*(ref*ma->b));
|
|
|
|
nr= r + 5*g + 25*b;
|
|
|
|
if(nr>124) nr= 124;
|
|
|
|
new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void delete_material_index()
|
|
|
|
{
|
|
|
|
Material *mao, ***matarar;
|
|
|
|
Object *ob, *obt;
|
|
|
|
Curve *cu;
|
|
|
|
Nurb *nu;
|
|
|
|
short *totcolp;
|
|
|
|
int a, actcol;
|
|
|
|
|
|
|
|
if(G.obedit) {
|
|
|
|
error("Unable to perform function in EditMode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ob= ((G.scene->basact)? (G.scene->basact->object) : 0) ;
|
|
|
|
if(ob==0 || ob->totcol==0) return;
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* take a mesh/curve/mball as starting point, remove 1 index,
|
|
|
|
* AND with all objects that share the ob->data
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
2003-04-26 11:56:44 +00:00
|
|
|
* after that check indices in mesh/curve/mball!!!
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
totcolp= give_totcolp(ob);
|
|
|
|
matarar= give_matarar(ob);
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* we delete the actcol */
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ob->totcol) {
|
|
|
|
mao= (*matarar)[ob->actcol-1];
|
|
|
|
if(mao) mao->id.us--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(a=ob->actcol; a<ob->totcol; a++) {
|
|
|
|
(*matarar)[a-1]= (*matarar)[a];
|
|
|
|
}
|
|
|
|
(*totcolp)--;
|
|
|
|
|
|
|
|
if(*totcolp==0) {
|
|
|
|
MEM_freeN(*matarar);
|
|
|
|
*matarar= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
actcol= ob->actcol;
|
|
|
|
obt= G.main->object.first;
|
|
|
|
while(obt) {
|
|
|
|
|
|
|
|
if(obt->data==ob->data) {
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* WATCH IT: do not use actcol from ob or from obt (can become zero) */
|
2002-10-12 11:37:38 +00:00
|
|
|
mao= obt->mat[actcol-1];
|
|
|
|
if(mao) mao->id.us--;
|
|
|
|
|
|
|
|
for(a=actcol; a<obt->totcol; a++) obt->mat[a-1]= obt->mat[a];
|
|
|
|
obt->totcol--;
|
|
|
|
if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
|
|
|
|
|
|
|
|
if(obt->totcol==0) {
|
|
|
|
MEM_freeN(obt->mat);
|
|
|
|
obt->mat= 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obt= obt->id.next;
|
|
|
|
}
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* check indices from mesh */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if(ob->type==OB_MESH) {
|
2004-03-20 23:59:57 +00:00
|
|
|
Mesh *me= get_mesh(ob);
|
|
|
|
mesh_delete_material_index(me, actcol-1);
|
2002-10-12 11:37:38 +00:00
|
|
|
makeDispList(ob);
|
|
|
|
}
|
|
|
|
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
|
|
|
|
cu= ob->data;
|
|
|
|
nu= cu->nurb.first;
|
|
|
|
|
|
|
|
while(nu) {
|
2005-06-25 22:51:51 +00:00
|
|
|
if(nu->mat_nr && nu->mat_nr>=actcol-1) {
|
|
|
|
nu->mat_nr--;
|
|
|
|
if (ob->type == OB_CURVE) nu->charidx--;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
makeDispList(ob);
|
|
|
|
}
|
|
|
|
}
|