Blender V2.61 - r43446

render_types.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * Contributor(s): (c) 2006 Blender Foundation, full refactor
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00031 #ifndef RENDER_TYPES_H
00032 #define RENDER_TYPES_H
00033 
00034 /* ------------------------------------------------------------------------- */
00035 /* exposed internal in render module only! */
00036 /* ------------------------------------------------------------------------- */
00037 
00038 #include "DNA_color_types.h"
00039 #include "DNA_customdata_types.h"
00040 #include "DNA_scene_types.h"
00041 #include "DNA_world_types.h"
00042 #include "DNA_object_types.h"
00043 #include "DNA_vec_types.h"
00044 
00045 #include "BLI_threads.h"
00046 
00047 #include "RE_pipeline.h"
00048 #include "RE_shader_ext.h"  /* TexResult, ShadeResult, ShadeInput */
00049 #include "sunsky.h"
00050 
00051 #include "BLO_sys_types.h" // for intptr_t support
00052 
00053 struct Object;
00054 struct MemArena;
00055 struct VertTableNode;
00056 struct VlakTableNode;
00057 struct GHash;
00058 struct RenderBuckets;
00059 struct ObjectInstanceRen;
00060 struct RayObject;
00061 struct RayFace;
00062 struct ReportList;
00063 struct Main;
00064 
00065 #define TABLEINITSIZE 1024
00066 #define LAMPINITSIZE 256
00067 
00068 typedef struct SampleTables
00069 {
00070     float centLut[16];
00071     float *fmask1[9], *fmask2[9];
00072     char cmask[256], *centmask;
00073     
00074 } SampleTables;
00075 
00076 typedef struct QMCSampler
00077 {
00078     struct QMCSampler *next, *prev;
00079     int type;
00080     int tot;
00081     int used;
00082     double *samp2d;
00083     double offs[BLENDER_MAX_THREADS][2];
00084 } QMCSampler;
00085 
00086 #define SAMP_TYPE_JITTERED      0
00087 #define SAMP_TYPE_HALTON        1
00088 #define SAMP_TYPE_HAMMERSLEY    2
00089 
00090 /* this is handed over to threaded hiding/passes/shading engine */
00091 typedef struct RenderPart
00092 {
00093     struct RenderPart *next, *prev;
00094     
00095     RenderResult *result;           /* result of part rendering */
00096     ListBase fullresult;            /* optional full sample buffers */
00097     
00098     int *recto;                     /* object table for objects */
00099     int *rectp;                     /* polygon index table */
00100     int *rectz;                     /* zbuffer */
00101     int *rectmask;                  /* negative zmask */
00102     intptr_t *rectdaps;                 /* delta acum buffer for pixel structs */
00103     int *rectbacko;                 /* object table for backside sss */
00104     int *rectbackp;                 /* polygon index table for backside sss */
00105     int *rectbackz;                 /* zbuffer for backside sss */
00106     intptr_t *rectall;                  /* buffer for all faces for sss */
00107 
00108     rcti disprect;                  /* part coordinates within total picture */
00109     int rectx, recty;               /* the size */
00110     short crop, ready;              /* crop is amount of pixels we crop, for filter */
00111     short sample, nr;               /* sample can be used by zbuffers, nr is partnr */
00112     short thread;                   /* thread id */
00113     
00114     char *clipflag;                 /* clipflags for part zbuffering */
00115 } RenderPart;
00116 
00117 /* controls state of render, everything that's read-only during render stage */
00118 struct Render
00119 {
00120     struct Render *next, *prev;
00121     char name[RE_MAXNAME];
00122     int slot;
00123     
00124     /* state settings */
00125     short flag, osa, ok, result_ok;
00126     
00127     /* result of rendering */
00128     RenderResult *result;
00129     /* if render with single-layer option, other rendered layers are stored here */
00130     RenderResult *pushedresult;
00131     /* a list of RenderResults, for fullsample */
00132     ListBase fullresult;    
00133     /* read/write mutex, all internal code that writes to re->result must use a
00134        write lock, all external code must use a read lock. internal code is assumed
00135        to not conflict with writes, so no lock used for that */
00136     ThreadRWMutex resultmutex;
00137     
00138     /* window size, display rect, viewplane */
00139     int winx, winy;         /* buffer width and height with percentage applied
00140                              * without border & crop. convert to long before multiplying together to avoid overflow. */
00141     rcti disprect;          /* part within winx winy */
00142     rctf viewplane;         /* mapped on winx winy */
00143     float viewdx, viewdy;   /* size of 1 pixel */
00144     float clipcrop;         /* 2 pixel boundary to prevent clip when filter used */
00145     
00146     /* final picture width and height (within disprect) */
00147     int rectx, recty;
00148     
00149     /* real maximum amount of xparts/yparts after correction for minimum */
00150     int xparts, yparts;
00151     /* real maximum size of parts after correction for minimum 
00152        partx*xparts can be larger than rectx, in that case last part is smaller */
00153     int partx, party;
00154     
00155     /* values for viewing */
00156     float ycor; /* (scene->xasp / scene->yasp), multiplied with 'winy' */
00157     
00158     float panophi, panosi, panoco, panodxp, panodxv;
00159     
00160     /* Matrices */
00161     float grvec[3];         /* for world */
00162     float imat[3][3];       /* copy of viewinv */
00163     float viewmat[4][4], viewinv[4][4];
00164     float winmat[4][4];
00165     
00166     /* clippping */
00167     float clipsta;
00168     float clipend;
00169     
00170     /* samples */
00171     SampleTables *samples;
00172     float jit[32][2];
00173     float mblur_jit[32][2];
00174     ListBase *qmcsamplers;
00175     
00176     /* shadow counter, detect shadow-reuse for shaders */
00177     int shadowsamplenr[BLENDER_MAX_THREADS];
00178     
00179     /* main, scene, and its full copy of renderdata and world */
00180     struct Main *main;
00181     Scene *scene;
00182     RenderData r;
00183     World wrld;
00184     struct Object *camera_override;
00185     unsigned int lay;
00186     
00187     ListBase parts;
00188     
00189     /* octree tables and variables for raytrace */
00190     struct RayObject *raytree;
00191     struct RayFace *rayfaces;
00192     struct VlakPrimitive *rayprimitives;
00193     float maxdist; /* needed for keeping an incorrect behaviour of SUN and HEMI lights (avoid breaking old scenes) */
00194 
00195     /* occlusion tree */
00196     void *occlusiontree;
00197     ListBase strandsurface;
00198     
00199     /* use this instead of R.r.cfra */
00200     float cfra;
00201     float mblur_offs, field_offs;
00202     
00203     /* render database */
00204     int totvlak, totvert, tothalo, totstrand, totlamp;
00205     struct HaloRen **sortedhalos;
00206 
00207     ListBase lights;    /* GroupObject pointers */
00208     ListBase lampren;   /* storage, for free */
00209     
00210     ListBase objecttable;
00211 
00212     struct ObjectInstanceRen *objectinstance;
00213     ListBase instancetable;
00214     int totinstance;
00215 
00216     struct Image *bakebuf;
00217     
00218     struct GHash *orco_hash;
00219 
00220     struct GHash *sss_hash;
00221     ListBase *sss_points;
00222     struct Material *sss_mat;
00223 
00224     ListBase customdata_names;
00225 
00226     struct Object *excludeob;
00227     ListBase render_volumes_inside;
00228     ListBase volumes;
00229     ListBase volume_precache_parts;
00230 
00231     /* arena for allocating data for use during render, for
00232         * example dynamic TFaces to go in the VlakRen structure.
00233         */
00234     struct MemArena *memArena;
00235     
00236     /* callbacks */
00237     void (*display_init)(void *handle, RenderResult *rr);
00238     void *dih;
00239     void (*display_clear)(void *handle, RenderResult *rr);
00240     void *dch;
00241     void (*display_draw)(void *handle, RenderResult *rr, volatile rcti *rect);
00242     void *ddh;
00243     
00244     void (*stats_draw)(void *handle, RenderStats *ri);
00245     void *sdh;
00246     void (*progress)(void *handle, float i);
00247     void *prh;
00248     
00249     void (*draw_lock)(void *handle, int i);
00250     void *dlh;
00251     int (*test_break)(void *handle);
00252     void *tbh;
00253     
00254     RenderStats i;
00255 
00256     struct ReportList *reports;
00257 };
00258 
00259 /* ------------------------------------------------------------------------- */
00260 
00261 struct ISBData;
00262 
00263 typedef struct DeepSample {
00264     int z;
00265     float v;
00266 } DeepSample;
00267  
00268 typedef struct ShadSampleBuf {
00269     struct ShadSampleBuf *next, *prev;
00270     intptr_t *zbuf;
00271     char *cbuf;
00272     DeepSample **deepbuf;
00273     int *totbuf;
00274 } ShadSampleBuf;
00275 
00276 typedef struct ShadBuf {
00277     /* regular shadowbuffer */
00278     short samp, shadhalostep, totbuf;
00279     float persmat[4][4];
00280     float viewmat[4][4];
00281     float winmat[4][4];
00282     float *jit, *weight;
00283     float d, clipend, pixsize, soft, compressthresh;
00284     int co[3];
00285     int size, bias;
00286     ListBase buffers;
00287     
00288     /* irregular shadowbufer, result stored per thread */
00289     struct ISBData *isb_result[BLENDER_MAX_THREADS];
00290 } ShadBuf;
00291 
00292 /* ------------------------------------------------------------------------- */
00293 
00294 typedef struct ObjectRen {
00295     struct ObjectRen *next, *prev;
00296     struct Object *ob, *par;
00297     struct Scene *sce;
00298     int index, psysindex, flag, lay;
00299 
00300     float boundbox[2][3];
00301 
00302     int totvert, totvlak, totstrand, tothalo;
00303     int vertnodeslen, vlaknodeslen, strandnodeslen, blohalen;
00304     struct VertTableNode *vertnodes;
00305     struct VlakTableNode *vlaknodes;
00306     struct StrandTableNode *strandnodes;
00307     struct HaloRen **bloha;
00308     struct StrandBuffer *strandbuf;
00309 
00310     char (*mtface)[MAX_CUSTOMDATA_LAYER_NAME];
00311     char (*mcol)[MAX_CUSTOMDATA_LAYER_NAME];
00312     int  actmtface, actmcol, bakemtface;
00313 
00314     float obmat[4][4];  /* only used in convertblender.c, for instancing */
00315 
00316     /* used on makeraytree */
00317     struct RayObject *raytree;
00318     struct RayFace *rayfaces;
00319     struct VlakPrimitive *rayprimitives;
00320     struct ObjectInstanceRen *rayobi;
00321     
00322 } ObjectRen;
00323 
00324 typedef struct ObjectInstanceRen {
00325     struct ObjectInstanceRen *next, *prev;
00326 
00327     ObjectRen *obr;
00328     Object *ob, *par;
00329     int index, psysindex, lay;
00330 
00331     float mat[4][4], nmat[3][3]; /* nmat is inverse mat tranposed */
00332     short flag;
00333 
00334     float dupliorco[3], dupliuv[2];
00335     float (*duplitexmat)[4];
00336     
00337     struct VolumePrecache *volume_precache;
00338     
00339     float *vectors; /* (RE_WINSPEED_ELEMS * VertRen.index) */
00340     int totvector;
00341     
00342     /* used on makeraytree */
00343     struct RayObject *raytree;
00344     int transform_primitives;
00345 
00346 } ObjectInstanceRen;
00347 
00348 /* ------------------------------------------------------------------------- */
00349 
00350 typedef struct VertRen
00351 {
00352     float co[3];
00353     float n[3];
00354     float *orco;
00355     unsigned int flag;  /* in use for clipping zbuffer parts, temp setting stuff in convertblender.c
00356                          * only an 'int' because of alignment, could be a char too */
00357     float accum;        /* accum for radio weighting, and for strand texco static particles */
00358     int index;          /* index allows extending vertren with any property */
00359 } VertRen;
00360 
00361 /* ------------------------------------------------------------------------- */
00362 
00363 struct halosort {
00364     struct HaloRen *har;
00365     int z;
00366 };
00367 
00368 /* ------------------------------------------------------------------------- */
00369 struct Material;
00370 struct MTFace;
00371 
00372 typedef struct RadFace {
00373     float unshot[3], totrad[3];
00374     float norm[3], cent[3], area;
00375     int flag;
00376 } RadFace;
00377 
00378 typedef struct VlakRen {
00379     struct VertRen *v1, *v2, *v3, *v4;  /* keep in order for ** addressing */
00380     float n[3];
00381     struct Material *mat;
00382     char puno;
00383     char flag, ec;
00384     int index;
00385 } VlakRen;
00386 
00387 typedef struct HaloRen
00388 {   
00389     short miny, maxy;
00390     float alfa, xs, ys, rad, radsq, sin, cos, co[3], no[3];
00391     float hard, b, g, r;
00392     int zs, zd;
00393     int zBufDist;   /* depth in the z-buffer coordinate system */
00394     char starpoints, type, add, tex;
00395     char linec, ringc, seed;
00396     short flarec; /* used to be a char. why ?*/
00397     float hasize;
00398     int pixels;
00399     unsigned int lay;
00400     struct Material *mat;
00401 } HaloRen;
00402 
00403 /* ------------------------------------------------------------------------- */
00404 
00405 typedef struct StrandVert {
00406     float co[3];
00407     float strandco;
00408 } StrandVert;
00409 
00410 typedef struct StrandSurface {
00411     struct StrandSurface *next, *prev;
00412     ObjectRen obr;
00413     int (*face)[4];
00414     float (*co)[3];
00415     /* for occlusion caching */
00416     float (*ao)[3];
00417     float (*env)[3];
00418     float (*indirect)[3];
00419     /* for speedvectors */
00420     float (*prevco)[3], (*nextco)[3];
00421     int totvert, totface;
00422 } StrandSurface;
00423 
00424 typedef struct StrandBound {
00425     int start, end;
00426     float boundbox[2][3];
00427 } StrandBound;
00428 
00429 typedef struct StrandBuffer {
00430     struct StrandBuffer *next, *prev;
00431     struct StrandVert *vert;
00432     struct StrandBound *bound;
00433     int totvert, totbound;
00434 
00435     struct ObjectRen *obr;
00436     struct Material *ma;
00437     struct StrandSurface *surface;
00438     unsigned int lay;
00439     int overrideuv;
00440     int flag, maxdepth;
00441     float adaptcos, minwidth, widthfade;
00442     
00443     float maxwidth; /* for cliptest of strands in blender unit */
00444     
00445     float winmat[4][4];
00446     int winx, winy;
00447 } StrandBuffer;
00448 
00449 typedef struct StrandRen {
00450     StrandVert *vert;
00451     StrandBuffer *buffer;
00452     int totvert, flag;
00453     int clip, index;
00454     float orco[3];
00455 } StrandRen;
00456 
00457 /* ------------------------------------------------------------------------- */
00458 
00459 typedef struct VolumeOb
00460 {
00461     struct VolumeOb *next, *prev;
00462     struct Material *ma;
00463     struct ObjectRen *obr;
00464 } VolumeOb;
00465 
00466 typedef struct MatInside {
00467     struct MatInside *next, *prev;
00468     struct Material *ma;
00469     struct ObjectInstanceRen *obi;
00470 } MatInside;
00471 
00472 typedef struct VolPrecachePart
00473 {
00474     struct VolPrecachePart *next, *prev;
00475     struct RayObject *tree;
00476     struct ShadeInput *shi;
00477     struct ObjectInstanceRen *obi;
00478     float viewmat[4][4];
00479     int num;
00480     int minx, maxx;
00481     int miny, maxy;
00482     int minz, maxz;
00483     int res[3];
00484     float bbmin[3];
00485     float voxel[3];
00486     struct Render *re;
00487 } VolPrecachePart;
00488 
00489 typedef struct VolumePrecache
00490 {
00491     int res[3];
00492     float *bbmin, *bbmax;
00493     float *data_r;
00494     float *data_g;
00495     float *data_b;
00496 } VolumePrecache;
00497 
00498 /* ------------------------------------------------------------------------- */
00499 
00500 struct LampRen;
00501 struct MTex;
00502 
00508 typedef struct LampShadowSubSample {
00509     int samplenr;
00510     float shadfac[4];   /* rgba shadow */
00511 } LampShadowSubSample;
00512 
00513 typedef struct LampShadowSample {
00514     LampShadowSubSample s[16];  /* MAX OSA */
00515 } LampShadowSample;
00516 
00517 typedef struct LampRen {
00518     struct LampRen *next, *prev;
00519     
00520     float xs, ys, dist;
00521     float co[3];
00522     short type;
00523     int mode;
00524     float r, g, b, k;
00525     float shdwr, shdwg, shdwb;
00526     float energy, haint;
00527     int lay;
00528     float spotsi,spotbl;
00529     float vec[3];
00530     float xsp, ysp, distkw, inpr;
00531     float halokw, halo;
00532     
00533     short falloff_type;
00534     float ld1,ld2;
00535     struct CurveMapping *curfalloff;
00536 
00537     /* copied from Lamp, to decouple more rendering stuff */
00539     short bufsize;
00541     short samp;
00543     float soft;
00545     short buffers, filtertype;
00547     short buftype;
00549     short bufflag;
00551     short shadhalostep;
00553     float clipsta;
00555     float clipend;
00557     float bias;
00558     /* Compression threshold for deep shadow maps */
00559     float compressthresh;
00560     
00561     short ray_samp, ray_sampy, ray_sampz, ray_samp_method, ray_samp_type, area_shape, ray_totsamp;
00562     short xold[BLENDER_MAX_THREADS], yold[BLENDER_MAX_THREADS]; /* last jitter table for area lights */
00563     float area_size, area_sizey, area_sizez;
00564     float adapt_thresh;
00565 
00566     /* sun/sky */
00567     struct SunSky *sunsky;
00568     
00569     struct ShadBuf *shb;
00570     float *jitter;
00571     
00572     float imat[3][3];
00573     float spottexfac;
00574     float sh_invcampos[3], sh_zfac; /* sh_= spothalo */
00575     
00576     float mat[3][3];    /* 3x3 part from lampmat x viewmat */
00577     float area[8][3], areasize;
00578     
00579     /* passes & node shader support: all shadow info for a pixel */
00580     LampShadowSample *shadsamp;
00581     
00582     /* ray optim */
00583     struct RayObject *last_hit[BLENDER_MAX_THREADS];
00584     
00585     struct MTex *mtex[MAX_MTEX];
00586 
00587     /* threading */
00588     int thread_assigned;
00589     int thread_ready;
00590 } LampRen;
00591 
00592 /* **************** defines ********************* */
00593 
00594 /* R.r.mode flag is same as for renderdata */
00595 
00596 /* R.flag */
00597 #define R_ZTRA          1
00598 #define R_HALO          2
00599 #define R_SEC_FIELD     4
00600 #define R_LAMPHALO      8
00601 #define R_NEED_TANGENT  16
00602 #define R_BAKE_TRACE    32
00603 #define R_BAKING        64
00604 #define R_ANIMATION     128
00605 
00606 /* vlakren->flag (vlak = face in dutch) char!!! */
00607 #define R_SMOOTH        1
00608 #define R_HIDDEN        2
00609 /* strand flag, means special handling */
00610 #define R_STRAND        4
00611 #define R_FULL_OSA      8
00612 #define R_FACE_SPLIT    16
00613 /* Tells render to divide face other way. */
00614 #define R_DIVIDE_24     32  
00615 /* vertex normals are tangent or view-corrected vector, for hair strands */
00616 #define R_TANGENT       64      
00617 #define R_TRACEBLE      128
00618 
00619 /* strandbuffer->flag */
00620 #define R_STRAND_BSPLINE    1
00621 #define R_STRAND_B_UNITS    2
00622 
00623 /* objectren->flag */
00624 #define R_INSTANCEABLE      1
00625 
00626 /* objectinstance->flag */
00627 #define R_DUPLI_TRANSFORMED 1
00628 #define R_ENV_TRANSFORMED   2
00629 #define R_TRANSFORMED       (1|2)
00630 
00631 #endif /* RENDER_TYPES_H */
00632