--- ray/src/common/bsdf.h 2011/04/19 21:31:22 2.11 +++ ray/src/common/bsdf.h 2012/10/13 20:15:43 2.20 @@ -1,4 +1,4 @@ -/* RCSid $Id: bsdf.h,v 2.11 2011/04/19 21:31:22 greg Exp $ */ +/* RCSid $Id: bsdf.h,v 2.20 2012/10/13 20:15:43 greg Exp $ */ /* * bsdf.h * @@ -14,7 +14,7 @@ * in the +Z direction, towards the interior of the space rather * than the exterior. * - * BSDF vectors always oriented away from surface, even when "incident." + * BSDF incident & exiting vectors are always oriented away from surface. * * Created by Greg Ward on 1/10/11. * @@ -30,6 +30,10 @@ extern "C" { #endif +#ifdef _WIN32 +#define strcasecmp stricmp +#endif + #define SDnameLn 128 /* maximum BSDF name length */ #define SDmaxCh 3 /* maximum # spectral channels */ @@ -67,13 +71,15 @@ typedef struct { } SDValue; /* Cached, encoded, cumulative distribution for one incident (solid) angle */ -#define SD_CDIST_BASE double cTotal; \ - struct SDCDst_s *next +#define SD_CDIST_BASE(styp) double cTotal; \ + struct styp *next typedef struct SDCDst_s { - SD_CDIST_BASE; /* base fields first */ + SD_CDIST_BASE(SDCDst_s); /* base fields first */ /* ...encoded distribution extends struct */ } SDCDst; +extern const SDCDst SDemptyCD; /* empty distribution */ + /* Forward declaration of BSDF component */ typedef struct SDComp_s SDComponent; @@ -81,15 +87,15 @@ typedef struct SDComp_s SDComponent; typedef const struct { /* return non-diffuse BSDF */ int (*getBSDFs)(float coef[SDmaxCh], const FVECT outVec, - const FVECT inVec, const void *dist); + const FVECT inVec, SDComponent *sdc); /* query non-diffuse PSA for vector */ SDError (*queryProjSA)(double *psa, const FVECT v1, const RREAL *v2, int qflags, - const void *dist); + SDComponent *sdc); /* get cumulative distribution */ const SDCDst *(*getCDist)(const FVECT inVec, SDComponent *sdc); /* sample cumulative distribution */ - SDError (*sampCDist)(FVECT outVec, double randX, + SDError (*sampCDist)(FVECT ioVec, double randX, const SDCDst *cdp); /* free a spectral BSDF component */ void (*freeSC)(void *dist); @@ -113,13 +119,16 @@ typedef struct { /* Loaded BSDF data */ typedef struct { - char name[SDnameLn]; /* BSDF name (derived from file) */ + char name[SDnameLn]; /* BSDF name (usu. derived from file) */ + char matn[SDnameLn]; /* material name */ + char makr[SDnameLn]; /* manufacturer */ char *mgf; /* geometric description (if any) */ float dim[3]; /* width, height, thickness (meters) */ SDValue rLambFront; /* diffuse front reflectance */ SDValue rLambBack; /* diffuse rear reflectance */ SDValue tLamb; /* diffuse transmission */ - SDSpectralDF *rf, *rb, *tf; /* non-diffuse BSDF components */ + SDSpectralDF *rf, *rb; /* non-diffuse BRDF components */ + SDSpectralDF *tf, *tb; /* non-diffuse BTDF components */ } SDData; /* List of loaded BSDFs */ @@ -130,12 +139,12 @@ extern struct SDCache_s { *next; } *SDcacheList; /* Global BSDF cache */ -/* BSDF cache retention preference */ -#define SDretainNone 0 /* free unreferenced data (default) */ -#define SDretainBSDFs 1 /* keep loaded BSDFs in cache */ +/* BSDF cache retention policies */ +#define SDretainNone 0 /* free unreferenced BSDF data */ +#define SDretainBSDFs 1 /* keep loaded BSDFs in memory */ #define SDretainAll 2 /* also keep cumulative cache data */ -extern int SDretainSet; /* set to SDretainNone by default */ +extern int SDretainSet; /* =SDretainNone by default */ /***************************************************************** * The following routines are less commonly used by applications. @@ -152,6 +161,9 @@ extern void SDclipName(char res[SDnameLn], const char /* Allocate new spectral distribution function */ extern SDSpectralDF *SDnewSpectralDF(int nc); +/* Add component(s) to spectral distribution function */ +extern SDSpectralDF *SDaddComponent(SDSpectralDF *odf, int nadd); + /* Free a spectral distribution function */ extern void SDfreeSpectralDF(SDSpectralDF *df); @@ -171,9 +183,8 @@ extern SDData *SDgetCache(const char *bname); extern void SDfreeCumulativeCache(SDSpectralDF *df); /* Sample an individual BSDF component */ -extern SDError SDsampComponent(SDValue *sv, FVECT outVec, - const FVECT inVec, double randX, - SDComponent *sdc); +extern SDError SDsampComponent(SDValue *sv, FVECT ioVec, + double randX, SDComponent *sdc); /* Convert 1-dimensional random variable to N-dimensional */ extern void SDmultiSamp(double t[], int n, double randX); @@ -190,10 +201,10 @@ void SDdisk2square(double sq[2], double diskx, doubl */ /* Get BSDF from cache (or load and cache it on first call) */ -/* Report any problems to stderr and return NULL on failure */ +/* Report any problems to stderr (in English), return NULL on failure */ extern const SDData *SDcacheFile(const char *fname); -/* Free a BSDF from our cache (clear all if NULL) */ +/* Free a BSDF from our cache (clear all if sd==NULL) */ extern void SDfreeCache(const SDData *sd); /* Query projected solid angle resolution for non-diffuse BSDF direction(s) */ @@ -210,8 +221,7 @@ extern double SDdirectHemi(const FVECT inVec, int sflags, const SDData *sd); /* Sample BSDF direction based on the given random variable */ -extern SDError SDsampBSDF(SDValue *sv, FVECT outVec, - const FVECT inVec, double randX, +extern SDError SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd); /***************************************************************** @@ -219,7 +229,7 @@ extern SDError SDsampBSDF(SDValue *sv, FVECT outVec, * Directions may be passed unnormalized to these routines. */ -/* Compute World->BSDF transform from surface normal and up (Y) vector */ +/* Compute World->BSDF transform from surface normal and BSDF up vector */ extern SDError SDcompXform(RREAL vMtx[3][3], const FVECT sNrm, const FVECT uVec); @@ -230,71 +240,11 @@ extern SDError SDinvXform(RREAL iMtx[3][3], RREAL vMt extern SDError SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT inpVec); -/* System-specific BSDF loading routine (not part of our library) */ +/* Application-specific BSDF loading routine (not part of our library) */ extern SDData *loadBSDF(char *name); -/* System-specific BSDF error translator (not part of our library) */ +/* Application-specific BSDF error translator (not part of our library) */ extern char *transSDError(SDError ec); - -/*################################################################*/ -/*######### DEPRECATED DEFINITIONS AWAITING PERMANENT REMOVAL #######*/ -/* - * Header for BSDF i/o and access routines - */ - -#include "mat4.h" - /* up directions */ -typedef enum { - UDzneg=-3, - UDyneg=-2, - UDxneg=-1, - UDunknown=0, - UDxpos=1, - UDypos=2, - UDzpos=3 -} UpDir; - /* BSDF coordinate calculation routines */ - /* vectors always point away from surface */ - -typedef int b_vecf2(FVECT v, int n, void *cd); -typedef int b_ndxf2(FVECT v, void *cd); -typedef double b_radf2(int n, void *cd); - -/* Bidirectional Scattering Distribution Function */ -struct BSDF_data { - int ninc; /* number of incoming directions */ - int nout; /* number of outgoing directions */ - float dim[3]; /* width, height, thickness (meters) */ - char *mgf; /* geometric description (if any) */ - void *ib_priv; /* input basis private data */ - b_vecf2 *ib_vec; /* get input vector from index */ - b_ndxf2 *ib_ndx; /* get input index from vector */ - b_radf2 *ib_ohm; /* get input radius for index */ - void *ob_priv; /* output basis private data */ - b_vecf2 *ob_vec; /* get output vector from index */ - b_ndxf2 *ob_ndx; /* get output index from vector */ - b_radf2 *ob_ohm; /* get output radius for index */ - float *bsdf; /* scattering distribution data */ -}; /* bidirectional scattering distrib. func. */ - -#define getBSDF_incvec(v,b,i) (*(b)->ib_vec)(v,i,(b)->ib_priv) -#define getBSDF_incndx(b,v) (*(b)->ib_ndx)(v,(b)->ib_priv) -#define getBSDF_incohm(b,i) (*(b)->ib_ohm)(i,(b)->ib_priv) -#define getBSDF_outvec(v,b,o) (*(b)->ob_vec)(v,o,(b)->ob_priv) -#define getBSDF_outndx(b,v) (*(b)->ob_ndx)(v,(b)->ob_priv) -#define getBSDF_outohm(b,o) (*(b)->ob_ohm)(o,(b)->ob_priv) -#define BSDF_value(b,i,o) (b)->bsdf[(o)*(b)->ninc + (i)] - -extern struct BSDF_data *load_BSDF(char *fname); -extern void free_BSDF(struct BSDF_data *b); -extern int r_BSDF_incvec(FVECT v, struct BSDF_data *b, int i, - double rv, MAT4 xm); -extern int r_BSDF_outvec(FVECT v, struct BSDF_data *b, int o, - double rv, MAT4 xm); -extern int getBSDF_xfm(MAT4 xm, FVECT nrm, UpDir ud, char *xfbuf); - -/*######### END DEPRECATED DEFINITIONS #######*/ -/*################################################################*/ #ifdef __cplusplus }