/* 
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * Contributors: Matt Ebb
 *
 * ***** END GPL LICENSE BLOCK *****
 */

struct VlakRen;
struct ShadeInput;
struct Render;

typedef struct ShadeInfo
{
	float P[3];				/* point coordinate */
	float dPdx[3];			/* derivative of P in screenspace */
	float dPdy[3];			/* derivative of P in screenspace */
	float N[3];				/* normal */
	float I[3];				/* normalized incoming view vector */
	
	/* *** irradiance sample variables *** */
	/* only available in illuminance loop  */
	float Pl[3];			/* position of irradiance sample (i.e. point on lamp) */
	float L[3];				/* vector from Pl to P */
	float Ln[3];			/* Normalized L */
	float NdotLn;			/* Dot product between N and Ln */
	/* *** end irradiance sample variables *** */
	
	int thread;
	int depth;				/* raytrace depth: 0 is first scanline hit, 1+ are ray bounces. */
	int sample, samplenr;	/* for shadow buffers */

	struct VlakRen *face;
	struct ObjectInstanceRen *obi;
} ShadeInfo;


void ray_shadeinput_init(struct ShadeInput *shi, struct ShadeInput *shi_orig);
void trace_color_shadeinput(struct Render *re, struct ShadeInput *shi, float *vec, float *col);
int trace_color(struct Render *re, struct ShadeInfo *si, float *vec, float *col);
float trace_occlusion(struct Render *re, struct VlakRen *vlr, struct ObjectInstanceRen *obi, float *from, float *to, float *vec);

void camera_to_local(float *v_local, float *v_cam, float *n, float *sn, float *tn);
void local_to_camera(float *v_cam, const float *v_local, const float *n, const float *sn, const float *tn);

inline float CosThetaf(const float *w);
inline float SinThetaf(const float *w);
inline float SinTheta2f(const float *w);
inline float CosPhif(const float *w);
inline float SinPhi(const float *w);
inline int SameHemisphere(const float *w, const float *wp);
float schlick_kr(const float cosalpha, const float ior);

/* camera space */
void reflect(float *ref, float *n, float *view);

float smoothstep(float a, float b, float x);
float distancesquared(float *a, float *b);

float rgb_to_luminance(float r, float g, float b);


