PDA

View Full Version : final gathering with custom shaders ?



dlanier
June 25th, 2007, 21:19
Hi,

In my custom shaders, I would like to use final gathering.

In the code I have :


//Detect final gather preprocessing phase
int dummy[4]; //for tile size query
if (state->options->finalgather && !mi_query(miQ_TILE_PIXELS, state, 0, dummy))
{
//We are in FG preprocessing phase
miIrrad_options opts;
miIRRAD_DEFAULT( &opts, state );
mi_compute_avg_radiance(result,state,'f',&opts);
return miTRUE;
}

if(state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE || miRAY_PHOTON(state->type))
{
*result = transp_black;
return miTRUE;
}


Should I add something else to support final gathering ?
It seems that enabling it has no effect in my scene on my custom shaders.
Thank you.
Regards,

dlanier
June 28th, 2007, 01:18
When using FG with my custom shaders, the final gather preprocess phase result to a black image then everything is drawn normallly.
But when using the others shaders, we see a draft of the resulting image.

Does someone know why this is wrong with my custom shaders ?
Thanks.
Regards,

bart
June 29th, 2007, 03:43
Detection for the pre-processing phase is not necessary for the regular use of finalgathering. Usually detection is used to optimize out things that are not necessary at pre-processing time.

First try using mi_compute_avg_radiance without the fg phase detection. It will return your indirect illumination which you can then multiply by your diffuse color.

At FG pre-processing time, mr knows to save the first hit from the camera into an FG point automatically.

bart
June 29th, 2007, 03:46
Also, note that something in the scene during that phase has to return a color in order to see anything. If it is all only compute_avg_radiance, and there is no environment color, then no light is entering the scene to see it eventually indirectly. I hope that made sense.

dlanier
June 29th, 2007, 19:52
Hi Bart,

Actually my shader is special as it's a shader that is a container for 3 others shaders.
It stores these 3 shaders, the first in the frame buffer and the 2 others in additional users frame buffers.
So I need to detect the phase of FG preprocessing or if not I get an error with users frame buffer not created as they are created after the FG preprocess phase.
But the mi_compute_avg_radiance call is made in the shader that is stored in the frame buffer not in the container.
So what should I modify to handle correctly FG ?
Thanks.
Regards,

bart
June 30th, 2007, 04:59
First of all, user framebuffers are specified and entered into the mental ray database at scene input, or if in a geometry shader, at scene preprocessing time.

Look at the render phase diagram in http://www.lamrug.org/resources/memorytips.html
mental ray Memory Tips

Framebuffers are created before FG point presampling.

You are on shader beta and have looked at the framebuffer code, right?
Those 10 input framebuffer shaders you could use for a container template.
Note they depend on user framebuffers having already been created by a geometry shader or by the application.

dlanier
June 30th, 2007, 06:52
Hi,

Well, it seems like if they are not created before the preprocessing phase as if I don't detect this FG preprocess, I get an error in my shader as the users frame buffers are not yet created, the mi_fb_put return miFALSE.
This is in Maya 7, 8.5, same in Max 8,9.
Regards,

bart
July 3rd, 2007, 09:30
That doesn't seem right, or I'm misunderstanding something. Are they being created by the Maya UI, or by geometry shaders? There is no max UI to create framebuffers.

Did you try the framebuffer code we have supplied? Make sure that works first, and then proceed in the direction of your code.