Volumetric Shader
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/12/2008 at 13:28, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10
Platform: Windows ;
Language(s) : C++ ;---------
I am programming a volume shader for a terrain generator. With some noise function I get my terrain and I have an implementation of a illumination model. The shader is assigned to a cube. Everything works fine until I put another object into the cube volume of my shader. I get strange displacements of my terrain, and strange shadows, which I don't really understand.
In which order is C4d processing the two objects. How are shadows calculated. For the volume shader of course there is no polygon surface, and therefore no surface hits, except on the surface of the surrounding cube.
I would be thankful for some advice. Sorry, the question is a bit fuzzy, but I am stuck and don't know where to look further. Maybe there is somewhere an example of a terrain shader in C?
What happens if I add another volume shader for e.g. fog? How do the two volume shaders interact?
Thanks in advance -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/12/2008 at 05:50, xxxxxxxx wrote:
I am afraid there is no example besides the two examples included in the sdk examples. vd->lhit will give you the entry identity of the ray. Without any code or more details I am afraid I can't be of any help.
cheers
Matthias -
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
Thanksvoid 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 samplesReal 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 volumeLONG 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;
}}
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/12/2008 at 11:42, xxxxxxxx wrote:
Maybe somebody could give me a hint, I am pretty stuck.
Thanks -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2008 at 02:58, xxxxxxxx wrote:
Hi,
you must clip the ray to the needs of your QAEB Tracer.
As the c4d raytracer will give you spans of rays, I assume it will first of all give you the span of entering your shader box and ending at the intersection point of the box that is in it. Then the next span would be from the inner box entry point to the inner box exit point. And then from exit point of that box to the exit point of your volume box. Maybe it´s also the other way round (so from back to front instead of front to back). You should debug to find out the correct order.
If front to back, simply calculate the QAEB function until the ray ends at the inner box. I am not sure if it´s mentioned by Musgrave how to handle clipping for the QAEB Tracer (too long ago that I´ve read the book) but that´s how I´d do it.
Good luck!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2008 at 05:14, xxxxxxxx wrote:
Thanks Katachi,
I am just not totally sure, what you mean by clipping. I already found out, that C4d gives me the different pieces of the ray. Does clipping mean, that I just set transparency of the pieces, which I don't need, to one? Or is there a direct way to influence which pieces are taken into account by C4d? It's more a practical questions about C4d, less about how to implement the QAEB. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/12/2008 at 05:24, xxxxxxxx wrote:
Yep, you simply don´t pass anything and leave the transparency at 100% (so simply do a vd->trans = 1.0; return;) once the ray that is passed to you is behind the inner cube (though as long as the cube is not transparent you most probably won´t need to worry as it won´t be called then).
Clipping in this case is only taken to be virtual. So, you simply march until a certain point before the inner cube intersection and then stop (clipped).
I have also implemented the QAEB Tracer some years ago, but hey it´s really down in the old HDs lying under my bed, so cannot check my old code now.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2008 at 06:04, xxxxxxxx wrote:
Finally I could locate the problem in my shader:
I also had to set the cosc value of the VolumeData, before calling vd->IlluminanceSurfacePoint(&ispd;,&diff;,&spec;). That solved the problem:vd->bumpn=vcn;
vd->cosc=!vcn*Vector(vd->ray->v.x,vd->ray->v.y,vd->ray->v.z)); -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2008 at 06:16, xxxxxxxx wrote:
There you go.