clray

diff rt.cl @ 20:63a6b46f58a0

fixed
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 09 Aug 2010 12:55:40 +0100
parents 8baea9b66b50
children bd6c2b25f6e7
line diff
     1.1 --- a/rt.cl	Mon Aug 09 06:45:57 2010 +0100
     1.2 +++ b/rt.cl	Mon Aug 09 12:55:40 2010 +0100
     1.3 @@ -5,7 +5,6 @@
     1.4  	int num_faces, num_lights;
     1.5  	int max_iter;
     1.6  	float4 ambient;
     1.7 -	int dbg;
     1.8  };
     1.9  
    1.10  struct Vertex {
    1.11 @@ -56,7 +55,6 @@
    1.12  #define MIN_ENERGY	0.001
    1.13  #define EPSILON		1e-6
    1.14  
    1.15 -//float4 trace(struct Ray ray, struct Scene *scn);
    1.16  float4 shade(struct Ray ray, struct Scene *scn, const struct SurfPoint *sp);
    1.17  bool find_intersection(struct Ray ray, const struct Scene *scn, struct SurfPoint *sp);
    1.18  bool intersect(struct Ray ray, global const struct Face *face, struct SurfPoint *sp);
    1.19 @@ -74,17 +72,10 @@
    1.20  		global const struct Light *lights,
    1.21  		global const struct Ray *primrays,
    1.22  		global const float *xform,
    1.23 -		global const float *invtrans,
    1.24 -		global struct Face *outfaces)
    1.25 +		global const float *invtrans)
    1.26  {
    1.27  	int idx = get_global_id(0);
    1.28  
    1.29 -	if(!idx) {
    1.30 -		for(int i=0; i<rinf->num_faces; i++) {
    1.31 -			outfaces[i] = faces[i];
    1.32 -		}
    1.33 -	}
    1.34 -
    1.35  	struct Scene scn;
    1.36  	scn.ambient = rinf->ambient;
    1.37  	scn.faces = faces;
    1.38 @@ -96,8 +87,6 @@
    1.39  	struct Ray ray = primrays[idx];
    1.40  	transform_ray(&ray, xform, invtrans);
    1.41  
    1.42 -	//fb[idx] = trace(ray, &scn);
    1.43 -
    1.44  	float4 pixel = (float4)(0, 0, 0, 0);
    1.45  	float4 energy = (float4)(1.0, 1.0, 1.0, 1.0);
    1.46  	int iter = 0;
    1.47 @@ -121,19 +110,6 @@
    1.48  	fb[idx] = pixel;
    1.49  }
    1.50  
    1.51 -/*float4 trace(struct Ray ray, struct Scene *scn)
    1.52 -{
    1.53 -	float4 color;
    1.54 -	struct SurfPoint sp;
    1.55 -
    1.56 -	if(find_intersection(ray, scn, &sp)) {
    1.57 -		color = shade(ray, scn, &sp);
    1.58 -	} else {
    1.59 -		color = (float4)(0, 0, 0, 0);
    1.60 -	}
    1.61 -	return color;
    1.62 -}*/
    1.63 -
    1.64  float4 shade(struct Ray ray, struct Scene *scn, const struct SurfPoint *sp)
    1.65  {
    1.66  	float4 norm = sp->norm;
    1.67 @@ -162,8 +138,8 @@
    1.68  			float diff = fmax(dot(ldir, norm), 0.0f);
    1.69  			dcol += sp->mat.kd * diff * scn->lights[i].color;
    1.70  
    1.71 -			//float spec = powr(fmax(dot(ldir, vref), 0.0f), mat.spow);
    1.72 -			//scol += sp->mat.ks * spec * scn->lights[i].color;
    1.73 +			float spec = powr(fmax(dot(ldir, vref), 0.0f), sp->mat.spow);
    1.74 +			scol += sp->mat.ks * spec * scn->lights[i].color;
    1.75  		}
    1.76  	}
    1.77  
    1.78 @@ -221,14 +197,14 @@
    1.79  	float4 bc = calc_bary(pt, face, norm);
    1.80  	float bc_sum = bc.x + bc.y + bc.z;
    1.81  
    1.82 -	if(bc_sum < 0.0 || bc_sum > 1.0 + EPSILON) {
    1.83 +	if(bc_sum < 1.0 - EPSILON || bc_sum > 1.0 + EPSILON) {
    1.84  		return false;
    1.85  		bc *= 1.2;
    1.86  	}
    1.87  
    1.88  	sp->t = t;
    1.89  	sp->pos = pt;
    1.90 -	sp->norm = norm;
    1.91 +	sp->norm = -normalize(face->v[0].normal * bc.x + face->v[1].normal * bc.y + face->v[2].normal * bc.z);
    1.92  	sp->obj = face;
    1.93  	sp->dbg = bc;
    1.94  	return true;