PDA

View Full Version : Light dispersion (renderman shader)


fraa
04-15-2004, 10:35 AM
While browsing Jeremy Birn's website, i found his tutorial about "Chromatic Aberrations" (http://www.3drender.com/light/lens.htm). I tried to achieve the same effect with a shader ... here's the result of my empirical study :)

http://fra.planet-d.net/work/research/09_dispersion_10.jpg

http://fra.planet-d.net/posts/dispersion.mpg

The whole thing is a trick, so it is physically unaccurate. The shader just fires 3 rays (instead of one) with a slight IOR offset and re-comp' them with a RGB filter.
It looks interesting enough, though any comments about the render or the method would be warmly welcomed. I'n not really happy about the shadows (they looks completely wrong), but i've still a lot of things to learn about shading language ...

the shader source is here (http://fra.planet-d.net/shaders/PoorDispersion.zip)

... and here is it for those who don't want do download it :

surface
PoorDispersion(float ior = 1.5; float dispersion_iota = 0.25;)
{
point R, T, Nn, Ni;
float krefl, ktran,
eta;

Nn = normalize(N);
Ni = normalize(I);

fresnel(Ni, Nn, 1.0 / ior, krefl, ktran, R, T);

if (isshadowray() != 0)
{
Oi = (1.0 - ktran);
}
else
{
eta = ior;
Oi = Os;

eta += (dispersion_iota * float random());
T = refract(Ni, Nn, 1 / eta);
Ci = trace(P, T) * color(1,0,0) * ktran;

eta += (dispersion_iota * float random());
T = refract(Ni, Nn, 1 / eta);
Ci += trace(P, T) * color(0,1,0) * ktran;

eta += (dispersion_iota * float random());
T = refract(Ni, Nn, 1 / eta);
Ci += trace(P, T) * color(0,0,1) * ktran;
}

Ci += trace(P, R) * krefl;

}

edit :
a same approach can be found here : http://animus.brinkster.net/stuff/plg_diffraction/plg_diffraction.html
using xsi. the shader looks really complex to me, i guess it handles far more many cases than my hawfull hack :)

fxjeane
04-17-2004, 09:51 PM
very nice..
I think you could use a for loop and add a "number of samples" parameter. Then you run the loop once per sample and keep indexing random rays to rgb values... Not that great of an improvement but it will give you a little more control.. I might give it a try and post it here, if I find some free time

Cheers
Rudy

fraa
04-19-2004, 07:31 AM
Thanks !!

mmh, yes, about the sampling loop, it is something i should have done. But, for mysterious reason, the platform i'm using doesn't require such a loop : the RenderDrive's pipeline seems to super-sample automaticaly every expression that contains some jitter (ie. a random() function). I was long puzzled about that, but i found their API/Render really nice as it handles a lot of things for the developper. I should ask Art-Render about that...

And may be try my shader on a different renderer (BMRT may be)

Well all these coding matters are clearly out of the scope of this forum so... about the dispersion, i assume simply dividing light in 3 RGB rays with equal weighting isn't physically correct ... light dispersion must be smthing more complex than a simple 3 channels comp :)
i have to look about that as well ...

Thanks for the tips, i'll try it anyway.

balistic
04-19-2004, 02:08 PM
That looks awesome. Thanks for sharing.

fraa
04-20-2004, 11:22 AM
Tanks a lot Mr Prince !
i like sharing my experiments, most of the time it helps to push the enveloppe :D

some more renders ... it looks pretty :P
http://fra.dozign.com/posts/dispersion_teapot.jpg

i tried it with entropy, errr, it's not precisely what i expected :)
i'l share the results asap ...

stew
04-26-2004, 09:49 AM
I tried something similar once, but including additional reflection rays. Takes <i>forever</i> to render.

It'd be a lot faster to do that in multiple passes - first rendering reflection and refraction maps, then rendering a final pass whith the shader doing multiple lookups in the maps and coloring them accordingly.

fraa
04-27-2004, 06:22 PM
Stew : mine takes *forever* to render with Entropy as well !
The buffered approach you suggest seems definitely the good one.

I was visiting your website, some cool stuff in it ! And I was so surprised to learn that Pixel:3D was RenderMan compliant !!
Amazing, so it can eat .sl shaders and stuff like that? Crazy !

thanks for the feedback !

edit : "Photoshop Plugin that enables you to load and save wave audio" -> i did this manually using the .raw format, errr, but never though about a plug-in for that, great idea !

stew
04-27-2004, 06:36 PM
Originally posted by fraa
Amazing, so it can eat .sl shaders and stuff like that?
No, not directly. You need to convert them to C, but Pixels provides a shader API that is closely derived from RSL.

CGTalk Moderation
01-18-2006, 02:00 AM
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.