Shadowrun: Awakened 29 September 2011 - Build 871
Functions
shade.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void add_light (point_light *)
void reset_lights (void)
flt shade_phong (ray *incident, vector *hit, vector *N, vector *L, flt specpower)
color shade_reflection (ray *, vector *, vector *, flt)
color shade_transmission (ray *, vector *, flt)
color shader (ray *)

Function Documentation

void add_light ( point_light )

Definition at line 78 of file shade.cpp.

References lightlist, and numlights.

Referenced by rt_light().

void reset_lights ( void  )

Definition at line 74 of file shade.cpp.

References numlights.

Referenced by rt_initialize().

                        {
  numlights=0;
}
flt shade_phong ( ray incident,
vector hit,
vector N,
vector L,
flt  specpower 
)

Definition at line 249 of file shade.cpp.

References ray::d, V, VAdd(), VDot(), VNorm(), and VScale().

Referenced by shader().

                                        {
  vector H, V;
  flt inten;

  V = incident->d;
  VScale(&V, -1.0);
  VAdd(&V, L, &H);
  VScale(&H, 0.5);   
  VNorm(&H);
  inten = VDot(N, &H);
  if (inten > 0.0) 
    inten = pow(inten, specpower);
  else 
    inten = 0.0;

  return inten;
} 
color shade_reflection ( ray ,
vector ,
vector ,
flt   
)

Definition at line 197 of file shade.cpp.

References ColorScale(), ray::d, ray::depth, EPSILON, FHUGE, ray::flags, ray::intstruct, ray::maxdist, ray::mbox, ray::o, Raypnt(), RT_RAY_REGULAR, ray::scene, ray::serial, trace(), VAddS(), vector::x, vector::y, and vector::z.

Referenced by shader().

                                                                               {
  ray specray;
  color col;
  vector R;
 
  VAddS(-2.0 * (incident->d.x * N->x + 
                incident->d.y * N->y + 
                incident->d.z * N->z), N, &incident->d, &R);

  specray.intstruct=incident->intstruct; /* what thread are we   */
  specray.depth=incident->depth - 1;   /* go up a level in recursion depth */
  specray.flags = RT_RAY_REGULAR;      /* infinite ray, to start with */
  specray.serial = incident->serial + 1; /* next serial number */
  specray.mbox = incident->mbox; 
  specray.o=*hit; 
  specray.d=R;                 /* reflect incident ray about normal */
  specray.o=Raypnt(&specray, EPSILON); /* avoid numerical precision bugs */
  specray.maxdist = FHUGE;             /* take any intersection */
  specray.scene=incident->scene;       /* global scenedef info */
  col=trace(&specray);                 /* trace specular reflection ray */ 

  incident->serial = specray.serial;    /* update the serial number */

  ColorScale(&col, specular);

  return col;
}
color shade_transmission ( ray ,
vector ,
flt   
)

Definition at line 226 of file shade.cpp.

References ColorScale(), ray::d, ray::depth, EPSILON, FHUGE, ray::flags, ray::intstruct, ray::maxdist, ray::mbox, ray::o, Raypnt(), RT_RAY_REGULAR, ray::scene, ray::serial, and trace().

Referenced by ext_volume_texture(), scalar_volume_texture(), and shader().

                                                                  {
  ray transray;
  color col;

  transray.intstruct=incident->intstruct; /* what thread are we   */
  transray.depth=incident->depth - 1;    /* go up a level in recursion depth */
  transray.flags = RT_RAY_REGULAR;       /* infinite ray, to start with */
  transray.serial = incident->serial + 1; /* update serial number */
  transray.mbox = incident->mbox;
  transray.o=*hit; 
  transray.d=incident->d;                /* ray continues along incident path */
  transray.o=Raypnt(&transray, EPSILON); /* avoid numerical precision bugs */
  transray.maxdist = FHUGE;              /* take any intersection */
  transray.scene=incident->scene;        /* global scenedef info */
  col=trace(&transray);                  /* trace transmission ray */  

  incident->serial = transray.serial;

  ColorScale(&col, trans);

  return col;
}
color shader ( ray )

Definition at line 83 of file shade.cpp.

References texture::ambient, color::b, scenedef::background, closest_intersection(), texture::col, ColorAccum(), ColorAddS(), ColorScale(), point_light::ctr, ray::d, texture::diffuse, ray::e, EPSILON, ray::flags, color::g, intersect_objects(), ray::intstruct, texture::islight, L, lightlist, ray::maxdist, ray::mbox, object::methods, N, object_methods::normal, numlights, ray::o, mission1::obj, texture::opacity, texture::phong, texture::phongexp, texture::phongtype, color::r, RAYPNT, reset_intersection(), RT_RAY_BOUNDED, RT_RAY_SHADOW, ray::s, ray::scene, ray::serial, shade_phong(), shade_reflection(), shade_transmission(), shadow_intersection(), texture::specular, point_light::tex, object::tex, texture::texfunc, VDOT, VSUB, vector::x, vector::y, and vector::z.

Referenced by trace().

                             {
  color col, diffuse, phongcol; 
  vector N, L, hit;
  ray shadowray;
  flt inten, t, Llen;
  object * obj;
  int numints, i;
  point_light * li;


  numints=closest_intersection(&t, &obj, incident->intstruct);  
        /* find the number of intersections */
                /* and return the closest one.      */

  if (numints < 1) {         
    /* if there weren't any object intersections then return the */
    /* background color for the pixel color.                     */
    return incident->scene->background;
  }

  if (obj->tex->islight) {  /* if the current object is a light, then we  */
    return obj->tex->col;   /* will only use the objects ambient color    */
  }

  RAYPNT(hit, (*incident), t)       /* find the point of intersection from t */ 
  obj->methods->normal(obj, &hit, incident, &N);  /* find the surface normal */

  /* execute the object's texture function */
  col = obj->tex->texfunc(&hit, obj->tex, incident); 

  diffuse.r = 0.0; 
  diffuse.g = 0.0; 
  diffuse.b = 0.0; 
  phongcol = diffuse;

  if ((obj->tex->diffuse > 0.0) || (obj->tex->phong > 0.0)) {  
    for (i=0; i<numlights; i++) {   /* loop for light contributions */
      li=lightlist[i];              /* set li=to the current light  */
      VSUB(li->ctr, hit, L)         /* find the light vector        */

      /* calculate the distance to the light from the hit point */
      Llen = sqrt(L.x*L.x + L.y*L.y + L.z*L.z) + EPSILON;

      L.x /= Llen; /* normalize the light direction vector */
      L.y /= Llen;
      L.z /= Llen;

      VDOT(inten, N, L)             /* light intensity              */

      /* add in diffuse lighting for this light if we're facing it */ 
      if (inten > 0.0) {            
        /* test for a shadow */
        shadowray.intstruct = incident->intstruct;
        shadowray.flags = RT_RAY_SHADOW | RT_RAY_BOUNDED; 
        incident->serial++;
        shadowray.serial = incident->serial;
        shadowray.mbox = incident->mbox;
        shadowray.o   = hit;
        shadowray.d   = L;      
        shadowray.maxdist = Llen;
        shadowray.s   = hit;
        shadowray.e = li->ctr;
        shadowray.scene = incident->scene;
        reset_intersection(incident->intstruct);
        intersect_objects(&shadowray);

        if (!shadow_intersection(incident->intstruct, Llen)) {
          /* XXX now that opacity is in the code, have to be more careful */
          ColorAddS(&diffuse, &li->tex->col, inten);

          /* phong type specular highlights */
          if (obj->tex->phong > 0.0) {
            flt phongval;
            phongval = shade_phong(incident, &hit, &N, &L, obj->tex->phongexp); 
            if (obj->tex->phongtype) 
              ColorAddS(&phongcol, &col, phongval);
            else
              ColorAddS(&phongcol, &(li->tex->col), phongval);
          }
        }
      }  
    } 
  }

  ColorScale(&diffuse, obj->tex->diffuse);

  col.r *= (diffuse.r + obj->tex->ambient); /* do a product of the */
  col.g *= (diffuse.g + obj->tex->ambient); /* diffuse intensity with  */
  col.b *= (diffuse.b + obj->tex->ambient); /* object color + ambient  */

  if (obj->tex->phong > 0.0) {
    ColorAccum(&col, &phongcol);
  }

  /* spawn reflection rays if necessary */
  /* note: this will overwrite the old intersection list */
  if (obj->tex->specular > 0.0) {    
    color specol;
    specol = shade_reflection(incident, &hit, &N, obj->tex->specular);
    ColorAccum(&col, &specol);
  }

  /* spawn transmission rays / refraction */
  /* note: this will overwrite the old intersection list */
  if (obj->tex->opacity < 1.0) {      
    color transcol;
    transcol = shade_transmission(incident, &hit, 1.0 - obj->tex->opacity);
    ColorAccum(&col, &transcol);
  }

  return col;    /* return the color of the shaded pixel... */
}

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net