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