Thanks KWD, but this texture is slow and does not work exactly how I want (you can not control with colorramp and does not allow select 100% other material)
raytracing from within OSL is rather slow, so wouldn’t it be a better idea to simply create a shader that calculates the distance to a given point and combine (add) several of them (one for each tree) to drive a mix shader?
// warning untested
shader distance(
point Pos=P,
point ObjectPosition,
float MaxDistance,
output float Dist=0,
){
float d = distance(Pos, ObjectPosition);
if(d < MaxDist){
Dist = 1-d/MaxDist;
}
}
@mano-wii: I am not quite sure what you mean. From the image that you linked to (the one with the trees) I guessed that you wanted a circular area around each tree. With a couple of trees that’s doable, but creating a circular area around each blade of grass clearly isn’t.
if you do want to create a circular area with different particles (say shorter and brown grass around the trees and longer and greener grass further away) the way to go would be creating vertex groups on the plane (which will need some subdividing to allow for some detail). One vertex group would have some weight in areas around the tree, the other would be more or less its inverse. These vertex groups could then be used to drive the dendity of two particle systems. (there are numerous tutorials on that and the manual is also helpful: http://wiki.blender.org/index.php/Doc:2.6/Manual/Modeling/Meshes/Vertex_Groups/Weight_Paint)
but of course I might be completely misunderstanding what you really want
@varkenvarken, that’s not I want. Each of the 20,000 particles are rendered as trees. (This texture would only be seen in around 100 of them). I’ll show a picture.
i see, that’s a whole different story. you might have a look at dynamic painting which lets you change mesh properties (like vertex colors) based in interaction w. other objects and/or particles. http://www.miikahweb.com/en/articles/blender-dynamicpaint-basics
Thanks @varkenvarken for the advice, but it seems hair particles don’t serve as a brush. I’ve tried.
I think if I put enough trace rays in OSL, would begin to look like a circle. But I don’t know how to do this.
you could sample a number of randomly distributed rays (warning: untested code):
...
for(int n=0; n<NumberOfRays; n++){
vector ray=noise("perlin",P,n);
ray[2]=1; // restrict to upper half
if(trace(P,ray)){
getmessage("trace","hitdist",Dist);
break;
}
}
... do something with Dist ..
notes:
as shown above the rays are not uniformly distributed but in this case that does matter much,
the code as shown breaks the loop at the first hit encountered. that won’t give you the shortest distance. if you want that, don’t break but compare against the shortest distance sofar (but beware for 0 distance when hitting the plane itself)
Thanks @varkenvarken now worked :). I just made a small change in the “vector ray=noise(“perlin”,P,n);” for “vector ray=noise(“cell”,P,n)*2-1;” (just gets faster).
Thank smart solution.