Instancing and point cloud shaders

   4706   4   1
User Avatar
Member
511 posts
Joined:
Offline
Hi there,

I want to populate a landscape with hundreds of trees. To render them efficiently I am using instancing.
The problem is, I was using point clouds to affect the shading of my tree with sort of a fake occlusion thing, where shading gets darker the closer it is to a point that birthed a clump of leaves.

The shader is like this: http://forums.odforce.net/index.php?showtopic=5114&hl=point+cloud [forums.odforce.net]

This works great when I'm rendering the original tree, but if the shader is used on the instanced geometry it will no longer work. I tried all manner of space change and rest position node combinations but it doesnt seem to be working at all.

Does anyone know how to make this work, if its at all possible?
It's not that big a deal in this particular case, since there are other ways to achieve more or less what I want. But, if I wanted for example to render loads of translucent things with pcloud based sss I would have a more serious problem there.

btw, is it possible to use metaballs to affect shading?

thanks
Sergio
User Avatar
Member
4256 posts
Joined: July 2005
Online
One thing to be aware of is that a point cloud is shared between all object which access it.

Say you have a shader which calculates diffuse() at each unshaded point in the point cloud pointCloud.bgeo. Say Object_A is the first object that happens to be rendered. Object_A will store its occlusion info into the unshaded points of pointCloud.bgeo and every other object that uses pointCloud.bgeo will end up using Object_A's occlusion info.

There are a couple of different ways to work around this.
  • The first is to have a seperate bgeo for every single instance. (Tons of copies). Very impractical but results in the fastest renders.
  • When you use pcexport give it a unique name for each object.

    Instead of:
    pcexport(handle,“occlusion”,occ);
    Use this
    pcexport(handle,concat(“occlusion”,uniqueName),occ);

  • Have your uniqueName based on a shader parameter. “occlusion1”
  • Base your uniqueName on getobjectname() "occlusion/obj/Instance"

  • Before the render, write out a single point cloud bgeo which contains ALL your instances. (Becareful of space)

    Sample Shader
    This shader just calculates diffuse() for each unshaded point clould point.

    vector pcIllum(string map; int samples; float radius; string chan {
    vector po = wo_space(P);
    vector no = normalize(wo_nspace(N));
    vector p = 0;
    vector n = 0;
    int handle = -1;
    int status = -1;
    handle = pcopen(map,“P”,po,“N”,no,radius,samples);
    vector illum = 0;
    vector ret = 0;
    while (pcunshaded(handle,chan)==1) {
    pcimport(handle,“P”,p);
    pcimport(handle,“N”,n);
    p = ow_space(p);
    n = normalize(ow_nspace(n));
    illuminance(p,n) {
    shadow(Cl);
    illum += Cl *diffuseBRDF(normalize(L),n);
    }
    status = pcexport(handle,chan,illum);
    }
    ret = pcfilter(handle,chan);
    pcclose(handle);
    return ret;
    }

    surface
    sssTest(string map = “$HOME/pcCloud.bgeo”;
    int samples = 10;
    float radius = 1.0;
    string pid = “”;
    int suffix = 0
    {
    string chan = suffix ? concat(“illum_”,getobjectname())
    : concat(“illum_”,pid);
    Cf = pcIllum(map,samples,radius,chan);

    }



    Timings based on the above shader

    Micropolygons Raytracing
    Memory CPU Memory CPU
    Method

    Seperate
    Bgeos (4123) 250MB 1m10s 250MB 53s

    Unique Channel
    pid Parameter 167MB 8m30s 166MB 1m34s

    Unique Channel
    getobjectname() 25MB 5m42s 25MB 52s

    Shared
    Point Cloud 10MB 25s 9MB 20s

Attachments:
sss.jpg (149.3 KB)

if(coffees<2,round(float),float)
User Avatar
Member
2199 posts
Joined: July 2005
Offline
If you aren't that close to the trees why not bake the occlusion into the geometry used as the instance.
The trick is finding just the right hammer for every screw
User Avatar
Member
511 posts
Joined:
Offline
Hi there,

thanks for taking the time to to do this post Wolfwood, Unfortunately I think I didnt explain my problem properly.

Basicaly my tree is structured as such:
My tree geo has 3 three shaders within it (branches, canopy, trunk), each shader is referencing a pcloud, this works fine if I render this geo directly without any form of instancing.

As soon as I instance the trees I no longer see any effect from the pcloud shader, (I'm using vops for the shader as I dont understand code, yet), I figured that If I added a rest position node to my shader, that the pcloud shading would get draged along with the geo as it gets plonked all over my landscape. Unfortunately this doesnt seem to happen.

My actual tree will no longer be using pclouds to fake occ, instead I baked it onto the geo with the occlusion sop found on the exchange.
But I'm still wanting to figure this out since I'm likely to want to use pcloud shaders in instances in the future. I suspect the problem might be because my shaders reside in the tree geo rather than the points i will be instancing to.

I tried all manner of space change combinations and rest position settings, I'm just wondering if the problem is due to my inability or if there is a limitation with point instancing or a bug.

thanks
Sergio
User Avatar
Member
4256 posts
Joined: July 2005
Online
Can you post a simplified scene?
if(coffees<2,round(float),float)
  • Quick Links