home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * sphereenv -
- * Make a spherical environment map from a cubical env map
- * by rendering a reflective sphere.
- *
- * Paul Haeberli - 1987
- */
- #include "texture.h"
-
- TEXTURE *tm;
- int doreflect;
- int size, samples;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- float vr, vg, vb;
- float tr, tg, tb;
- int x, y;
- IMAGE *image;
- int i;
- vect pos, c;
- short *rbuf, *gbuf, *bbuf;
-
- if(argc<5) {
- fprintf(stderr,"usage: sphereenv size samples file.env file.rgb [-s]\n");
- exit(1);
- }
- if(argc>5) {
- if(strcmp(argv[5],"-s") == 0)
- doreflect = 1;
- }
- size = atoi(argv[1]);
- samples = atoi(argv[2]);
- tm = tmopen(argv[3]);
- if(!tm) {
- printf("can't open environment map.\n");
- exit(1);
- }
- rbuf = (short *)malloc(size*sizeof(short));
- gbuf = (short *)malloc(size*sizeof(short));
- bbuf = (short *)malloc(size*sizeof(short));
- image = iopen(argv[4],"w",RLE(1),3,size,size,3);
- for(y=0; y<size; y++) {
- for(x=0; x<size; x++) {
- tr = tg = tb = 0.0;
- for(i=0; i<samples; i++) {
- if(samples>1) {
- pos.x = (x+frand())/size-0.5;
- pos.y = (y+frand())/size-0.5;
- pos.z = 0;
- } else {
- pos.x = (float)x/size-0.5;
- pos.y = (float)y/size-0.5;
- pos.z = 0.0;
- }
- shadesphere(&pos,&c);
- tr += c.x;
- tg += c.y;
- tb += c.z;
- }
- rbuf[x] = 255*tr/samples;
- gbuf[x] = 255*tg/samples;
- bbuf[x] = 255*tb/samples;
- }
- putrow(image,rbuf,y,0);
- putrow(image,gbuf,y,1);
- putrow(image,bbuf,y,2);
- tpercentdone(100.0*y/(size-1));
- }
- iclose(image);
- }
-
- shadesphere(p,c)
- vect *p, *c;
- {
- vect e, v, r;
-
- vscale(p,2.02);
- if(spheretovect(p,&v)) {
- if(doreflect) {
- e.x = 0.0;
- e.y = 0.0;
- e.z = 1.0;
- vreflect(&e,&v,&r);
- v = r;
- }
- lookx(&v);
- envsample(tm,&v,c);
- } else
- vzero(c);
- }
-
- lookx(v)
- vect *v;
- {
- float temp;
-
- temp = v->z; /* to make us look down the x axis */
- v->z = v->y;
- v->y = -v->x;
- v->x = temp;
- }
-