5 |
|
* Routines for Radiance -> OpenGL materials. |
6 |
|
*/ |
7 |
|
|
8 |
< |
/* ==================================================================== |
9 |
< |
* The Radiance Software License, Version 1.0 |
10 |
< |
* |
11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
13 |
< |
* |
14 |
< |
* Redistribution and use in source and binary forms, with or without |
15 |
< |
* modification, are permitted provided that the following conditions |
16 |
< |
* are met: |
17 |
< |
* |
18 |
< |
* 1. Redistributions of source code must retain the above copyright |
19 |
< |
* notice, this list of conditions and the following disclaimer. |
20 |
< |
* |
21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
22 |
< |
* notice, this list of conditions and the following disclaimer in |
23 |
< |
* the documentation and/or other materials provided with the |
24 |
< |
* distribution. |
25 |
< |
* |
26 |
< |
* 3. The end-user documentation included with the redistribution, |
27 |
< |
* if any, must include the following acknowledgment: |
28 |
< |
* "This product includes Radiance software |
29 |
< |
* (http://radsite.lbl.gov/) |
30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
31 |
< |
* (http://www.lbl.gov/)." |
32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
34 |
< |
* |
35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
36 |
< |
* and "The Regents of the University of California" must |
37 |
< |
* not be used to endorse or promote products derived from this |
38 |
< |
* software without prior written permission. For written |
39 |
< |
* permission, please contact [email protected]. |
40 |
< |
* |
41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
42 |
< |
* nor may "Radiance" appear in their name, without prior written |
43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
44 |
< |
* |
45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 |
< |
* SUCH DAMAGE. |
57 |
< |
* ==================================================================== |
58 |
< |
* |
59 |
< |
* This software consists of voluntary contributions made by many |
60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
62 |
< |
* <http://www.lbl.gov/>. |
63 |
< |
*/ |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
|
#include "radogl.h" |
11 |
|
|
12 |
|
int domats = 1; /* are we doing materials? */ |
13 |
|
|
14 |
+ |
extern lut_free_t freemtl; |
15 |
+ |
|
16 |
|
LUTAB mtab = LU_SINIT(free,freemtl); |
17 |
|
|
18 |
|
|
19 |
|
void |
20 |
< |
rgl_matclear() /* clean up materials */ |
20 |
> |
rgl_matclear(void) /* clean up materials */ |
21 |
|
{ |
22 |
|
lu_done(&mtab); |
23 |
|
domats = 1; |
25 |
|
|
26 |
|
|
27 |
|
MATREC * |
28 |
< |
getmatp(nam) /* find material record for modifier name */ |
29 |
< |
char *nam; |
28 |
> |
getmatp( /* find material record for modifier name */ |
29 |
> |
char *nam |
30 |
> |
) |
31 |
|
{ |
32 |
|
register LUENT *lup; |
33 |
|
|
40 |
|
|
41 |
|
|
42 |
|
int |
43 |
< |
o_default(o) /* default object is non-material modifier */ |
44 |
< |
register OBJREC *o; |
43 |
> |
o_default( /* default object is non-material modifier */ |
44 |
> |
register OBJREC *o |
45 |
> |
) |
46 |
|
{ |
47 |
|
register LUENT *lup; |
48 |
|
#ifdef DEBUG |
58 |
|
goto memerr; |
59 |
|
strcpy(lup->key, o->oname); |
60 |
|
} else if (lup->data != NULL) |
61 |
< |
freemtl((MATREC *)lup->data); |
61 |
> |
freemtl(lup->data); |
62 |
|
if ((lup->data = o->os) != NULL) /* make material reference */ |
63 |
|
((MATREC *)lup->data)->nlinks++; |
64 |
< |
return; |
64 |
> |
return(0); |
65 |
|
memerr: |
66 |
|
error(SYSTEM, "out of memory in o_default"); |
67 |
+ |
return(0); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
+ |
int |
72 |
+ |
o_unsupported( /* unsupported object primitive */ |
73 |
+ |
OBJREC *o |
74 |
+ |
) |
75 |
+ |
{ |
76 |
+ |
objerror(o, WARNING, "unsupported type"); |
77 |
+ |
return(0); |
78 |
+ |
} |
79 |
+ |
|
80 |
+ |
|
81 |
|
MATREC * |
82 |
< |
newmaterial(nam) /* get an entry for a new material */ |
83 |
< |
char *nam; |
82 |
> |
newmaterial( /* get an entry for a new material */ |
83 |
> |
char *nam |
84 |
> |
) |
85 |
|
{ |
86 |
|
register LUENT *lup; |
87 |
|
/* look it up (assign entry) */ |
93 |
|
goto memerr; |
94 |
|
strcpy(lup->key, nam); |
95 |
|
} else if (lup->data != NULL) |
96 |
< |
freemtl((MATREC *)lup->data); |
96 |
> |
freemtl(lup->data); |
97 |
|
lup->data = (char *)malloc(sizeof(MATREC)); |
98 |
|
if (lup->data == NULL) |
99 |
|
goto memerr; |
101 |
|
return((MATREC *)lup->data); |
102 |
|
memerr: |
103 |
|
error(SYSTEM, "out of memory in newmaterial"); |
104 |
+ |
return NULL; /* pro forma return */ |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
void |
109 |
< |
freemtl(mp) /* free a material */ |
148 |
< |
register MATREC *mp; |
109 |
> |
freemtl(void *p) /* free a material */ |
110 |
|
{ |
111 |
+ |
register MATREC *mp = (MATREC *)p; |
112 |
+ |
|
113 |
|
if (!--mp->nlinks) |
114 |
|
free((void *)mp); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
int |
119 |
< |
m_normal(o) /* compute normal material parameters */ |
120 |
< |
register OBJREC *o; |
119 |
> |
m_normal( /* compute normal material parameters */ |
120 |
> |
register OBJREC *o |
121 |
> |
) |
122 |
|
{ |
123 |
|
register MATREC *m; |
124 |
|
/* check arguments */ |
145 |
|
m->u.m.specexp = 2./(o->oargs.farg[4]*o->oargs.farg[4]); |
146 |
|
if (m->u.m.specexp > MAXSPECEXP) |
147 |
|
m->u.m.specexp = MAXSPECEXP; |
148 |
+ |
return(0); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
int |
153 |
< |
m_aniso(o) /* anisotropic material */ |
154 |
< |
register OBJREC *o; |
153 |
> |
m_aniso( /* anisotropic material */ |
154 |
> |
register OBJREC *o |
155 |
> |
) |
156 |
|
{ |
157 |
|
register MATREC *m; |
158 |
|
/* check arguments */ |
179 |
|
m->u.m.specexp = 2./(o->oargs.farg[4]*o->oargs.farg[5]); |
180 |
|
if (m->u.m.specexp > MAXSPECEXP) |
181 |
|
m->u.m.specexp = MAXSPECEXP; |
182 |
+ |
return(0); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
int |
187 |
< |
m_glass(o) /* glass material (hopeless) */ |
188 |
< |
OBJREC *o; |
187 |
> |
m_glass( /* glass material (hopeless) */ |
188 |
> |
OBJREC *o |
189 |
> |
) |
190 |
|
{ |
191 |
|
register MATREC *m; |
192 |
|
|
195 |
|
setcolor(m->u.m.ambdiff, 0., 0., 0.); |
196 |
|
setcolor(m->u.m.specular, .08, .08, .08); |
197 |
|
m->u.m.specexp = MAXSPECEXP; |
198 |
+ |
return(0); |
199 |
|
} |
200 |
|
|
201 |
|
|
223 |
|
scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[4]); |
224 |
|
} |
225 |
|
m->u.m.specexp = UNKSPECEXP; |
226 |
+ |
return(0); |
227 |
|
} |
228 |
|
|
229 |
|
|
244 |
|
/* guess the rest */ |
245 |
|
setcolor(m->u.m.specular, .1, .1, .1); |
246 |
|
m->u.m.specexp = UNKSPECEXP; |
247 |
+ |
return(0); |
248 |
|
} |
249 |
|
|
250 |
|
|
274 |
|
m->u.l.spotdir[0] = m->u.l.spotdir[1] = 0.; |
275 |
|
m->u.l.spotdir[2] = -1.; |
276 |
|
} |
277 |
+ |
return(0); |
278 |
|
} |
279 |
|
|
280 |
|
|
292 |
|
setcolor(m->u.m.specular, o->oargs.farg[0], |
293 |
|
o->oargs.farg[1], o->oargs.farg[2]); |
294 |
|
m->u.m.specexp = MAXSPECEXP; |
295 |
+ |
return(0); |
296 |
|
} |
297 |
|
|
298 |
|
|
307 |
|
setcolor(m->u.m.ambdiff, 0.2, 0.2, 0.2); |
308 |
|
setcolor(m->u.m.specular, 0.1, 0.1, 0.1); |
309 |
|
m->u.m.specexp = UNKSPECEXP; |
310 |
+ |
return(0); |
311 |
|
} |