Back to index

radiance  4R0+20100331
t_func.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: t_func.c,v 2.7 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  t_func.c - routine for procedural textures.
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "ray.h"
00011 #include  "func.h"
00012 #include  "rtotypes.h"
00013 
00014 /*
00015  *     A procedural texture perturbs the surface normal
00016  *  at the point of intersection with an object.  It has
00017  *  the form:
00018  *
00019  *     modifier texfunc name
00020  *     4+ xvarname yvarname zvarname filename xf
00021  *     0
00022  *     n A1 A2 ..
00023  *
00024  *  Filename is the name of the file where the variable definitions
00025  *  can be found.  The list of real arguments can be accessed by
00026  *  definitions in the file.  The xf is a transformation to get
00027  *  from the original coordinates to the current coordinates.
00028  */
00029 
00030 
00031 extern int
00032 t_func(                     /* compute texture for ray */
00033        register OBJREC  *m,
00034        register RAY  *r
00035 )
00036 {
00037        FVECT  disp;
00038        double  d;
00039        register MFUNC  *mf;
00040        register int  i;
00041 
00042        if (m->oargs.nsargs < 4)
00043               objerror(m, USER, "bad # arguments");
00044        mf = getfunc(m, 3, 0x7, 1);
00045        setfunc(m, r);
00046        errno = 0;
00047        for (i = 0; i < 3; i++) {
00048               disp[i] = evalue(mf->ep[i]);
00049               if (errno == EDOM || errno == ERANGE) {
00050                      objerror(m, WARNING, "compute error");
00051                      return(0);
00052               }
00053        }
00054        if (mf->f != &unitxf)
00055               multv3(disp, disp, mf->f->xfm);
00056        if (r->rox != NULL) {
00057               multv3(disp, disp, r->rox->f.xfm);
00058               d = 1.0 / (mf->f->sca * r->rox->f.sca);
00059        } else
00060               d = 1.0 / mf->f->sca;
00061        for (i = 0; i < 3; i++)
00062               r->pert[i] += disp[i] * d;
00063        return(0);
00064 }