Mon, Nov 11, 3:11 AM CST

Renderosity Forums / Carrara



Welcome to the Carrara Forum

Forum Coordinators: Kalypso

Carrara F.A.Q (Last Updated: 2024 Nov 05 6:06 am)

 

Visit the Carrara Gallery here.

Carrara Free Stuff here.

 
Visit the Renderosity MarketPlace - Your source for digital art content!
 

 



Subject: Iridescence Part 2


marcq ( ) posted Fri, 23 May 2003 at 1:40 AM · edited Fri, 08 November 2024 at 10:22 AM

file_59693.jpg

While looking for posts on snow, of all things, I came a cross DotPainter's interesting post on iridescence and decided to experiment.

The picture here uses a shader in the highlight channel that mixes 8 colors (the rainbow plus white) based on slope. I didn't spend much time fine tuning the slope bands; the color grading could be improved and more of the red portion made visible with some tweaking.

This technique is basically what DotPainter suggested and looks good for a quick effect. By the nature of slope, though, you get a bar color banding on spherical surfaces when the color bands ought really to be round. But on some surfaces, like the glass, it is hard to tell.

Anyway, a nice technique for the toolkit but I wanted to try a formula shader shown in the next post.

Marc


marcq ( ) posted Fri, 23 May 2003 at 1:49 AM

file_59694.jpg

This picture uses a formula shader to select gradation of one of seven colors (the rainbow colors) based on the difference in the angle between the surface normal and a reference vector.

Since it is using the real normal and not slope, it avoids the banding effect of slope and produces (I think) more interesting highlights.

The shader in question could be greatly improved if the formula allowed you to enter the angles of your light source so that you could get the purple center to line up properly on the highlight. The render here has arbitrary alignment (I didn't tweak the reference vector much) which is why the highlights are more red than they should be. But it shows the basic principle.

With a mixer referencing more than one of these, each with a reference vector aligned to a light source, you might be able to get these right for multiple lights (not really sure about that ;-).

Anyway, this is just incremental from DotPainter's post (http://www.renderosity.com/messages.ez?Form.ShowMessage=720518) but seems to be an interesting effect so here it is.

Marc


marcq ( ) posted Fri, 23 May 2003 at 1:54 AM

file_59695.jpg

Here's the cut crystal effect. Same shader but with a cellular pattern in the bump channel.

BTW The color pattern can be narrowed in the formula; I have it set pretty wide to highlight the effect...

If there is interest I'll post the formula text. It's long because it references 7 colors but there isn't that much to it conceptually.

Marc


whkguamusa ( ) posted Fri, 23 May 2003 at 2:09 AM

Looks great to me, please do post the formula. mdc


mdesmarais ( ) posted Fri, 23 May 2003 at 7:11 AM

I'd like to see it too. . .


marcq ( ) posted Fri, 23 May 2003 at 8:54 AM

Formula first then explanation:

cg1 = 1;
cb1 = 1;
cr1 = 0;

ctr1 = 0.1;

cg2 = 0;
cb2 = 1;
cr2 = 0;

ctr2 = 0.2;

cg3 = 1;
cb3 = 1;
cr3 = 0;

ctr3 = 0.3;

cg4 = 1;
cb4 = 0;
cr4 = 0;

ctr4 = 0.4;

cg5 = 1;
cb5 = 0;
cr5 = 1;

ctr5 = 0.5;

cg6 = 0.5;
cb6 = 0;
cr6 = 1;

ctr6 = 0.6;

cg7 = 0;
cb7 = 0;
cr7 = 1;

ctr7 = 0.7;

sx = 0.5;
sy = 0.5;
sz = 0.5;

fo = 6;

slen = sqrt( sx * sx + sy * sy + sz * sz);

angle = abs ( acos( (sx * nx + sy * ny + sz * nz) / slen )) * 2 / PI;

v1 = 1 fo * abs ( angle ctr1);
cv1 = v1 > 0 ? v1 : 0;

v2 = 1 fo * abs ( angle ctr2);
cv2 = v2 > 0 ? v2 : 0;

v3 = 1 fo * abs ( angle ctr3);
cv3 = v3 > 0 ? v3 : 0;

v4 = 1 fo * abs ( angle ctr4);
cv4 = v4 > 0 ? v4 : 0;

v5 = 1 fo * abs ( angle ctr5);
cv5 = v5 > 0 ? v5 : 0;

v6 = 1 fo * abs ( angle ctr6);
cv6 = v6 > 0 ? v6 : 0;

v7 = 1 fo * abs ( angle ctr7);
cv7 = v7 > 0 ? v7 : 0;

red = cv1 * cr1 + cv2 * cr2 + cv3 * cr3 + cv4 * cr4 + cv5 * cr5 + cv6 * cr6 + cv7 * cr7;

green = cv1 * cg1 + cv2 * cg2 + cv3 * cg3 + cv4 * cg4 + cv5 * cg5 + cv6 * cg6 + cv7 * cg7;

blue = cv1 * cb1 + cv2 * cb2 + cv3 * cb3 + cv4 * cb4 + cv5 * cb5 + cv6 * cb6 + cv7 * cb7;

This is the formula I used in the highlights channel. Carrara doesn't appear to allow comments (or if it does, I don't know the comment delimiter.)

It isn't as bad as it looks. Basically, the formula uses the normal vector (nx, ny, nz) to compute the angle between the normal and reference vector you give it (sx, sy, sz.) The reference vector need not be normalized (i.e., don't worry about making the length "one").

This angle represents how far away from the reference vector a given surface is aligned. Zero means the surface is perpendicular to the reference vector, higher values mean more tilted. In this formula, angle goes from 0 to 1 but it could be tweaked to be in radians or degrees.

The angle is then used to determine how much of each of the seven reference colors should be shown at each point. This is linear with slope "fo".

cr1, cg1, and cb1 define the red, green and blue values for color one, cr2, cg2, cb2 for color two, etc. Values are from 0 to 1 again.

ctr1, ctr2, etc. determines the angular center of the color. A zero means the color is center around angle of 0 degrees, i.e., it shows when the facet is perpendicular to the reference vector. A 0.1 would mean the color shows at a slight angle. 0.4 at a greater angle, etc.

fo determines how fast a color falls off around its center. Use larger values for more tightly spaced colors (who have ctr values near each other) and smaller values for larger spacing unless you want a ringed effect.

Ideally the reference vector is related to your light source.

At the moment, the equation uses the local normal vector, not the global vector. It should probably use the global. Additionally, it would be better than rather specifying a reference vector, you gave it yaw and pitch of your light source and it computed the reference vector. I don't think this is a big deal except for the necessary tinkering of finding the two correct angles and then finding the right polarity of the reference vector.

You could theoretically make the reference vector (or light angles) use the p1 through p4 parameters which are supposed to be animatable.

There may also be errors in the above like my reference vector is backward or some such.

If anyone does to the anlge modification, please post or send to me. This shader was inspired by DOtpainter's post I came across but I was really looking for snow effects and need to get back to my winter project ;-)

To use this formula, cut and paste into the text of a formula shader in your highlights channel (alternately, use the color channel until you have it looking the way you want and then move it.) Adjust the reference vector to be as you want. Currently, this is just trial and error.

If you want different colors, get the rgb values for the colors you want (you can use carrara's color picker to find these by using the RGB slider view). Adjust the centering you want for each. Adjust the falloff 'fo' if the colors over lap to much or too little. A higher fo makes for a narrower band of color.

This formula supports 7 colors (for the rainbow colors); you can use less by deleting the other colors or setting their centers large. You can easily add more colors by cloning the text.

Colors need not be in order but it helps to keep track of them.

As a tip, the carrara formula window is tiny and hard to edit in. I used word to do my edits and cut and paste back to the window.

Keep in mind that you must hit 'parse' for the new formula to take effect and that the parser is not very good. It is unforgiving of the lack of space (put space around every variable and operator) and don't forget the semicolon at the end of the line.

Marc


marcq ( ) posted Fri, 23 May 2003 at 8:57 AM

BTW if anyone uses this formula for an image, I'd love to see what it looks like. Should be able to give your diamonds 'fire' and might look pretty neat in some GI renders. Marc


marcq ( ) posted Fri, 23 May 2003 at 11:12 AM

Oops- just noticed my RGB values are 'wrong'. Color 1 and 3 are the same. I think one should be cg1= 0; cb1= 1; cr1 = 1; which would put more purple in the scene. Marc


Kixum ( ) posted Fri, 23 May 2003 at 12:18 PM

WOW!!!!!!!!!!!!!!!!! Thanks a whole ton for posting this. It seems that it should be something that some of our plug-in gurus could also whack on. Thanks so much for posting this! -Kix

-Kix


marcq ( ) posted Fri, 23 May 2003 at 1:37 PM

I have been trying to convince one of them to do this. Please help apply pressure ;-)


mdesmarais ( ) posted Fri, 23 May 2003 at 2:27 PM

Excellent! Thanks. I've played with the SDK a little- seems like you've done most of the hard work for making a shader. . . there would be a butt-load of sliders though. ;-) I don't know nearly enough to get the true angles to the light or anything, but you're right- for someone with some experience, this would seem do-able. Hmm, multiple lights might get funny though. . . Markd


marcq ( ) posted Fri, 23 May 2003 at 3:56 PM

I think for many scenes you don't need true angle; you just want some 'fire' in the scene. For distant lights, the angle to the light should be the yaw/pitch angles. It is tough for spots but for most of those, an approximation may do (i.e., treat as a distant light). It sure would be nice to have this as a plug-in ;-) Marc


whkguamusa ( ) posted Fri, 23 May 2003 at 4:40 PM

This is very interesting! Can I ask what kind of background you have that you can do something like this? It is completely over my head (I have a hard time figuring out what country code number to add to an area code to make an international call). Thanks again for posting both the information and explanation. mdc


marcq ( ) posted Fri, 23 May 2003 at 5:32 PM

Oh, I'm a hardware engineer by trade. But I'd forgotten how to find the angle between to vectors. I just typed in "angle between two vectors" into google and get several hits. The rest of it is fairly simple algebra although since the formula syntax is a subset of C, it helps to know C. When I first read the Carrara manual, I blew off formulas but I've since come to find them very useful. I wish there was a way to use one as an operator, i.e., have it operate on underlying data. Then you could do some really cool stuff. Marc


bijouchat ( ) posted Sun, 01 June 2003 at 12:48 AM

oh gosh... I'm going to have to play with this!!!!! thanks for posting it!


marcq ( ) posted Sun, 01 June 2003 at 1:42 AM

Enjoy... and please post any improvements or note any images! The reference vector is definitely off in this picture. The formula could be reworked to generate a reference vector from a pair of angles. Given that, one should then be able to get those angles to match two of the angles used on a light source making aligning with your light source much easier. (Alignment is important if you want to use a narrower spread of color like maybe in a gem picture; although if you just like the look but want more blue than red, rather than play with the reference vector, you could also change the colors around; i.e. swap blue for red.) Someday I may play around with that but if someone figures that out sooner, please post the amended formula. Bijouchat, I'd forgotten you do a lot of gems and jewelry; I'm eager to see what you do with it! Marc BTW I can't resist anymore... I used to have a cat name Bijou (for real; nice siamese)


bijouchat ( ) posted Sun, 01 June 2003 at 7:21 AM

cool! (about the cat!) well, how my nick here came about is that my usual nick is bijou. But some ingrate g got to my nick first at Renderosity so I had to choose a different one... so I chose bijouchat... as I am always called a cat by my boyfriend due to my rather feline nature. g anyway, about the formula, I suck at math, though I have two mathematics reference books to help with these things when I need it. (and that happens more often than you might think when doing shaders lol) But I do know a few things, and I know that in gemstones, the dispersion aka iridescence (and the patterns caused by refraction for that matter) are related to the refractive index. I use a cad program to help me with the correct angles for light refraction before the gemstone model ever enters Carrara. Carrara does refraction very well (helped along with the Fresnel shader from Lost Horizon though!), as is shown in my blue Hope model... all the patterns in that render are caused by refraction, none are postworked. Was a heck of a job getting the model to be shaped as much as possible like the real stone to pull that off. its important to note, that violet refracts more than red. So changing the colour to reflect more of the blues/violets and a little less of red would be more accurate regarding gemstone dispersion. I guess I better hit those pages about optics again... lol. Boy, gemstones have me running back to the science books all the time in the name of art g I'll be sure to show you what I come up with!


marcq ( ) posted Sun, 01 June 2003 at 11:00 AM

You are correct about the refraction varying with wavelength; the formula above is a cheat to model that. I can't think off hand of a way to do real dispersion in Carrara other than to do multiple renders with slightly varying refraction indices and combine them in post. Might be tedious but for gem only pictures like you do, it might not be too bad. On the handle, it's amazing how seemingly always obscure names are already taken. Or my handle which is a combination of first and last name turns out to be a river in northern France. I've received mail several times from people wondering if I'm a relative (since the river name has become a family name). Marc


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.