This file is indexed.

/usr/share/k3d/shaders/k3d_reflections.h is in k3d-data 0.8.0.3-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/************************************************************************
 * reflections.h - Functions which compute reflected light by either
 *                 ray tracing or environment mapping.
 *
 * Author: Larry Gritz (gritzl@acm.org)
 *
 * $Revision: 1.1 $    $Date: 2004/05/19 18:15:20 $
 *
 ************************************************************************/


#ifndef REFLECTIONS_H
#define REFLECTIONS_H

#include "k3d_filterwidth.h"
#include "k3d_raysphere.h"


/* ReflMap() - Use a reflection map for reflections in flat objects.
 * Inputs are:
 *    reflname - filename of reflection map
 *    P - origin of traced ray
 *    blur - amount of additional blur to add to environment map
 * Outputs are:
 *    return value - the color of incoming light
 *    alpha - opacity of reflection map lookup in the direction R.
 * Warning -  the texture call itself takes derivatives, causing
 * trouble if called inside a loop or varying conditional!  Be cautious.
 */
color ReflMap ( string reflname;  point P; float blur;
                output float alpha; )
{
    /* Transform to the space of the environment map */
    point Pndc = transform ("NDC", P);
    float x = xcomp(Pndc), y = 1-ycomp(Pndc);
    alpha = float texture (reflname[3], x, y, "blur", blur, "fill", 1);
    return color texture (reflname, x, y, "blur", blur);
}



/* Environment() - A replacement for ordinary environment() lookups, this
 * function ray traces against an environment sphere of known, finite 
 * radius.  Inputs are:
 *    envname - filename of environment map
 *    envspace - name of space environment map was made in
 *    envrad - approximate supposed radius of environment sphere
 *    P, R - position and direction of traced ray
 *    blur - amount of additional blur to add to environment map
 * Outputs are:
 *    return value - the color of incoming environment light
 *    alpha - opacity of environment map lookup in the direction R.
 * Warning -  the environment call itself takes derivatives, causing
 * trouble if called inside a loop or varying conditional!  Be cautious.
 */
color Environment ( string envname, envspace;  uniform float envrad;
                    point P;  vector R;  float blur; output float alpha;)
{
    /* Transform to the space of the environment map */
    point Psp = transform (envspace, P);
    vector Rsp = normalize (vtransform (envspace, R));
    uniform float r2 = envrad * envrad;
    /* Clamp the position to be *inside* the environment sphere */
    if ((vector Psp).(vector Psp) > r2)
        Psp = point (envrad * normalize (vector Psp));
    float t0, t1;
    if (raysphere (Psp, Rsp, envrad, 1.0e-4, t0, t1) > 0)
	Rsp = vector (Psp + t0 * Rsp);
    alpha = float environment (envname[3], Rsp, "blur", blur, "fill", 1);
    return color environment (envname, Rsp, "blur", blur);
}




/* RayTrace() - A fancy ray trace routine, particularly suitable for
 * use with the "ray server."  Tries to sample over the surface
 * element and over the varying ray spread due to surface curvature.
 * An ordinary call to trace would point sample the environment in a
 * very simplistic way.  This function takes the size of the surface
 * facet and curvature of the surface into account, and lets you
 * sample the space with multiple rays.
 * 
 * Inputs:
 *    P - surface position
 *    Rdir - the unit-length reflection direction.
 *    blur - reflection blurriness; 0 = sharp reflection
 *    jitter - when 1, fully jitter the stochastic ray directions.  Lower
 *          numbers jitter less, 0 doesn't jitter.  Lowering jitter may help
 *          alleviate "sparkling" due to animation with low nrays.
 *    nsamples - number of rays with which to sample.  Larger numbers will
 *          yield better-sampled reflections, but will be more expensive.
 *          Note that the function reduces this number for secondary rays,
 *          assuming that the distribution from primary rays will be
 *          sufficient!
 * Return value: the average of the trace calls.
 * 
 * Warning!!! This function takes derivatives to find out the ray spread!
 * This can cause trouble if RayTrace() is called inside a loop or varying
 * conditional!  Be cautious.
 */
color
RayTrace (point P;  vector Rdir;  float Kr, blur, jitter;  
          uniform float nsamples;  output float alpha;)
{
#if (defined(BMRT) || defined(RAYSERVER_H))
    float rand () {
        extern float jitter;
        return (raylevel()==0) ? (0.5 + jitter * (float random() - 0.5)) : 0.5;
    }
    extern float du, dv;
    color C, Ct;
    float hitdist; point Phit, Pmiss;  vector Nhit, Rmiss;
    float bluramt = blur + filterwidthp(Rdir);
    uniform float nrays = (raylevel() == 0 ? max(1,ceil(sqrt(nsamples))) : 1);
    vector Tu = Du(P) * (1.5 * du); /* overblur just a tad... */
    vector Tv = Dv(P) * (1.5 * dv);
    if (Kr < 0.0001) {
	C = 0;
    } else if (bluramt > 0 || nrays > 1) {
        /* Construct orthogonal components to Rdir */
        vector uoffset = blur * normalize (vector (zcomp(Rdir) - ycomp(Rdir),
                                                   xcomp(Rdir) - zcomp(Rdir),
                                                   ycomp(Rdir) - xcomp(Rdir)));
        vector voffset = Rdir ^ uoffset;
        uniform float i, j;
        C = 0;  alpha = 0;
        for (i = 0;  i < nrays;  i += 1) {
            for (j = 0;  j < nrays;  j += 1) {
                /* Add a random offset to the smooth reflection vector */
                vector R = Rdir + ((i + rand())/nrays - 0.5) * uoffset +
                                  ((j + rand())/nrays - 0.5) * voffset;
		R = normalize(R);
                point Pray = P +  ((j + rand())/nrays - 0.5) * Tu +
                                  ((i + rand())/nrays - 0.5) * Tv;
#pragma nolint 3  /* this call intentionally passes uninitialized vars */
		fulltrace (Pray, R, Ct, hitdist, Phit, Nhit, Pmiss, Rmiss);
		C += Ct;
		alpha += 1 - step(1.0e10,hitdist);
            }
        }
	uniform float totrays = nrays*nrays;
        C /= totrays;   alpha /= totrays;
    } else {
        /* No blur or curvature, just do a simple trace */
#pragma nolint 2  /* this call intentionally passes uninitialized vars */
	fulltrace (P, Rdir, C, hitdist, Phit, Nhit, Pmiss, Rmiss);
	alpha = 1 - step(1.0e10,hitdist);
    }
    return C;
#else
    return color 0;
#endif
}





#define ENVPARAMS \
        envname, envspace, envrad, rayjitter, raysamples

#define DECLARE_ENVPARAMS                           \
        string envname, envspace;                   \
        uniform float envrad, rayjitter, raysamples

#define DECLARE_DEFAULTED_ENVPARAMS                                 \
        string envname = "", envspace = "world";                    \
        uniform float envrad = 100, rayjitter = 0, raysamples = 1



color
SampleEnvironment (point P;  vector R;  float Kr, blur;  DECLARE_ENVPARAMS;)
{
    color C = 0;
    float alpha;
    if (envname != "") {
	if (envspace == "NDC")
	    C = ReflMap (envname, P, blur, alpha);
	else
	    C = Environment (envname, envspace, envrad, P, R, blur, alpha);
    }
#if (defined(BMRT) || defined(RAYSERVER_H))
    color Cray = RayTrace (P, R, Kr, sqrt(blur), rayjitter, raysamples, alpha);
    C = Cray + (1-alpha) * C;
#endif
    return Kr * C;
}




#endif /* defined(REFLECTIONS_H) */