RENDER.H

Go to the documentation of this file.
00001 /* --
00002 OpenFX Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 /*  RENDER.H include file for the renderer */
00006 
00007 #pragma warning( disable : 4312)
00008 
00009 #define UNSIGNED unsigned long
00010 
00011 /* true double precison and float types rather than the re-definitions used in renderer to reduce memory usage */
00012 typedef double tDOUBLE;
00013 typedef float  tFLOAT;
00014 
00015 #include <conio.h>
00016 
00017 #include <process.h>
00018 #include <stdlib.h>
00019 #include <stdarg.h>
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <math.h>
00023 #include <windows.h>
00024 #include <gl\gl.h>
00025 #include <gl\glu.h>
00026 
00027 #include "rmessage.h"
00028 extern void RenderYield(void);
00029 extern void WindowedRenderMessage(int message);
00030 extern void WindowedRenderString(char *str);
00031 extern void WindowedRenderInfo(char *str);
00032 extern void UpdateNTTrace(long l);
00033 extern void UpdateNTFrame(long f, long s);
00034 extern int ConfirmNTabort(void);
00035 extern int GetRenderNTnewfile(char *name, char *rep_name);
00036 #define X__getenv(c)    R_GetEnv(c)
00037 
00038 #include "../common/mem.h"
00039 
00040 #define TRUE  1
00041 #define FALSE 0
00042 
00043 
00044 #define YES       1
00045 #define NO        0
00046 #define FAIL     -1
00047 #define OK        1
00048 
00049 #define GET_MATX  "%f %f %f %f"
00050 #define GET_VEC   "%f %f %f"
00051 #define GET_DOB   "%f"
00052 #define double float
00053 #define PI 3.1415926
00054 
00055 
00056 #ifndef min
00057 #define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
00058 #endif
00059 #ifndef max
00060 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00061 #endif
00062 
00063 #ifdef TRACER
00064 #undef  VERSION
00065 #define VERSION "Tracer Module "
00066 #endif
00067 
00068 //#define FRONT_CLIPPING_PLANE 1.0f // far too small
00069 //#define FRONT_CLIPPING_PLANE 100.0f
00070 #define FRONT_CLIPPING_PLANE 750.0f
00071 #define UNIT  32768L
00072 #define UNIT2 65526L
00073 #define BIGP  2147483647L
00074 #define BIGN -2147483647L
00075 #define FARAWAY 1.0e30
00076 #define max_spec 1000
00077 #define SHSCALE  3.921571e-3     // 1/255 
00078 //define NGLASS 2
00079 #define NGLASS 4
00080 
00086 #define VECCOPY(a,b)    { b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; }
00087 #define INVERT(a)       { a[0] = -a[0]; a[1] = -a[1]; a[2] = -a[2]; }
00088 #define VECSUB(a,b,c)   { c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; c[2]=a[2]-b[2];}
00089 #define VECSUM(a,b,c)   { c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2];}
00090 #define VECSCALE(a,b,c) { c[0]=(a)*b[0]; c[1]=(a)*b[1]; c[2]=(a)*b[2];}
00091 #define DOT(a,b)        ( (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) )
00092 #define CROSS(v1,v2,r)  { \
00093                           r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]);  \
00094                           r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]);  \
00095                           r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]);  \
00096                         }
00097 
00103 #define SINGLE    1
00104 #define TILE      2
00105 #define PLANE           0 
00106 #define CYLINDER        1 /*< \brief*         "                              "         */
00107 #define PLANE_MOZIAC    2
00108 #define CYLINDER_MOZIAC 3
00109 #define MAP_BY_VERTEX   4
00110 #define MAP_SPHERICAL   5
00111 #define EOPAQUE   0       
00112 #define TRANSP    1       
00113 #define GLOSS     0       
00114 #define MATT      1       
00115 #define STILBRUSH 0
00116 #define ANIMBRUSH 1
00117 #define BUMPBRUSH 2
00118 #define REFLBRUSH 3
00119 #define PSETBRUSH 4
00120 #define PLAIN     0
00121 #define TEXTU     1
00122 #define BRUM      2
00123 #define TBRUM     3
00124 #define MBRUM     4
00125 #define SKYCOLOUR 0
00126 #define SKYGRADED 1
00127 #define SKYMAPPED 2
00128 #define BACKDROP  3
00129 #define SKYCUBE   4
00130 #define NORMAL    0    
00131 #define NOSHADOW  1
00132 #define SHADOWS   2
00133 #define SPOTLIGHT 3
00134 #define DUMMYL    4
00135 #define NOCOLOUR  32768
00136 #define BITS8     0   
00137 #define BITS16    1
00138 #define BITS24    2
00139 #define NUL_FILE  1   
00140 #define TIF_FILE  5
00141 #define B24_FILE  8
00142 #define J24_FILE  9
00143 #define PNG_FILE 10
00144 #define JPS_FILE 11
00145 #define AVI_FILE 21
00146 #define NONE      0   
00147 #define LOW       1
00148 #define MEDIUM    2
00149 #define HIGH      3
00150 #define ULTRA     4
00151 
00158 #define UCHAR  unsigned char
00159 typedef double vector[3];
00160 typedef long   ivector[3];
00161 typedef double vector2[2];
00162 
00163 #include "light_fsb.h"    // included because these strucrures are also used by the post processors
00164 
00172 typedef struct XIP_RENDER_tag {
00173   long   imo,first_frame,this_frame,last_frame;
00174   double fmr; 
00175   char   *parameters;
00176   char   *mparameters;
00177 } XIP;
00178 
00186 typedef struct Renderer_SKELETON {
00187   long id;         
00188   vector p,pcopy;  
00189   double T[4][4],R[4][4],Q[4][4];
00190   double bLength,weight,wrange,wzone;
00191 }skel;
00192 
00200 typedef struct THD_tag {
00201  UCHAR  *ram;             
00202  long   *Zbuffer,         
00203         *Xbuffer,         
00204         *Zobject,         
00205         *Xobject,         
00206         *Zglass[NGLASS],  
00207         *ZglassO[NGLASS]; 
00208  double *Zdepth,          
00209         *Zposn,           
00210         *Zglassd[NGLASS], 
00211         *Zground;         
00212  UCHAR  *Red,   *Green,   *Blue,   *Alfa,
00213         *L_Red, *L_Green, *L_Blue, *L_Alfa,
00214         *LL_Red,*LL_Green,*LL_Blue,*LL_Alfa;
00215 } THD;
00216 
00217 // include the structure definitions for vertex and faces 
00218 
00219 #include "vertex_face.h" 
00220 
00229 typedef struct Renderer_SHADER_tag {
00230   char file[256],        
00231        parameters[256];  
00232   void *module;          
00233   void *function;        
00234   void *functionGL;      
00235   void *morph;           
00236   void *close;           
00237   long shaderID;         
00238 } shader;
00239 
00247 typedef struct Renderer_AXIS_tag {
00248        vector boin,bo;   
00249        vector buin,bu;   
00250        vector bvin,bv;   
00251        vector bn;        
00252        double tl;  
00253        double tv;  
00254        vector bu_norm, 
00255               bv_norm; 
00256 } axis;
00257 
00266 typedef struct Renderer_IMAP_tag {
00267         vector pin,xin,yin; 
00268         vector n,p,x,y;     
00269         char filename[256], 
00270              frefl[256],    
00271              fbump[256],    
00272              ftran[256];    
00273         short map;          
00274         short moziac;       
00275         BOOL  bAnimS,bAnimR,bAnimB,bAnimT; 
00276         BOOL  bLoadedS,bLoadedR,           
00277               bLoadedB,bLoadedT;           
00278         BOOL  bTiled,bShaded,bDecal;       
00279         short pp,rp,bp,tp;                 
00280         double bumpx,bumpy,angle;          
00281         double pd,rd;                      
00282         short xmax,ymax,                   
00283               xmaxrefl,ymaxrefl,
00284               xmaxbump,ymaxbump,
00285               xmaxtran,ymaxtran;           
00286         unsigned char kt,kc[3];            
00287         unsigned char *p24R,*p24G,*p24B;   
00288         unsigned char *p24Rrefl,*p24Grefl,*p24Brefl;
00289         unsigned char *p24Rbump,*p24Gbump,*p24Bbump;
00290         unsigned char *p24Rtran,*p24Gtran,*p24Btran; 
00291 } imap;
00292 
00302 typedef struct Renderer_MATL_tag {
00303        axis ax;        
00304        unsigned char color[3],texco[3];    
00305        unsigned char acolour[3],scolour[3];
00306        unsigned char xc[3],yc[3],zc[3]; 
00307        unsigned char gloss;     
00308        unsigned char refl;      
00309        unsigned char transp;    
00310        long refractive_index;   /*<< \brief Surface refractive index 1000 integer units = 1.0 */
00311        BOOL bInternalShader;    
00312        int internalShaderID;    
00313        long shaderID[4];        
00314        BOOL bSmooth,
00315             bShiny,
00316             bClear,
00317             bGlassEdge,
00318             bUseSurfaceMapping; 
00319        unsigned char params[16];
00320        // pad bytes are ignored
00321        unsigned char other_properties[512];
00322        double mmw_params[12];  
00323 } matl;
00324 
00325 
00333 typedef struct Renderer_VECTOR4_tag {
00334  double x,y,z,w;
00335  BOOL   selected;
00336 } vector4;
00337 
00345 typedef struct Renderer_NurbsProperties_tag {
00346  char name[32];            /* name field             */
00347  long GranularityMax,      /* for visualising in the */
00348       GranularityMin;      /* view windows           */
00349  long     u_scale,         /* texture coord scaling  */
00350           v_scale;
00351  long     shader,          /* surface properties     */
00352           map,
00353           axis,
00354           param,
00355           smoothing,
00356           shiny,
00357           brilliance,
00358           reflectivity,
00359           transparency,
00360           glasstype,
00361           maptiled,
00362           mapshaded,
00363           mapdecal;
00364  long     pad[4];
00365  unsigned char colour[3],
00366           material_colour[3];
00367  char     hidden;
00368  char     padc[5];
00369 } NurbsProperties;
00370 
00378 typedef struct Renderer_NurbsSurfSample_tag {
00379     vector point,normal;
00380     double normLen;
00381     double u,v;
00382 } NurbsSurfSample;
00383 
00390 typedef struct Renderer_NURBS_tag {
00391  long id;
00392  long numU,numV;
00393  long orderU,orderV;
00394  double *kvU,*kvV;
00395  vector4 **points;
00396  NurbsProperties properties;
00397  BOOL strV0, strVn, strU0, strUn;
00398  BOOL flatV, flatU;
00399  NurbsSurfSample c00, c0n, cn0, cnn;
00400 } nurbs;
00401 
00402 
00410 typedef struct Renderer_GROUND_tag {
00411         vector        pin,xin,yin;
00412         vector        p,x,y,n,dx,dy,dyy; 
00413         double        lengthx,lengthy,  
00414                       height,range,bump;  
00415         double        spec,trans,refl,ambient_light;
00416         unsigned char color[3],   
00417                       acolor[3];  
00418         short         type,    
00419                       maptype, 
00420                       texture, 
00421                       shiny,   
00422                       ispec;  
00423         imap          map;      
00424         BOOL          mapped;   
00425 } ground;
00426 
00433 typedef struct Renderer_SKY_tag {
00434         unsigned char Horizon[3],  
00435                       Zenith[3],
00436                       Hblend[3],
00437                       Zblend[3]; 
00438         double blendratio;       
00439         short  type;             
00440         imap   map;              
00441         BOOL   mapped;           
00442 } sky;
00443 
00451 typedef struct Renderer_PARTICLE_tag{
00452   vector pfx;   
00453   vector p,pl;  
00454   vector v,g,dg;
00455   vector c,dc;  
00456   double fAlpha,fAge,fLifetime,fAlphaDelta,fSize,fSizeDelta;
00457   BOOL   bSpin; 
00458 } Particle;
00459 
00467 typedef struct Renderer_PARTICLESYSTEM_tag {
00468   vector pin;     
00469   double dPhi,dTheta,dAlpha,ima;
00470   short  im;
00471   double sx,sy,sz; 
00472   vector tpin,spin;
00473   double tdPhi,sdPhi,tdTheta,sdTheta,tdAlpha,sdAlpha,tima,sima;
00474   short  tim,sim;
00475   double tsx,ssx,tsy,ssy,tsz,ssz;
00476   double particle_object_transformation[4][4];
00477   long id;    
00478   long blend_type;
00479   long Rate;  
00480   long NumP;  
00481   long iid;   
00482   long dframe;
00483   char ImageName[256]; 
00484   // parameters from animator
00485   unsigned char colour_start[3],colour_end[3];
00486   long alpha_start,alpha_end,size_start,size_end,life,particle_size_scale,speed,
00487        ew_start,ud_start,ns_start,ew_end,ud_end,ns_end,
00488        theta,boing,particle_speed_scale;
00489   long valpha,vcolour,vsize,vlife,vspeed;
00490   BOOL bBurst,bSuppress, 
00491        bGround,
00492        bSingle,
00493        bSteadyState,    
00494        bSpinOff;     
00495   // renderer specifics below
00496   vector vel; 
00497   double dt,     
00498          mratio; 
00499   Particle *particles;  
00500   vector vColorStart,vColorVar,vColorEnd; 
00501   vector vTempVelocity,vPrevLocation,vLocation;
00502   double fTimeLastUpdate;
00503   double fSizeScale;
00504   double fAlphaStart,fAlphaVar,fAlphaEnd,fSizeStart,fSizeVar,fSizeEnd;
00505   double fSpeed,fSpeedVar,fTheta; 
00506   double fLifeTime,fLifeVar,fGravityVar; 
00507   vector vGravityStart,vGravityEnd;
00508   long uParticlesPerSec; 
00509   double fEmissionResidue; 
00510 } ParticleSystem;
00511 
00519 typedef struct Renderer_OBJECT_tag { /* info for each object */
00520         BOOL    in_use;   
00521         vector  Centre;   
00522         axis    Abase;    
00523         // Pointers to key object data      
00524         vertex  *Vbase,*Vbackup; 
00525         face    *Fbase,*Fbackup; 
00526         tvertex *Vtracebase;     
00527         tface   *Ftracebase;      
00528         long    *Skids;          
00529         skel    *Skeleton;       
00530         imap    *Mbase;          
00531         matl    *Tbase,*Tbackup; 
00532         nurbs   *Nbase;          
00533         long    NoFaces,NoVertices,
00534                 NoNurbs,
00535                 NoMaps,NoMats,
00536                 NoSkeleton;
00537         long    NoTraceVertices,NoTraceFaces;  
00538         long    NoFbackup,NoVbackup,NoTbackup;  
00539         long    xmin,xmax,ymin,ymax; 
00540         double  trpos[4][4],trinv[4][4];  
00541         vector  Offset; 
00542         double  fi,theta,alpha,ima; 
00543         double  sx,sy,sz;           
00544         double  morphratio,effectratio, 
00545                 ambient_light;   
00546         short   visibility,      
00547                 im,
00548                 effect;          
00549         BOOL    wireframe;  
00550         BOOL    self_shadow,cast_shadow,show_shadow; 
00551         long    AnimatorID;     
00552         char    *effect_param_list; 
00553         char    FileNameKey[256];
00554 } object;
00555 
00556 
00557 extern FILE *debug;  
00559 #ifdef MODULE_RENDER
00560 char         IniFilename[256];
00561 BOOL         full_mirror=FALSE,bRenderOpenGL=FALSE;
00562 long         ResolutionX,ResolutionY
00563              ,renderer_silent=0
00564              ,XMIN=0,XMAX=320,YMIN=0,YMAX=200 //,FAST=NO
00565              ,OUTPUT_FILE_TYPE=B24_FILE
00566              ,anti_alias=NO,anti_alias_edges=NO,ntsc_colours=NO
00567              ,objectIDbufferON=NO
00568              ,alfachannelON=NO,alfagroundON=NO
00569              ,StereoRenderingON=NO
00570              ,remove_hidden_faces=NO,in_mirror_phase=NO,mblurON=0
00571              ,instant_callback=NO,jpeg_quality=75
00572              ,nCOLOUR=NOCOLOUR,RenderCurrentFrame,nScriptframes;
00573 fullscreenbuffer *FullScreenBuffer,*MotionBlurBuffer;
00574 float            *fszBuffer;
00575 XIP              *ImageProcesses;
00576 
00577 extern unsigned long  *colorstats0;  
00578 extern unsigned short *colorstats1;  
00580 extern char *R_GetEnv(char const *aa);
00581 
00582 object         *Object=NULL;
00583 ground         Ground;     
00584 sky            Sky;        
00585 shader         *Shader;    
00586 vector         ViewPoint;
00587 light          *Lights;    
00588 ParticleSystem *ParticleS; 
00589 char          colour0_flag=0;
00590 unsigned char colour0_red=0,colour0_green=0,colour0_blue=0;
00591 long          ObjectCount=0 
00592              ,FirstObject=0
00593              ,Xcentre,Ycentre
00594              ,Nlights=0,R_Nground=0,Nsky=0
00595              ,Nparticles=0  
00596              ,Nshader=0,nImageProcesses=0
00597              ,shadow_buffer_size=320
00598              ,skyBmax
00599              ,flashing=0,CamIm=0
00600              ,trace_shadows,trace_reflections,trace_refractions
00601              ,trace_partition,trace_depth
00602              ,trace_face_count_target,trace_voxel_min_size
00603              ,ColourResolution=BITS8
00604              ,tzeros=3
00605              ,aaXstep,aaYstep
00606              ,ClipXmin,ClipXmax,ClipYmin,ClipYmax,ClipZmin,ClipZmax;
00607 
00608 unsigned short     *RendererUshortBuffer;
00609 unsigned long      *RendererUlongBuffer;
00610 short              *ZskyBuffer,*RendererShortBuffer;
00611 long               *RendererLongBuffer,
00612                    *gZbuffer,*gXbuffer,    // the g***** scanline buffers would be used for rendering in a single thread
00613                    *gZobject,*gXobject,
00614                    *gZglass[NGLASS],
00615                    *gZglassO[NGLASS];
00616 double             *gZdepth,
00617                    *gZposn,
00618                    *gZglassd[NGLASS],
00619                    *gZground,
00620                    *DL,*DR,*D1,
00621                    AntiCamera[4][4],
00622                    CameraRotate[4][4],
00623                    ViewTransform[4][4]={1.0,0.0,0.0,0.0
00624                              ,0.0,1.0,0.0,0.0
00625                              ,0.0,0.0,1.0,0.0
00626                              ,0.0,0.0,0.0,1.0};
00627 GLfloat            AntiCameraGL[3][3];
00628 unsigned char *gRed,   *gGreen,   *gBlue,   *gAlfa,
00629               *gL_Red, *gL_Green, *gL_Blue, *gL_Alfa,
00630               *gLL_Red,*gLL_Green,*gLL_Blue,*gLL_Alfa,
00631               *DummyShadow;
00632 int            CamPolarisation;
00633 double         scalex,scaley,
00634                BigL=FARAWAY,
00635                CamPhi,    
00636                CamTheta,  
00637                CamAlpha,  
00638                CamIma, 
00639                CamSx,CamSy,CamSz,
00640                CamFocalLength,CamFnumber,CamFocusDepth,CamFocusDepthM,CamRuler,CamStereoSeparation,CamParallaxDepth,
00641                skyYscale,skyXscale,
00642                ambient_light=0.1,smoothing_angle=0.01,
00643                shadow_density=0.5,glass_shadow_density=0.8,
00644                ground_ambient_light,
00645                object_ambient_light,
00646                wave_phase;
00647 unsigned char *VGA_screen=NULL,*ObjectIdBuffer=NULL;
00648 int            Nprocessors=1,Nthreads=0;
00649 
00650 #else
00651 
00652 extern char IniFilename[];
00653 extern BOOL  full_mirror,bRenderOpenGL;
00654 extern long  ResolutionX,ResolutionY
00655             ,renderer_silent
00656             ,XMIN,XMAX,YMIN,YMAX
00657             //,FAST
00658             ,OUTPUT_FILE_TYPE
00659             ,anti_alias,anti_alias_edges,ntsc_colours
00660             ,objectIDbufferON
00661             ,alfachannelON,alfagroundON
00662             ,StereoRenderingON
00663             ,remove_hidden_faces,in_mirror_phase,mblurON
00664             ,instant_callback,jpeg_quality
00665             ,nCOLOUR,RenderCurrentFrame,nScriptframes;
00666 extern fullscreenbuffer *FullScreenBuffer,*MotionBlurBuffer;
00667 extern float            *fszBuffer;
00668 extern XIP              *ImageProcesses;
00669 extern unsigned long  *colorstats0;
00670 extern unsigned short *colorstats1;
00671 extern char *R_GetEnv(char const *aa);
00672 extern object         *Object;
00673 extern ground         Ground;
00674 extern sky            Sky;
00675 extern shader         *Shader;
00676 extern vector         ViewPoint;
00677 extern light          *Lights;
00678 extern ParticleSystem *ParticleS;
00679 extern char          colour0_flag;
00680 extern unsigned char colour0_red,colour0_green,colour0_blue;
00681 extern long          ObjectCount,FirstObject
00682                      ,Xcentre,Ycentre
00683                      ,Nlights,nImageProcesses,R_Nground,Nsky,Nparticles
00684                      ,Nshader,shadow_buffer_size
00685                      ,skyBmax
00686                      ,flashing,CamIm
00687                      ,trace_shadows,trace_reflections,trace_refractions
00688                      ,trace_partition,trace_depth
00689                      ,trace_face_count_target,trace_voxel_min_size
00690                      ,trace_shadows,trace_reflections,trace_refractions
00691                      ,ColourResolution
00692                      ,tzeros
00693                      ,aaXstep,aaYstep
00694                      ,ClipXmin,ClipXmax,ClipYmin,ClipYmax,ClipZmin,ClipZmax;
00695 extern unsigned short   *RendererUshortBuffer;
00696 extern unsigned long    *RendererUlongBuffer;
00697 extern long             *RendererLongBuffer;
00698 extern short            *ZskyBuffer,*RendererShortBuffer;
00699 
00700 extern double           *DL,*DR,*D1,
00701                         AntiCamera[4][4],
00702                         CameraRotate[4][4],
00703                         ViewTransform[4][4];
00704 extern GLfloat          AntiCameraGL[3][3];
00705 extern unsigned char  *DummyShadow;
00706 extern int            CamPolarisation;
00707 extern double         scalex,scaley,
00708                       BigL,CamPhi,CamTheta,CamAlpha,CamIma,
00709                       CamSx,CamSy,CamSz,
00710                       CamFocalLength,CamFnumber,CamFocusDepth,CamFocusDepthM,CamRuler,CamStereoSeparation,CamParallaxDepth,
00711                       skyYscale,skyXscale,
00712                       ambient_light,smoothing_angle,
00713                       shadow_density,glass_shadow_density,
00714                       ground_ambient_light,
00715                       object_ambient_light,
00716                       wave_phase;
00717 extern unsigned char  *VGA_screen,*ObjectIdBuffer;
00718 extern int            Nprocessors,Nthreads;
00719 
00720 #endif
00721 
00722 #include "protos.h"

Generated on Sun Apr 27 14:20:13 2014 for OpenFX by  doxygen 1.5.6