THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/12/2008 at 13:32, xxxxxxxx wrote:
Below I have put the code of my Terrain shader as a volume shader. The shader itself works fine, but if I have e.g. a cube cutting through the terrain, I get image errors.
Does the rendering of the ray stop, after I have set a color vd->col=diff^col in the volume shader with transparency vd->trans=0.0 ? Not that I get a secondary beam after the cube, which overwrites the color of the terrain.
An example is here http://science-animation.de/index.php?id=80
Thanks
void TerrainShaderQAEB::CalcVolumetric(PluginMaterial *mat, VolumeData *vd)
{
Vector v1; // start point at camera
Vector v2; // target point
Vector vcn;
Vector vdiff;
Vector v,vdn;
Vector vStep;
Vector vc,vc1,vc2;
Real val;
LONG count;
Real l,lFull,step1,step2,dstep;
Real fac=0.5;
LONG maxSamples=30;
Real SampleLength=10.0; // [m] how long are the samples
Real A=1/distance; // Distance value for the fog density [1/m]
Real B=1/height; // height coefficient for the atmospheric extinction [1/m]
Real yOffset=heightOffset; // offset in the height to move fog up and down.
Vector diff,spec;
Bool flag=false;
Bool borderFlag=false; // This flag is set to true when we cross the border of the volume
LONG i;
dstep=0.1;
v1=Vector(vd->ray->p.x,vd->ray->p.y,vd->ray->p.z);
v2=vd->p;
vdiff=(v2-v1);
vdn=!vdiff;
lFull=Len(vdiff);
if (lFull>1000) lFull=1000;
vd->trans=1.0;
l=0;
count=0;
while (l<lFull && count<700 && flag==false) {
v=v1+l*vdn;
count++;
val=cn.GetValue(Vector(v.x,0.0,v.z)/50.0)*100.0; // my terrain function
// Terrain so far only in a box fabs(x/y/z)<100
if (fabs(v.x)<100 && fabs(v.y)<100 && fabs(v.z)<100) {
vc=Vector(v.x,val,v.z);
if (v.y<val) { // we are below the mountain
if (borderFlag) {
vc1=!(Vector(v.x+dstep,cn.GetValue(Vector(v.x+dstep,0.0,v.z)/50.0)*100.0,v.z)-vc);
vc2=!(Vector(v.x,cn.GetValue(Vector(v.x,0.0,v.z+dstep)/50.0)*100.0,v.z+dstep)-vc);
vcn=vc1%vc2; // calculate the normal vector
vd->bumpn=!vcn;
ispd.bumpn=!vcn;
ispd.calc_shadow=ILLUMINATE_SHADOW_ON;
ispd.cosine_cutoff=false;
ispd.lhit=0;
ispd.local_mat=NULL;
ispd.model=SimpleIllumModel;
ispd.orign=!vcn;
ispd.p=v;
ispd.phongn=!vcn;
ispd.ray_vector=Vector(vd->ray->v.x,vd->ray->v.y,vd->ray->v.z);
ispd.raybits=vd->raybits;
ispd.receive_caustics=false;
ispd.receive_gi=false;
ispd.specular_exponent=0.0;
vd->IlluminanceSurfacePoint(&ispd;,&diff;,&spec;);
i=int(cTex[0].GetValue((Vector(v.x,0.0,v.z))/scale1)*COL_COUNT);
color=col _;
vd->col=diff^color;
vd->trans=0.0;
flag=true;
} else {
vd->col=0.0;
vd->trans=1.0;
flag=true;
}
}
borderFlag=true;
// Step along the view ray
step1=fov/500*Len(v1-v);
step2=fabs(val-v.y)*0.5;
if (step2>step1) step1=step2;
if (step1<0.2) step1=0.2;
l=l+step1;
} else {
// Larger steps if we are out of the cube with the terrain
step1=fabs(val-v.y)*0.5;
if (step1<10) step1=10;
l=l+step1;
}
}
if (!flag) {
vd->col=0.0;
vd->trans=1.0;
}
}
