Is it possible to create an iridescence shader in Cycles?
Specifically for something like DVDs, soap bubbles, engine oil, etc..
-
$\begingroup$ would an OSL shader be an acceptable answer? $\endgroup$– zeffiiCommented Jul 3, 2013 at 9:08
-
$\begingroup$ @zeffii, it's worth a shot. $\endgroup$– CharlesLCommented Jul 3, 2013 at 14:30
-
1$\begingroup$ True iridescence probably isn't possible: blender.stackexchange.com/q/17/14 $\endgroup$– DanielCommented Jul 16, 2013 at 12:45
-
1$\begingroup$ See also: blenderartists.org/forum/… and blenderartists.org/forum/… and blendswap.com/blends/view/70401 and luxrender.net/wiki/Pearl_material $\endgroup$– Dave JarvisCommented Oct 11, 2015 at 1:14
3 Answers
From your linked definition of iridescence:
Iridescence [is] the property of certain surfaces that appear to change color as the angle of view or the angle of illumination changes.
Thus, the following node setup should suffice:
If you're not familiar with node groups, this will create a new "node" called Iridescence that takes a base color parameter (you probably want white) and a factor parameter (which determines how strong the iridescence is; you probably want about 0.4) to output a color that you can put into a shader. You can see examples of how this works before.
The setup simply takes the dot product of the view vector and the surface normal and maps it to a spectrum. If you're not familiar with vector math, you can basically think of a dot product as a measure of how parallel two vectors are: the dot product of two perpendicular vectors is 0, while the dot product of two normalized parallel (or anti-parallel) vectors is 1.
You can put this node group in any shader and get a nice result. I tried it in a Diffuse BSDF, but putting it in a Glass BSDF might yield some nice bubble renders.
Here's an image of Suzanne wearing her iridescent cloak (the factor is set to 1.0 to exaggerate the effect):
Here's the factor turned down to 40% (lower works in better lighting setups, but my sky texture is blowing it out):
-
1$\begingroup$ It's sometimes also nice to Add a magic or distorted noise texture to the Normal or Reflection coordinates $\endgroup$ Commented Aug 13, 2013 at 8:37
-
$\begingroup$ Could you post an EXPANDED version of the node-setup in your iridescence shader? I can't even guess at what is in "Group Input" and/or "Group Output"...Otherwise it LOOKS like a great shader... TIA... :O) $\endgroup$ Commented Aug 20, 2013 at 23:06
-
$\begingroup$ @DavidA.Lewis please see my edit. $\endgroup$– wcharginCommented Aug 20, 2013 at 23:09
-
1$\begingroup$ @DavidA.Lewis Node groups were changed a lot in 2.67. That is the expanded form, the nodes "group input" and "group output" are now part of the way node groups work (and can't be expanded). $\endgroup$– gandalf3Commented Aug 21, 2013 at 2:54
-
$\begingroup$ Why did you use the camera vector? How well would that work with something like a mirror in the scene? Should you perhaps use the incoming vector instead? $\endgroup$ Commented Jul 22, 2017 at 5:02
True iridescence is difficult to achieve using Cycles. However, there are ways you can fake the effects of iridescence by shifting the color slightly based on the object normals. This has the advantage of being highly customizable for your particular purpose and much faster than true iridescence would be.
Update: I was able to find an implementation of this using Cycles on this BA thread.
Here is the node setup:
And an example render using the above node setup with different values:
EDIT: Found a better implementation done directly in Cycles. The old BI node setup can be found here.
-
$\begingroup$ Noise Scale: 5 Million!?!? Is that necessary for faking some tiny surface geometry that creates iridescence? (Nice answer, btw) $\endgroup$ Commented Mar 14, 2016 at 8:14
-
$\begingroup$ The setup posted here is far from correct (I know because I'm the author of the mentioned thread). The noise scale only serves for sampling purposes, as we need different seeds for each sample, but as I mentioned in that same thread, the output values are not normalized, and create a strange bias in the wavelength distribution. For diffraction grating (CDs, DVDs, etc), I'd advise to use my OSL script (also in the thread), wich is more accurated and physically based. $\endgroup$– SecropCommented Feb 23, 2018 at 10:05
This is where OpenShadingLanguage can step in. Using an OSL script you can get an iridescence effect.
Michel J. Anders has already done the hard work on his Small Blender Things blog with his surface iridescence shader. You may find some of his other scripts interesting as well.
For example: