PDA

View Full Version : bent normal and occlusion pass in prman 12.5


raven0us
02-12-2007, 06:02 AM
I tried to compile the RSL code in the prman application note #35 Global Illumination...

the compiler does not recognize shadingnormal as a built in funtion and quits with errors...

I also tried to compile the shader occlusion.sl in the Hayden Landis Siggraph pdf

again the compiler didn't recognize the rayhittest function....

What I want to do is to render an ambient occlision and bent normal pass using AOVs.

A.Whitehurrst's online tutorial is depth map based....need a shader that'll outout ambient occlusion and bent normal...my understanding is that you assign the variables in the shader that store these passes to aov....

this is the Hayden Landis occlusion.sl shader source

#define BIG 1e20

color vectortocolor(vector v) {
return ((color v) + 1) / 2;
}


surface occlusion (float samples = 16;
float doBendNormal = 0;)

{
normal NN = normalize(N);
vector up = vector(0,1,0);
float sum = 0;
float i;
vector dirsum = 0;
vector side = up ^ NN;
for (i = 0; i<samples; i = i+1) {
float phi = random()*2*PI;
float theta = acos(sqrt(random()));
vector dir = rotate(NN,theta,point(0),side);
dir = rotate(dir,phi,point(0),NN);
point Ph;
normal Nh;
if (rayhittest(P,dir,Ph,Nh) > BIG) {
sum = sum + 1;
dirsum = dirsum - NN;
}
}
sum /= samples;
dirsum = normalize(dirsum);
if (doBendNormal != 0) {
vector bend = dirsum - NN;
Ci = vectortocolor(bend);
} else {
Ci = sum;
}
}

playmesumch00ns
02-12-2007, 09:23 AM
I think shadingnormal is defined in the pxslayUtil.h function under lib/slim/include in your prman installation or somewhere liek that. Anyway the following is totally off the top of my head. You'll definitely want to check syntax and arguments in the prman docs:


surface Occlusion
(
float Samples = 20;
float MaxError = 0;
float MaxDist = 1e9;
float ConeAngle = 90;

// this could just as well be a float, but I tend to pack other things into the spare channels
output varying color aovOcclusion=0;
output varying color aovBentNormal=0;
)
{
normal Nn = normalize(N);

// assign the normal to the bentNormal var so if raytracing's not on we get a sensible output
vector bentNormal = vector Nn;

// get the ambient occlusion. store the average unoccluded direction in bentNormal
float ambocc = 0;
ambocc = occlusion( P, Nn, Samples, "coneangle", radians( ConeAngle ), "maxerror", MaxError, "maxdistance", MaxDist,
"environmentdir", bentNormal );

// set the occlusion output
// i normally pack things like reflection occlusion into the spare channels
setcomp( aovOcclusion, 0, ambocc );

// set the bent normal output. if you want to use the result for 2.5d relighting you'll want the commented line
// below
// aovBentNormal = color normalize( vtransform( "world", bentNormal ) );
aovBentNormal = color bentNormal;

Ci = aovOcclusion;
Oi = 1;

}

rendermaniac
02-12-2007, 10:06 AM
Last time I looked shadingnormal() was defined in $RMANTREE/lib/shaders/normals.h ie in the shaders directory for RenderManProserver (the renderer) and not part of RAT. This isn't the most obvious place to find it!

Basically all it does it check the ray depth and doubled sided attributes to see if it needs to flip the normals to face the camera or not.

Hayden Landis's shaders were written for Entropy, not prman, which had extension fuctions for doing raytracing that aren't available in prman.

The code playmesumch00ns posted is the best way to do it now.

Simon

raven0us
02-12-2007, 10:55 AM
playmesumch00ns....

I got the following errors when I compiled it......

line 9: ERROR: syntax error

line 9: ERROR: Invalid or absent parameter default

line 10: ERROR: syntax error

line 10: ERROR: Invalid or absent parameter default

So I did this (correct me if this is wrong)

output varying color aovOcclusion = 0;
output varying color aovBentNormal = 0;

And I don't get the errors shown above...but I still get this message...

it says that secomp is not a known built in function...

(1) what does secomp do?..looks like it's putting the aovOcclusion in the red channel and ambocc in the blue channel...

(2) If it's an exr output how would you assign variables/aovs to the different channels that exrs can hold??

(3) got another question on the 2.5d lighting...(I want the bent normal pass for relighting in post)...

color normalize( vtransform( "world", bentNormal ) )

calculates the bentNormal in world space as opposed to object or tangent space??

this is very exciting...
immensely greatful for the reply and code...It really does hlp to learn...:thumbsup:



rendermaniac...

thanks ..yeah it's there..:)

playmesumch00ns
02-12-2007, 01:11 PM
Hehe like I said, off the top of my head. I've edited the post to correct the most grevious errors: you're right, the aov's do need a default value.

And secomp was a typo, it should have been setcomp. It's setting the red channel (0) of aovOcclusion to be ambocc, leaving the g and b channels free for other data you might want to put in there.

Like I said, check the exact parameter names to the occlusion function in the docs (and I may well have mixed up the order of coneangle and samples).

the bentNormal value set by the occlusion call is in current (camera) space. So yes that commented line just transforms it to world space so you can use it to do relighting for example.


As for setting exr channels, that's done in the Display lines in the rib. You could output aovOcclusion and aovBentNormal to seperate files (I'd recommmend this), or pack them into a single exr.

raven0us
02-13-2007, 02:18 AM
playmesumch00ns....

on compilin I get the following error..


line 20: ERROR: function occlusion, arg 4: type mismatch
string expected instead of float

I put the samples flag after point and normal.......
float ambocc = occlusion( P, Nn,Samples,radians( ConeAngle ), "maxerror", MaxError, "maxdistance", MaxDist,
"environmentdir", bentNormal );

and still the same error.....

I added "coneangle"

float ambocc = occlusion( P, Nn,Samples,"coneangle",radians( ConeAngle ), "maxerror", MaxError, "maxdistance", MaxDist,
"environmentdir", bentNormal );

and it compiles....

but...

on rendering I get the bentNormal pass....smashing!!
but the occlusion pass looks weird....it gets stored in the red channel....but is very "blocky" like this.....I tried increasing the samples changing other parameters ....but nothing happend....raytracing is on...

attached the images....

probably somethimg wrong with the changes I made...

playmesumch00ns
02-13-2007, 08:35 AM
Hmmm that looks very strange to me. Are you sure raytracing is on and all your objects are visible to rays? It looks as though the occlusion call is doing nothing, as the bent normal appears to be the actual surface normal.

The occlusion pass itself looks just like an uninitialized variable (i.e. the ambocc value is just filled with random data). Try initializing the ambocc variable to 0 to double check this (I've edited the code above to reflect this). My suspicion is that your occlusion pass will come out pure black when you do this.

So, you need to triple-check that raytracing is enabled and all your objects are visible to rays.

raven0us
02-13-2007, 11:47 AM
playmesumch00ns..

you are right again....

using mayaman.... enabled raytracing by turning on raytracing in the regular maya render globals....and if I attach a blinn shader I get the obvious reflections....when I attach the Occlusion shader all I get is the black image for the occlusion pass.....mmm and the normal render....:scream:

I've asked the mayaman list for some help....can you tell me what's wrong?


I compiled and rendered the shader for 3delight as well.....

compiled the shaders for both prman and 3delight using Malcolm Kesson's cutter.... ...
and the Occlusion.sl that compiles with prman's shader this time gave some errors when I compiled it with 3delight's shaderdl.That's normal behaviour???

the error ....
Occlusion.sl:20: ERROR: invalid type or name for argument number 6 of 'occlusion' function



so I edited it like this.....

ambocc = occlusion( P, Nn, Samples, "coneangle", radians(ConeAngle),"maxdist", MaxDist,"environmentdir", bentNormal );

and it worked!!:twisted:

....why is shaderdl giving errors for the maxerror parameter?and is it "maxdist" or "maxdistance"...the docs say "maxdist"

prman's shader compiles with "maxdistance" and "maxdist".

but I still coudn't get 3delight to render the passes....need to look at the docs ...attached pics for the 3delight settings and a raytrace test render...the sphere has a clay shader and the floor has a shiny shader....attached geoattributes to both sphere and floor and enabled visible to reflections....and I get the reflections..I assume that turns raytrace on or is on by default for 3delight....

but still can't get it to work...apologies for troubling...thanks for taking the time to respond....

Sajeev

Parsival
02-13-2007, 01:04 PM
Hi,
I use MayaMan + Air and if I want to render the AO pass I have to enable the Radiance in the MayaMan Global Illumination Options, I don't know if you have to do the same with PRMan, I cannot check it, I don't have PRMan.
Bye

Parsival

raven0us
02-13-2007, 06:27 PM
Parsival,

Yes it's the same for mayaman+ prman ... you enable radiance in the global illuminations tab. and you get the occlusion pass...

I like to render all my projects into passes..and comp later.currently I use mentalray...renderman is new to me...started learning it...love it...So what I want to do is to render out aovs/framebuffers...for occlusion and bent normal pass using renderman....

the shader source provided by playmesumch00ns is great...you begin to see how things work...but I stlll can't get the passes...I'll keep trying:)

meanwhile I'm sure playmesumch00ns or someone else will point out what I'm missing...it must be something very basic....

raven0us
02-13-2007, 07:14 PM
Yippie!!:bounce:

got back to work..

and it works...with mayaman+prman....

the culprit was "maxdist" parameter in the occlusion function.

the red channel in inverted...but that's no big deal....then again just for practice...


playmesumch00ns is there a way to invert the channel in in RSL. I want to see if I can figure it out...so let me know yes/no.:)...should I fix it or not...?

3delight's shaderdl does give errors with the same shader source..and it does't like the "maxerror" parameter.....tried "maxvariation" still the same error...but no worries.....because I'll be using mayaman_prman anyway.....

attahced pics.....samples are 256....

compiled shader with

aovBentNormal = color normalize( vtransform( "world", bentNormal ) );

default shading rate....1

thank you so much playmesumch00ns......

raven0us
02-13-2007, 07:16 PM
here is the inverted red channel for aovOcclusion....:applause:

playmesumch00ns
02-13-2007, 08:44 PM
Glad you got it working :)

CGTalk Moderation
02-13-2007, 08:44 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.