PDA

View Full Version : Displacement Mapping in RenderMan


pjblewis
11-03-2006, 04:59 PM
Hi,

I'm new here, though I've been haunting the place for a few weeks. Seems like a great community! Anyway, on to why I started this topic...

At the moment I'm in the process of learning RenderMan, but I'm having a problem with my displacement mapping. For some reason after displacement my normals are coming out all wrong, even though before displacement they are OK. An image of this is here (http://pjblewis.com/code/renderman/cubes.jpg). The left side hasn't been painted properly, but the right side has.

Here's my displacement shader:
displacement hansDisp (string texName = "";float dispMult = 0.1)
{
float magnitude;
magnitude = dispMult * ( float texture( texName ) * 2 - 1 );
P += magnitude * normalize (N);
N = calculatenormal (P);
}

Does anyone know why this might be happening?

Thanks very much :)

darktding
11-04-2006, 03:07 PM
the reason right off the bat is because you are not using subdivison surfaces. If you are using MTOR theres a MTOR-subdivision plugin you need to load in and then convert your mesh into a subdivided one and you are set...I think you can also use maya's subdivision mesh. Also it looks like you mesh has way too many triangles in the topology, subdivison works efficient when you have quads since it doesnt add unwanted loops in your mesh...

pjblewis
11-04-2006, 03:36 PM
Ah, brilliant, thank you very much! Converting to subdivision surfaces seemed to do the trick.

playmesumch00ns
11-04-2006, 04:51 PM
You can fix this without using subdivision surfaces. You need to store the shading normal's offset from the geometric normal, and then re-apply it after you've calculated your displaced normal. Like this:

displacement hansDisp (string texName = "";float dispMult = 0.1)
{
float magnitude;
magnitude = dispMult * ( float texture( texName ) * 2 - 1 );

normal Nn = normalize(N);
vector deltaN = Nn - normalize(Ng);
P += magnitude * Nn;
N = normalize( calculatenormal (P) );

N = normalize( N + deltaN );
}





I'm never sure quite how many normalizes you want in there. Experiment and see what combination works :)

pjblewis
11-04-2006, 11:30 PM
I'll try that too, as I'd quite like to have support for polygonal surfaces as well as subdivision urfs. I'll have to wait until I go back in on Monday though, so I'll let you know if that works.

Thanks guys :)

CGTalk Moderation
11-04-2006, 11:30 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.