GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/echo/lightEcho.c Lines: 0 25 0.0 %
Date: 2017-05-26 Branches: 0 6 0.0 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "echo.h"
25
#include "privateEcho.h"
26
27
/*
28
******* echoLightPosition()
29
**
30
** sets "pos" to xyz position for current sample of given light
31
*/
32
void
33
echoLightPosition(echoPos_t pos[3], echoObject *light,
34
                  echoThreadState *tstate) {
35
  char me[]="echoLightPos";
36
  echoPos_t x, y;
37
  echoRectangle *rectLight;
38
39
  x = tstate->jitt[0 + 2*echoJittableLight] + 0.5;
40
  y = tstate->jitt[1 + 2*echoJittableLight] + 0.5;
41
  switch(light->type) {
42
  case echoTypeRectangle:
43
    rectLight = RECTANGLE(light);
44
    ELL_3V_SCALE_ADD3(pos, 1, rectLight->origin,
45
                     x, rectLight->edge0,
46
                     y, rectLight->edge1);
47
    break;
48
  default:
49
    fprintf(stderr, "%s: currently only support echoTypeRectangle lights", me);
50
    break;
51
  }
52
  return;
53
}
54
55
/*
56
******* echoLightColor()
57
**
58
** sets "col" to RGB color for current sample of given light, which
59
** is at distance Ldist.  Knowing distance allows computation of the
60
** inverse square fall-off of light intensity
61
*/
62
void
63
echoLightColor(echoCol_t rgb[3], echoPos_t Ldist,
64
               echoObject *light, echoRTParm *parm, echoThreadState *tstate) {
65
  echoCol_t rgba[4], falloff;
66
  echoPos_t x, y;
67
68
  x = tstate->jitt[0 + 2*echoJittableLight] + 0.5;
69
  y = tstate->jitt[1 + 2*echoJittableLight] + 0.5;
70
  if (light->ntext) {
71
    echoTextureLookup(rgba, light->ntext, x, y, parm);
72
    ELL_3V_COPY(rgb, rgba);
73
  } else {
74
    ELL_3V_COPY(rgb, light->rgba);
75
  }
76
  ELL_3V_SCALE(rgb, light->mat[echoMatterLightPower], rgb);
77
  if (light->mat[echoMatterLightUnit]) {
78
    falloff = AIR_CAST(echoCol_t, light->mat[echoMatterLightUnit]/Ldist);
79
    falloff *= falloff;
80
    ELL_3V_SCALE(rgb, falloff, rgb);
81
  }
82
83
  return;
84
}
85
86
void
87
echoEnvmapLookup(echoCol_t rgb[3], echoPos_t norm[3], Nrrd *envmap) {
88
  int qn;
89
  float *data;
90
91
#if ECHO_POS_FLOAT
92
  qn = limnVtoQN_f[limnQN16octa](norm);
93
#else
94
  qn = limnVtoQN_d[limnQN16octa](norm);
95
#endif
96
  data = (float*)(envmap->data) + 3*qn;
97
  ELL_3V_COPY(rgb, data);
98
}
99