Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HOw to do Diamond shader?

493 views
Skip to first unread message

duck

unread,
Mar 23, 2004, 11:46:39 AM3/23/04
to
Does any one know where I can find information about writing a diamond shader?
Does not matter raytrace or fake reflection.

Stephen H. Westin

unread,
Mar 23, 2004, 12:34:28 PM3/23/04
to
tak_...@hotmail.com (duck) writes:

> Does any one know where I can find information about writing a
> diamond shader? Does not matter raytrace or fake reflection.

Well, diamond is difficult for a couple of reasons. First, its high
index of refraction results in lots of internal reflections, which
means long ray paths. Second, dispersion (the prism effect) seems
to be an important part of diamond's appearance.

The first issue can be approached with brute force: just allow rays to
continue for many bounces, and live with the long rendering times. The
second is herder, since there are few renderers that deal with
dispersion. I don't know if some of the newer RenderMan
implementations do, but I suspect that's low on the list of priorities
for most implementors.

--
-Stephen H. Westin
Any information or opinions in this message are mine: they do not
represent the position of Cornell University or any of its sponsors.

Alexander Magidow

unread,
Mar 23, 2004, 11:34:37 PM3/23/04
to
duck wrote:
> Does any one know where I can find information about writing a diamond shader?
> Does not matter raytrace or fake reflection.
There is a rather technical discussion on this very subject in
comp.graphics.rendering.raytracing

Andrew

unread,
Mar 24, 2004, 4:50:54 AM3/24/04
to
tak_...@hotmail.com (duck) wrote in message news:<ade53876.04032...@posting.google.com>...

> Does any one know where I can find information about writing a diamond shader?
> Does not matter raytrace or fake reflection.

This article might help, it appeared in New Scientist magazine at the
end of last year. If you have access to the Materials Research Society
material (!) you might want to have a look at the original research
for more technical information.

Andrew.

http://www.newscientist.com/news/news.jsp?id=ns99994466

Dan Maas

unread,
Mar 24, 2004, 7:52:57 AM3/24/04
to
For dispersion you could always render multiple passes with different
indices of refraction and composite them. Also in RenderMan shading
language it is possible to send out rays for each color component
separately.

Dan

westin*nos...@graphics.cornell.edu (Stephen H. Westin) wrote in message news:<s0u10fl...@kingslake.graphics.cornell.edu>...

Nicholas Yue

unread,
Mar 24, 2004, 9:10:51 PM3/24/04
to
danie...@yahoo.com (Dan Maas) wrote in message news:<fcd1af44.04032...@posting.google.com>...

> For dispersion you could always render multiple passes with different
> indices of refraction and composite them. Also in RenderMan shading
> language it is possible to send out rays for each color component
> separately.

Any example on how to send out ray separately?

Cheers
--
Nicholas Yue

GGarramuno

unread,
Mar 24, 2004, 11:22:05 PM3/24/04
to
> Does any one know where I can find information about writing a diamond shader?
> Does not matter raytrace or fake reflection.

Here you can find a free and open source mental ray shader that
simulates diffraction, written by Daniel Rind:
http://animus.brinkster.net/stuff/plg_diffraction/plg_diffraction.html
Porting it to renderman should be relatively easy.

Stam published also a paper describing an algorithm used in maya for
diffraction (but for reflections) at:
http://www.dgp.toronto.edu/people/stam/reality/Research/Diffraction/
I'm not too sure but my guess is that it may be possible to adapt it
to refractions.

Dan Maas

unread,
Mar 25, 2004, 7:08:34 AM3/25/04
to
> Any example on how to send out ray separately?

Just trace three times with different indices of refraction, then use
comp()/setcomp() to bring the results together. Something like

"Poor Man's Dispersion"
color red_ray = trace(red_ior);
color grn_ray = trace(grn_ior);
color blu_ray = trace(blu_ior);

color final;
setcomp(final, 0, comp(red_ray, 0));
setcomp(final, 1, comp(grn_ray, 1));
setcomp(final, 2, comp(blu_ray, 2));


Dan

Stephen H. Westin

unread,
Mar 25, 2004, 9:17:29 AM3/25/04
to
GGarr...@aol.com (GGarramuno) writes:

> tak_...@hotmail.com (duck) wrote in message news:<ade53876.04032...@posting.google.com>...
> > Does any one know where I can find information about writing a diamond shader?
> > Does not matter raytrace or fake reflection.
>
> Here you can find a free and open source mental ray shader that
> simulates diffraction, written by Daniel Rind:
> http://animus.brinkster.net/stuff/plg_diffraction/plg_diffraction.html
> Porting it to renderman should be relatively easy.

Diffraction isn't usually visually important in rendering
diamonds. But then the two examples on that page are of refraction,
not diffraction. I think the author means *dispersion*, which is the
dependence of refraction on wavelength.

> Stam published also a paper describing an algorithm used in maya for
> diffraction (but for reflections) at:
> http://www.dgp.toronto.edu/people/stam/reality/Research/Diffraction/
> I'm not too sure but my guess is that it may be possible to adapt it
> to refractions.

That's diffraction. Not directly applicable, but whatever he uses to
map the spectrum to RGB might be of help.

Stephen H. Westin

unread,
Mar 25, 2004, 9:21:51 AM3/25/04
to
danie...@yahoo.com (Dan Maas) writes:

But Dan, won't that just give you three spikes, instead of a
continuous spectrum? I would try something more like

color red_sum = 0, green_sum = 0, blue_sum = 0;

for ( i=0; i<n_waves; i++ ) {
color result = trace(ior[i]);
red_sum += red_weight[i] * result;
green_sum += green_weight[i] * result;
blue_sum += blue_weight[i] * result;
}

where red_weight, green_weight, blue_weight are precalculated to
project the spectrum into RGB.

Dan Maas

unread,
Mar 26, 2004, 1:01:07 AM3/26/04
to
You're right. I said "poor man's" for a reason :). Certainly with more
spectral samples you could get a smoother result.

Dan

westin*nos...@graphics.cornell.edu (Stephen H. Westin) wrote in message

news:<s08yhpv...@diesel.graphics.cornell.edu>...

Przemyslaw Koprowski

unread,
Mar 29, 2004, 5:08:31 AM3/29/04
to
Stephen H. Westin wrote:
> But Dan, won't that just give you three spikes, instead of a
> continuous spectrum? I would try something more like
>
> color red_sum = 0, green_sum = 0, blue_sum = 0;
>
> for ( i=0; i<n_waves; i++ ) {
> color result = trace(ior[i]);
> red_sum += red_weight[i] * result;
> green_sum += green_weight[i] * result;
> blue_sum += blue_weight[i] * result;
> }
>
> where red_weight, green_weight, blue_weight are precalculated to
> project the spectrum into RGB.
>
How about converting into HLS, doing a number samples (in similar manner
as above) for different hues and then using Catmull-Rom spline for an
interpolation?

(It's just an idea out of top of my head, haven't tried it myself :)

Przemek

Will R

unread,
Mar 30, 2004, 7:47:42 PM3/30/04
to
>But Dan, won't that just give you three spikes, instead of a
>continuous spectrum? I would try something more like
>

Ideally, I'd think you would want to have all shaders know about spectra.
Perhaps you could do something along the lines of message passing, where each
ray traced hits a surface with a shader, and the shader figures itself out for
a particular frequency?
------------------
A board certified thin-foil chapeautinist, and practicing AluFoil
Haberdasherer.
http://apple.slashdot.org/comments.pl?sid=100795&cid=8595566
Remove SPAM block from email

Stephen H. Westin

unread,
Mar 31, 2004, 9:08:54 AM3/31/04
to
fork...@aol.comSPAM (Will R) writes:

> >But Dan, won't that just give you three spikes, instead of a
> >continuous spectrum? I would try something more like
> >
>
> Ideally, I'd think you would want to have all shaders know about spectra.
> Perhaps you could do something along the lines of message passing, where each
> ray traced hits a surface with a shader, and the shader figures itself out for
> a particular frequency?

Well, the RenderMan standard includes spectral descriptions of color,
but I don't think any RenderMan implementation fundamentally works
with more than 3 color channels. You *do* make sure all your shaders
work with an arbitrary number of channels, don't you? :)

Will R

unread,
Mar 31, 2004, 3:16:38 PM3/31/04
to
<< Well, the RenderMan standard includes spectral descriptions of color,
but I don't think any RenderMan implementation fundamentally works
with more than 3 color channels. You *do* make sure all your shaders
work with an arbitrary number of channels, don't you? :) >><BR><BR>

All my martian clients are currently insisting on no less than seven color
channels for each image. This is to accomodate proper reproduction of colors
such as DJKASccm, FER'glpur, and plaid (the color).

Actually, after a little checking, it seems that message passing only works
between a light and a surface, but not between two surfaces, yes? What I had
in mind, which now seems rather impossible, was something along these lines...

surface diamond(foo) {
float colors[nsamples];
for(i=0; i<nsamples; i++) {
output float freq = start_freq+(i/nsamples);
colors[i] = trace(bar); // where bar can move based on i and the ior...
}
// do something with color array to make RGB triplet... Or whatever.
}


surface table(foo) {
float freq=0;
surfacemessage("freq", freq);
// assume a shader that will now figure out its intensity at a particular
frequency goes on this line
// a star shader might use an equation based on its temperature, for example.
Ci = DeLuxe;
}


That make sense to anybody? There any sort of workaround to do something along
those lines for chromatic aberration?

Rick LaMont

unread,
Mar 31, 2004, 4:12:50 PM3/31/04
to
Will R <fork...@aol.comSPAM> wrote:
> it seems that message passing only works between a light and a surface,
> but not between two surfaces, yes?

It's true that you cannot pass messages between two surface shaders.

Message passing works between shaders that are cooperating to shade
a single point on the surface of a primitive. They form a pipeline
like this:

displacement -> lights -> surface -> atmosphere

[The surface shader may trigger the light shaders to be evaluated on
demand, but lights are still conceptually upstream from the surface
shader when it comes to message passing.]

It makes more sense to pass messages downstream to shaders that have
not yet been evaluated. Attempting to pass messages upstream will
yield the default value from the parameter initializer.

Now it should be clear why you cannot pass messages between two surface
shaders. Messages are not passed from one primitive to another and a
primitive can only have one surface shader.


Rick LaMont
Dot C Software, Inc.
http://www.dotcsw.com/

0 new messages