3 |
|
* bsdf.h |
4 |
|
* |
5 |
|
* Declarations for bidirectional scattering distribution functions. |
6 |
– |
* Assumes <stdio.h> already included. |
6 |
|
* |
7 |
|
* A material is oriented in right-hand coordinate system with X-axis |
8 |
|
* in the surface plane pointed to the right as seen from the front. |
22 |
|
#ifndef _BSDF_H_ |
23 |
|
#define _BSDF_H_ |
24 |
|
|
25 |
+ |
#include "platform.h" |
26 |
|
#include "fvect.h" |
27 |
|
#include "ccolor.h" |
28 |
|
|
30 |
|
extern "C" { |
31 |
|
#endif |
32 |
|
|
33 |
– |
#ifdef _WIN32 |
34 |
– |
#define strcasecmp stricmp |
35 |
– |
#endif |
36 |
– |
|
33 |
|
#define SDnameLn 128 /* maximum BSDF name length */ |
34 |
|
#define SDmaxCh 3 /* maximum # spectral channels */ |
35 |
|
|
54 |
|
typedef enum {SDEnone=0, SDEmemory, SDEfile, SDEformat, SDEargument, |
55 |
|
SDEdata, SDEsupport, SDEinternal, SDEunknown} SDError; |
56 |
|
|
57 |
< |
/* English ASCII strings corresponding to ennumerated errors */ |
57 |
> |
/* English strings corresponding to ennumerated errors */ |
58 |
|
extern const char *SDerrorEnglish[]; |
59 |
|
|
60 |
< |
/* Additional information on last error (ASCII English) */ |
60 |
> |
/* Pointer to error list in preferred language */ |
61 |
> |
extern const char **SDerrorList; |
62 |
> |
|
63 |
> |
/* Additional information on last error (generally in English) */ |
64 |
|
extern char SDerrorDetail[]; |
65 |
|
|
66 |
|
/* Holder for BSDF value and spectral color */ |
83 |
|
typedef struct SDComp_s SDComponent; |
84 |
|
|
85 |
|
/* Methods needed to handle BSDF components (nothing is optional) */ |
86 |
< |
typedef const struct { |
86 |
> |
typedef struct { |
87 |
|
/* return non-diffuse BSDF */ |
88 |
< |
int (*getBSDFs)(float coef[SDmaxCh], const FVECT outVec, |
89 |
< |
const FVECT inVec, SDComponent *sdc); |
88 |
> |
int (*getBSDFs)(float coef[SDmaxCh], const FVECT inVec, |
89 |
> |
const FVECT outVec, SDComponent *sdc); |
90 |
|
/* query non-diffuse PSA for vector */ |
91 |
|
SDError (*queryProjSA)(double *psa, const FVECT v1, |
92 |
|
const RREAL *v2, int qflags, |
103 |
|
/* Structure to hold a spectral BSDF component (typedef SDComponent above) */ |
104 |
|
struct SDComp_s { |
105 |
|
C_COLOR cspec[SDmaxCh]; /* component spectral bases */ |
106 |
< |
SDFunc *func; /* methods for this component */ |
106 |
> |
const SDFunc *func; /* methods for this component */ |
107 |
|
void *dist; /* loaded distribution data */ |
108 |
|
SDCDst *cdList; /* cumulative distribution cache */ |
109 |
|
}; |
122 |
|
char matn[SDnameLn]; /* material name */ |
123 |
|
char makr[SDnameLn]; /* manufacturer */ |
124 |
|
char *mgf; /* geometric description (if any) */ |
125 |
< |
float dim[3]; /* width, height, thickness (meters) */ |
125 |
> |
double dim[3]; /* width, height, thickness (meters) */ |
126 |
|
SDValue rLambFront; /* diffuse front reflectance */ |
127 |
|
SDValue rLambBack; /* diffuse rear reflectance */ |
128 |
< |
SDValue tLamb; /* diffuse transmission */ |
128 |
> |
SDValue tLambFront; /* diffuse front transmittance */ |
129 |
> |
SDValue tLambBack; /* diffuse back transmittance */ |
130 |
|
SDSpectralDF *rf, *rb; /* non-diffuse BRDF components */ |
131 |
|
SDSpectralDF *tf, *tb; /* non-diffuse BTDF components */ |
132 |
|
} SDData; |
145 |
|
#define SDretainAll 2 /* also keep cumulative cache data */ |
146 |
|
|
147 |
|
extern int SDretainSet; /* =SDretainNone by default */ |
148 |
+ |
extern unsigned long SDmaxCache; /* =0 (unlimited) by default */ |
149 |
|
|
150 |
|
/***************************************************************** |
151 |
|
* The following routines are less commonly used by applications. |
153 |
|
|
154 |
|
#define SDisLoaded(sd) ((sd)->rLambFront.spec.flags != 0) |
155 |
|
|
156 |
< |
/* Report an error to the indicated stream (in English) */ |
157 |
< |
extern SDError SDreportEnglish(SDError ec, FILE *fp); |
156 |
> |
/* Report an error to the indicated stream */ |
157 |
> |
extern SDError SDreportError(SDError ec, FILE *fp); |
158 |
|
|
159 |
|
/* Shorten file path to useable BSDF name, removing suffix */ |
160 |
|
extern void SDclipName(char res[SDnameLn], const char *fname); |
190 |
|
/* Convert 1-dimensional random variable to N-dimensional */ |
191 |
|
extern void SDmultiSamp(double t[], int n, double randX); |
192 |
|
|
192 |
– |
/* Map a [0,1]^2 square to a unit radius disk */ |
193 |
– |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
194 |
– |
|
195 |
– |
/* Map point on unit disk to a unit square in [0,1]^2 range */ |
196 |
– |
extern void SDdisk2square(double sq[2], double diskx, double disky); |
197 |
– |
|
193 |
|
/***************************************************************** |
194 |
|
* The calls below are the ones most applications require. |
195 |
|
* All directions are assumed to be unit vectors. |
196 |
|
*/ |
197 |
|
|
198 |
|
/* Get BSDF from cache (or load and cache it on first call) */ |
199 |
< |
/* Report any problems to stderr (in English), return NULL on failure */ |
199 |
> |
/* Report any problems to stderr, return NULL on failure */ |
200 |
|
extern const SDData *SDcacheFile(const char *fname); |
201 |
|
|
202 |
|
/* Free a BSDF from our cache (clear all if sd==NULL) */ |
208 |
|
const SDData *sd); |
209 |
|
|
210 |
|
/* Return BSDF for the given incident and scattered ray vectors */ |
211 |
< |
extern SDError SDevalBSDF(SDValue *sv, const FVECT outVec, |
212 |
< |
const FVECT inVec, const SDData *sd); |
211 |
> |
extern SDError SDevalBSDF(SDValue *sv, const FVECT inVec, |
212 |
> |
const FVECT outVec, const SDData *sd); |
213 |
|
|
214 |
|
/* Compute directional hemispherical scattering at given incident angle */ |
215 |
|
extern double SDdirectHemi(const FVECT inVec, |