Page Menu
Home
Search
Configure Global Search
Log In
Files
F2427
transmissivity-and-tir.post-orange.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Author
Ed Halley (halley)
Created
Nov 13 2013, 1:04 PM
Size
5 KB
Mime Type
text/x-diff
Engine
local-disk
Format
Raw Data
Handle
e0/97/3dffe774e61bf7882d84e0c9ca40
transmissivity-and-tir.post-orange.patch
View Options
Index: source/blender/render/intern/source/ray.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/ray.c,v
retrieving revision 1.70
diff -u -b -B -u -r1.70 ray.c
--- source/blender/render/intern/source/ray.c 2 Feb 2006 21:08:39 -0000 1.70
+++ source/blender/render/intern/source/ray.c 3 Feb 2006 14:12:48 -0000
@@ -1445,30 +1445,31 @@
}
-static void refraction(float *refract, float *n, float *view, float index)
+static int refraction(float *refract, float *n, float *view, float index)
{
float dot, fac;
VECCOPY(refract, view);
- index= 1.0/index;
dot= view[0]*n[0] + view[1]*n[1] + view[2]*n[2];
if(dot>0.0) {
+ index = 1.0/index;
fac= 1.0 - (1.0 - dot*dot)*index*index;
- if(fac<= 0.0) return;
+ if(fac<= 0.0) return 0;
fac= -dot*index + sqrt(fac);
}
else {
- index = 1.0/index;
fac= 1.0 - (1.0 - dot*dot)*index*index;
- if(fac<= 0.0) return;
+ if(fac<= 0.0) return 0;
fac= -dot*index - sqrt(fac);
}
refract[0]= index*view[0] + fac*n[0];
refract[1]= index*view[1] + fac*n[1];
refract[2]= index*view[2] + fac*n[2];
+
+ return 1;
}
/* orn = original face normal */
@@ -1515,6 +1516,25 @@
}
#endif
+static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr)
+{
+ float dx, dy, dz, d;
+
+ if (0 == (shi->mat->mode & (MA_RAYTRANSP|MA_ZTRA)))
+ return -1;
+
+ /* shi.co[] calculated by shade_ray() */
+ dx= shi->co[0] - is->start[0];
+ dy= shi->co[1] - is->start[1];
+ dz= shi->co[2] - is->start[2];
+ d= sqrt(dx*dx+dy*dy+dz*dz);
+
+ shr->alpha *= d;
+ if (shr->alpha > 1.0) shr->alpha= 1.0;
+
+ return d;
+}
+
/* the main recursive tracer itself */
static void traceray(ShadeInput *origshi, short depth, float *start, float *vec, float *col, VlakRen *vlr, int traflag)
{
@@ -1532,6 +1552,7 @@
isec.vlrorig= vlr;
if( d3dda(&isec) ) {
+ float d= 1.0;
shi.mask= origshi->mask;
shi.osatex= origshi->osatex;
@@ -1543,12 +1564,17 @@
shi.do_preview= 0;
shade_ray(&isec, &shi, &shr);
+ if (traflag & RAY_TRA)
+ d= shade_by_transmission(&isec, &shi, &shr);
if(depth>0) {
- if(shi.mat->mode & (MA_RAYTRANSP|MA_ZTRA) && shr.alpha!=1.0) {
- float f, f1, refract[3], tracol[4];
+ if(shi.mat->mode & (MA_RAYTRANSP|MA_ZTRA) && shr.alpha < 1.0) {
+ float nf, f, f1, refract[3], tracol[4];
+ tracol[0]= shi.r;
+ tracol[1]= shi.g;
+ tracol[2]= shi.b;
tracol[3]= col[3]; // we pass on and accumulate alpha
if(shi.mat->mode & MA_RAYTRANSP) {
@@ -1558,10 +1584,12 @@
norm[0]= - shi.vn[0];
norm[1]= - shi.vn[1];
norm[2]= - shi.vn[2];
- refraction(refract, norm, shi.view, shi.ang);
+ if (!refraction(refract, norm, shi.view, shi.ang))
+ reflection(refract, norm, shi.view, shi.vn);
}
else {
- refraction(refract, shi.vn, shi.view, shi.ang);
+ if (!refraction(refract, shi.vn, shi.view, shi.ang))
+ reflection(refract, shi.vn, shi.view, shi.vn);
}
traflag |= RAY_TRA;
traceray(origshi, depth-1, shi.co, refract, tracol, shi.vlr, traflag ^ RAY_TRAFLIP);
@@ -1570,9 +1598,10 @@
traceray(origshi, depth-1, shi.co, shi.view, tracol, shi.vlr, 0);
f= shr.alpha; f1= 1.0-f;
- fr= 1.0+ shi.mat->filter*(shi.r-1.0);
- fg= 1.0+ shi.mat->filter*(shi.g-1.0);
- fb= 1.0+ shi.mat->filter*(shi.b-1.0);
+ nf= d * shi.mat->filter;
+ fr= 1.0+ nf*(shi.r-1.0);
+ fg= 1.0+ nf*(shi.g-1.0);
+ fb= 1.0+ nf*(shi.b-1.0);
shr.diff[0]= f*shr.diff[0] + f1*fr*tracol[0];
shr.diff[1]= f*shr.diff[1] + f1*fg*tracol[1];
shr.diff[2]= f*shr.diff[2] + f1*fb*tracol[2];
@@ -1832,7 +1861,7 @@
shadfac[3]= (1.0-alpha)*shadfac[3];
}
-static void ray_trace_shadow_tra(Isect *is, int depth)
+static void ray_trace_shadow_tra(Isect *is, int depth, int traflag)
{
/* ray to lamp, find first face that intersects, check alpha properties,
if it has col[3]>0.0 continue. so exit when alpha is full */
@@ -1840,6 +1869,7 @@
ShadeResult shr;
if( d3dda(is)) {
+ float d= 1.0;
/* we got a face */
shi.mask= 1;
@@ -1847,9 +1877,11 @@
shi.depth= 1; // only now to indicate tracing
shade_ray(is, &shi, &shr);
+ if (traflag & RAY_TRA)
+ d= shade_by_transmission(is, &shi, &shr);
/* mix colors based on shadfac (rgb + amount of light factor) */
- addAlphaLight(is->col, shr.diff, shr.alpha, shi.mat->filter);
+ addAlphaLight(is->col, shr.diff, shr.alpha, d*shi.mat->filter);
if(depth>0 && is->col[3]>0.0) {
@@ -1857,7 +1889,7 @@
VECCOPY(is->start, shi.co);
is->vlrorig= shi.vlr;
- ray_trace_shadow_tra(is, depth-1);
+ ray_trace_shadow_tra(is, depth-1, traflag | RAY_TRA);
}
}
}
@@ -2192,7 +2224,7 @@
isec.col[0]= isec.col[1]= isec.col[2]= 1.0;
isec.col[3]= 1.0;
- ray_trace_shadow_tra(&isec, DEPTH_SHADOW_TRA);
+ ray_trace_shadow_tra(&isec, DEPTH_SHADOW_TRA, 0);
QUATCOPY(shadfac, isec.col);
//printf("shadfac %f %f %f %f\n", shadfac[0], shadfac[1], shadfac[2], shadfac[3]);
}
@@ -2248,7 +2280,7 @@
isec.col[0]= isec.col[1]= isec.col[2]= 1.0;
isec.col[3]= 1.0;
- ray_trace_shadow_tra(&isec, DEPTH_SHADOW_TRA);
+ ray_trace_shadow_tra(&isec, DEPTH_SHADOW_TRA, 0);
shadfac[0] += isec.col[0];
shadfac[1] += isec.col[1];
shadfac[2] += isec.col[2];
Event Timeline
Log In to Comment