|
![](/i/fill.gif) |
clipka wrote:
> In one scene I'm working on, I need to sample data from discrete points using
> trace(). From this, I'm currently generating a heightfield-like mesh.
>
> Now I want to add some "ground fog"-like effect that follows the contours of
> this height field.
>
> I tried with a pigment based on a function that takes the values from an array,
> but it seems that accessing an array from within functions is not possible (or
> I'm doing something wrong).
>
> Another idea would be to do an orthographic shot of the heightfield mesh with a
> gradient pattern to convert it into a heightfield image; however, I would
> prefer to avoid the additional rendering step.
>
> Any smart idea how to accomplish this?
clipka,
At the risk of missing the point entirely and/or saying something
stupid, I present this code:
// begin code
#declare hfRes = <40,40>;
#declare hfPts = array[hfRes.x][hfRes.y];
#declare hp = function{pigment{crackle scale .25}}
// read from hp pigment function into array
#declare V=0;
#while(V<hfRes.y)
#declare U=0;
#while(U<hfRes.x)
#declare hfPts[U][V] = hp(U/hfRes.x,V/hfRes.y,0).x;
#declare U=U+1;
#end
#declare V=V+1;
#end
// read from array into a pigment
#declare hfHeight=
pigment{
pigment_pattern{planar translate y}
pigment_map{
#declare V=0;
#while(V<hfRes.y)
[V/hfRes.y
planar rotate z*90 translate x
color_map{
#declare U=0;
#while(U<hfRes.x)
[U/hfRes.x
rgb hfPts[U][V]
]
#declare U=U+1;
#end
}
]
#declare V=V+1;
#end
}
}
// the pigment as a function
#declare hfF_Height=
function{
pattern{
pigment_pattern{hfHeight rotate x*90}
}
}
// height_field transforms
#declare hfTransform=
transform{
translate-(x+z)/2
scale<10,2,10>
rotate y*33
}
// height_field
height_field{
function hfRes.x, hfRes.y{
pigment{
hfHeight
scale<1,-1,1> translate y
}
}
pigment{rgb x}
transform{hfTransform}
}
// the base pattern for the fog
#declare fogPlane=function{pattern{planar}}
// the fog box
box{0,1
pigment{rgbt 1}
interior{
media{
//emission 1
//absorption 1
scattering{5,1}
density{
// base fog pattern is elevated with function pattern
function{
#declare offsX=1/hfRes.x;
#declare offsY=1/hfRes.y;
fogPlane(x,y-hfF_Height(x,0,z),z)
}
color_map{[.75 rgb 0][1 rgb 1]}
}
}
}
hollow
transform{hfTransform}
}
// end code
Basically it writes pigment values into an array, and then write values
from that array into an array-like pigment. It's not much different from
that SSS code I posted a while back. The resulting pigment is then used
to deform a function density within a box. It's not perfect, but may
suit your needs.
This code doesn't do the work of tracing the height_field, but since
you're a smart guy you can make the necessary changes :)
I hope this helps!
Sam
Post a reply to this message
|
![](/i/fill.gif) |