Skip to content

Commit

Permalink
reflection slightly better but strange colours maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-george committed Mar 11, 2018
1 parent c66fa82 commit 4f1a65d
Showing 1 changed file with 57 additions and 17 deletions.
74 changes: 57 additions & 17 deletions raw.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ void main(void)
Expand Down Expand Up @@ -124,6 +132,14 @@ void main() {
Expand Down Expand Up @@ -177,6 +193,14 @@ void main(void)
Expand Down Expand Up @@ -224,6 +248,14 @@ void main ()
Expand Down Expand Up @@ -252,7 +284,7 @@ uniform mat3 normalMatrix; //mv matrix without translation
const int raytraceDepth = 3;
const int numSpheres = 6;
const float decay = 0.3;
const vec3 lightSource = vec3(6,4,3);
vec3 lightSource = vec3(6,4,3);
// Blinn-Phong
vec3 diffuse = vec3(0.1,0.1,0.1);
vec3 specular = vec3(0.1,0.1,0.1);
Expand Down Expand Up @@ -335,12 +367,14 @@ void sphere_intersect(Sphere sph, inout Ray ray, inout Intersection intersect)
u = u2;
}
if (u>0){
intersect.point = u*ray.dir;
intersect.point = ray.origin + u*ray.dir;
intersect.hit = 1;
intersect.normal = normalize(intersect.point - sph.centre);
if (u<intersect.t){
intersect.colour = (sph.transparency)*intersect.colour+sph.colour;
intersect.bp_colour = (sph.transparency)*intersect.bp_colour+blinn_phong(intersect.colour,intersect.point,intersect.normal);
intersect.colour = (sph.transparency)*intersect.colour
+sph.colour;
intersect.bp_colour = (sph.transparency)*intersect.bp_colour
+blinn_phong(intersect.colour,intersect.point,intersect.normal);
intersect.t=u;
}
}
Expand All @@ -358,12 +392,10 @@ void plane_intersect(Plane pl, inout Ray ray, inout Intersection intersect)
vec3 p = u*ray.dir;
intersect.point = ray.origin + p;
vec3 col = pl.colour;
if (!bool(
(int((p.x+1024)*4)+int((p.z+1024)*4))%2)
){
col = vec3(0,0,0);
if (!bool((int((p.x+1024)*4)+int((p.z+1024)*4))%2)){
col = -pl.colour;
}
intersect.normal = pl.normal;
intersect.normal = normalize(pl.normal);
intersect.colour += col;
intersect.bp_colour += blinn_phong(intersect.colour,intersect.point,intersect.normal);
Expand Down Expand Up @@ -416,12 +448,11 @@ vec3 computeShadow(in Intersection intersect)
i2.t = FLT_MAX;
// see if there are any intersections
Intersect(shadowRay, i2);
if (!bool(i2.hit)){
return intersect.bp_colour;
}
else {
return intersect.colour;
return intersect.bp_colour;
}
}
Expand Down Expand Up @@ -468,23 +499,24 @@ void main()
vec4 colour = vec4(0,0,0,1);
Ray ray;
ray.origin = vec3(0,0,0); //((mvMatrixScene)*vec4(0,0,0,1)).xyz;// vec3(0,0,0);//(mvMatrix*vec4(0,0,0,1)).xyz;
ray.origin = vec3(0,0,0);//(mvMatrix*vec4(0,0,0,1)).xyz;
ray.dir = normalize((mvMatrixScene)*vec4(dir,0)).xyz;
lightSource = (vec4(6,4,3,1)).xyz;
float closest = 1.0/0.0;
Intersection i;
i.t = closest;
i.t = closest;
for(int d = 0; d < raytraceDepth;d++){
ray.depth = d;
Intersect(ray,i);
if (i.hit == 1) {
if (i.t<closest){
closest = i.t;
colour += (pow(decay,pow(d,2)))*vec4(computeShadow(i),1);//pow(decay,pow(d,2))*vec4(blinn_phong(i.colour,i.point,i.normal,true),1);
colour += (pow(decay,pow(d,2)))*vec4(i.bp_colour,1);//pow(decay,pow(d,2))*vec4(blinn_phong(i.colour,i.point,i.normal,true),1);
}
ray.origin = i.point + epsilon * i.normal;
ray.dir = reflect(ray.dir,i.normal);
ray.origin = ((mvMatrixScene)*(vec4(i.point + epsilon * i.normal,0))).xyz;
ray.dir = normalize(((mvMatrixScene)*vec4(normalize(reflect(ray.dir,i.normal)),0)).xyz);
} else {
break;
}
Expand All @@ -509,6 +541,14 @@ void main()
Expand Down

0 comments on commit 4f1a65d

Please sign in to comment.