 Let's go. Welcome everybody. My name is Robert Moulant. I am here today to talk about hacking interference phenomena into your renders. Let me start off with two possible disappointments. First of all we are in the developer attic and it says hacking in the title but I actually didn't change a single line of code in Blender. So everything that I show you will run on a vanilla Blender 3.3. The other disappointment might be that I am not a computer graphics scientist. I don't write renders, I don't do shader programming. So why should you believe anything that I have to say here? My name tags as illustrator, photographer. So hopefully to instill a bit of faith in me, the knowledge that I have 17 years of academic experience in nano photonics might alleviate the problem a bit. I see this as a double-edged sword where on the one hand what I show you is what I can do and to make things as physically correct as I possibly can. On the other hand a smart computer graphics scientist might be able to do the same thing with minimal loss of visual quality and 10 times faster. But here we go, it's something and it's better than nothing I guess. So what are we talking about? You probably have all seen phenomena like this where you spill a bit of fuel on a wet patch on the tarmac and you get all these colors and where do they come from because you did not put any paint on the tarmac. This is a well-known example, but if you look a bit more closely you actually will see also on the steam pipe of a coffee machine to make milk froth there is this rainbow-like banding effect going on as well. Here this is the electronic eye of a urinoir that was just cleaned and the detergent has left a residue here that also instills these colorful patterns. And if you got here by train you might actually have had a look at the windscreen here if you zoom in there is also this purple yellow coloring going on. But of course one of the major and most well-known examples the prettiest perhaps is the soap bubble and one of these two is a photo and the other one is a render and who here can immediately spot which one is a render who is sure like that's the render. This result is something you can get yourself like the at the end of the talk I will show you QR code and you can download the notes that I'm presenting here with all the materials in it just from blender artists and street to use for whatever you like. So why is this happening so let's have a bit closer look at light we're blender users we know the essentials we know reflection we know refraction reflection is you have a light ray and it's bumps off a surface and I can see it on my sensor camera or in this quick this case the computer and refraction is this banding of light around that is caused by transparent objects at the surface here this is going on with the light ray as it is treated by cycles so you have an incoming light ray and I chose just for simplicity air and glass but it can be any combination but let's say air and glass we have an incoming light ray and a small fraction of it is reflected and another fraction of it is refracted and the angle with which the refraction takes place is determined by a constant that we call in optics refractive index though you would see it as index of refraction in blender typically and for air it's about one and for glass it's about one point five now the the angle is determined by the refractive index but also the amount of light that is reflected and refracted and the first person to actually derive the equations for how much is it was Augustin Fresnel to which we will get in a second but this is the model that is implemented in cycles for glass if you take the plain glass shader what it does internally is it calculates the the like the Fresnel coefficient how much light is refracted or refracted and then splits it up into shaders a refractive and a glossy shader so you can substitute this glass shader here for this small node group it does exactly the same if you would render both images you get the same output and what you see is it on the top is a refractive shader on the bottom is a glossy shader and the Fresnel node so there is Mr. Fresnel the Fresnel node is dictating a mixed shader how much of the light goes where and the angle dependency you see back if you look at the Fresnel node itself with the node wrangle for example for example the steeper the angle is the more light will be reflected it's exactly what if you've seen the talk by the Andrew Price he said exactly the same so this is really essential for photo realism so that is thick objects let's go to a thinner object but still relatively thick let's say a millimeter or so this is microscopic for light what happens is I have my light ray coming in a bit is refracted reflected large amount is refracted then I get an internal reflection which is them subsequently again refracted and cycles will take these two light rays that are reflected add them together and that's your output but if you now go to really thin films and that's not a millimeter but a thousandth of a millimeter or smaller you cannot circumvent looking at light as a wave so at this scale you cannot distinguish any more like light is a ray you have to look at it as waves but the essences are still the same I have a wave coming in I have a wave that is reflected it has a bit smaller amplitude because it's less intense I have a refracted wave which is then internally reflected and also refracted again but the major difference here is that the amplitude of the first reflection and the second reflection can be opposite in phase so they are instead of adding they are canceling each other or at least partially canceling each other well this phenomenon goes on and on and on for an infinite amount of times until I don't have any light that is coming out anymore and that is the end result of what cycles should report to your virtual camera that this is the color of the pixel the color of the pixel also depends on the wavelength of the light which is just the color of your light it depends on the angle of incidence it depends on the refractive index of your film and it depends on the thickness of the film and you can even go beyond this it doesn't need to be glass it can be a metal it can be an absorber and why stop at a thin film in air you can also make you substrate a metal a glass or an absorber so summarizing thin film interference and the color of your pixels depend on the incoming color the wavelength the angle film thickness the refractive index of your film and the refractive index of your substrate my goal was to create a note for thin film interference that would replace this Fresnel node and give you a physically accurate model that actually shows the interference that's versatile easy to use and GPU compatible implementation which is going to be high-level because I would like to show you the examples but this from code to note I implemented this first in OSL so open shading language and for for this kind of physical problem it's very useful to use complex math and if you're not familiar with complex math it's essentially an extension of the everyday math that we have but it's really good at bookkeeping waves and faces and how they add together so it's an easy tool to do or to have but it's not available in open shading language itself so I implemented it Python on the other hand does have complex numbers so I use Python to benchmark that what I did in OSL was actually working and correct within machine precision then as I said I've worked as a researcher in nano photonics for quite a while I have mudlap code that tackled this phenomenon and I ported it to both Python and open shading language because I'm not in academia anymore mudlap licenses are expensive and Python is there and I used both these implementations to benchmark the one against the other on the left hand you see one of the more intricate examples with with wildly varying colors as a function of angle which which are physically correct and on the right hand side you see the difference between the Python implementation and the OSL implementation which is for academic standards not great but for visuals it's fine then I had a working and benchmark OSL code I wanted notes I was very happy to come across OSL Pi by Lazy Dodo Ray Molenkamp and the only drawback here was that it was last updated May 2018 and for Blender 2.8 by now Blender 3.3 has a way more versatility with the vector math notes and I found a little bug so I benchmarked OSL Pi conversion from OSL to the node groups by both visually checking that this was like what I wrote in OSL was actually also translated to the correct node group and by simply running the OSL code versus the node and making sure that the difference would be zero so it's it's all benchmarked to the best of my abilities but no guarantees results three node groups one on the left thin layer on glass in the middle of rain layer on the conductor or a metal or an absorber and on the right a double layer on the conductor and to start off with the first one here layer on glass this is how you hook it up so this is the Fresnel substitute as it were you can just add a refractive index I called it and it's the custom way of calling index of refraction in in physics and you can add the refractive index and the extinction coefficient of your layer and the thickness and the rest will automatically follow so here's the soap film on the left the refractive index of the substrate is air and therefore it's one the layer is simply 1.4 for the red the green and the blue value you can see that the n layer actually is a color input so you can add a different refractive index for each color and then I animated the thickness D and you automatically get the colors that you see on the right hand side oil film where I for dramatic effect did not connect to the transmitted node transmitted light node so you really get this dark patch of material with the interference coming from your oil spill and the only difference here is the refractive index that I put in there the layer of the substrate is water and is 1.33 and the thin layer has a refractive index of 1.6 which is something like turpentine I believe anti reflection coating commonly used on optics like your spectacles or your camera objectives etc there is a very simple version of an anti reflection coating which uses a magical thickness of your layer if you make the layer zero you get the plain glass if you connect the node to have the correct thickness you see that the reflection actually reduces and it's reduced and not gone because this simple anti reflection coating only works for a single wavelength so the other colors are still partially there later on the conductor it's a slightly different in the sense that now you can choose your refractive index and extinction coefficient also for your substrate and this allows you to use metals so metals also have a refractive index and they have an extinction coefficient so before going to the layer part I want to show you an example of just using this as a metal shader like I said before the colors give you or the N and K are color inputs so you would need to hook up the refractive index of the metal that you would like to use with a color input box just a note and you get these values from websites like refractive index.info where you type in the wavelength that you want to use and it says this is the refractive index of this material at that wavelength so here on the left I did that for copper there's a copper N and a copper K for red green and blue in both cases and I just connect the node to a glossy shader and you immediately get something that looks like copper you can do the same for gold the values for N and K are different but you automatically get a gold colored substrate like I said I am not a computer graphics scientist and nor am I a coder we have Lucas Stockner in the audience who is a coder and who knows approximations better than me so if you only want to have a realistic metal shader what I created here is then overkill for you because it calculates too much and within a good approximation you can get very lifelike results and tomorrow Lucas will talk about the implementation in that in the principle shader in blender but what that can cannot do is then adding for example an oxide on your copper layer so I just took refractive index of copper oxide from refractive index.info and I drive the thickness from zero and then you get your plain freshly cut copper color and if you add thickness of the copper oxide with some noise pattern you get what I think is a pretty decent age copper look. Heating of iron if you remember the steam frothing pipe the iron refractive index you plug them in the iron oxide refractive index you plug them in you drive the thickness of your layer and you automatically get the colors that you see here and on the right hand side you see a small piece of differentially tempered steel which essentially is the same color scale and finally no not finally one more example silicon with an oxide layer if anybody ever worked in a clean room they have silicon waivers there and silicon itself looks a bit gray bluish as you see when the layer is zero but it automatically oxidizes as well or sometimes in a processing step you add oxide and it turns purple but kind of purple depends again on the angle. You just cleaned your kitchen and somebody puts their greasy finger on your on your metal it is an interference effect so this is how you get like a realistic fingerprint on your metal. Then finally a bit garish but this was a special request in the blender artist thread double layer for mimicking polychromic car paints and they are typically made from a sandwich of a very thin top layer of metal then a dielectric layer a glassy layer and then again a metal bottom layer so in this case I have a chosen chromium six nanometers so that is six billionth of millimeter yes and it's partially transparent and then there's the glass and then there's aluminum which is optically thick so it only reflects and I drive the thickness of the glass layer and you should start to see something maybe now huh interesting luckily I'm doing this on my own laptop so I can just go there here then there we go that's what you get if you drive the thickness and it goes completely all over the place but some people like it back to the presentation luckily I don't have many slides sure limitations because I said that it's like to the best of my capabilities I made it physically correct but there are limitations in a renderer that's based on RGB so on the left hand side as an example you see the soap film color as a function of soap film thickness for what would be in a spectral renderer and I took the d65 white point here and what you see is that initially it starts out with the color banding but as the film comes becomes thicker you will get a sort of gray reflection which is exactly what we expect from glass thick glass reflects like white and not colored cycles the cycles implementation will just keep going it will never stop but then again it is thin film interference so if you go for thin film and then smack like a millimeter on top of your model then it's not really thin film anymore so but anyway there is a limit to the usability here but it's like let's say in this case 700 nanometers 0.7 micron it's pretty much the same as a spectral renderer at least visually other limitation is if you have roughness the micro facet model and this node group they don't communicate so the node group calculates the ink the final color for this single ray that comes in but the the shader itself will subsample the space to find out the final value of the color because they don't communicate it will always use the color of the node group while sampling whereas if you would combine the two it would actually calculate the correct color per sample so this is not something I can fix without hacking or actually hacking into the blender code yeah with that I come to an end here are some acknowledgments for photos for the previous scene etc here's the QR code if to the goes to the link above if you would like to sample the materials that I put there thank you yeah it's it's different math yeah so you're then looking at diffractive optics so but the fly is it is both geometrical like color color through structure but thin films are easy to describe with level relatively simple math and if you go into the realm of photonic crystals and and like color through structure you can make it very hard very quickly yeah no no no no I know that on blender artists there are some people that have at least implemented mimicking the diffractive optical elements but yeah it's it's just different math anybody else anything absolutely absolutely ah in that case the the let's let's just go to that image in that case the thickness is relatively thin it's not constant I faked it here by driving the thickness with two noise structures one rough noise structure and then a I think it was a magic structure where the input vector was driven by another noise yeah so get the swirly effect because that's exactly what I saw in the photo that I use as a reference so with these thicknesses like it's accurate but exactly what you said like as soon as you go to really thick layers just plug in a Fresnel note or something like a glass shader and make the smooth transition where you like it to be to go from the interference shader to the standard macroscopic shader yeah this this was RGB both sorry s RGB both yeah but the photo is also s RGB right so that's not the reason but but I am interested in how this translates to other color spaces for sure yeah yeah yeah yeah so essentially the approximation in in this node group is that you say my red green and blue colors are lasers that that's essentially the assumption between the math so so you mean in the respectful implementation I did that if you go to the the threat I did that to compare for the s RGB color space where I put a spectral implementation of like over the full sun spectrum and it's it is different but it's also much much slower so I would say it's not worth the effort but it is possible the problem here is that you're still you're assuming a spectrum that man I did it for the white light spectrum but if you have a yellow light in your scene in your scene what yellow is it is it is it like some hot metal or is it a fluorescent tube and that that kind of information we simply don't have in cycles yeah yeah yeah and smaller I mean this is within the limitation that I already told you is accurate down to zero nanometer so if you make this if you look at the bubble it actually starts as be not being there because if there's no bubble layer it's not there so it's really physically accurate in that sense it is tight like why it works down to zero is because the model assumes it's all an infinitely flat plane whereas the virus has 3d structure that you cannot resolve anymore with light they are but that like what saves us here is that the film is only thin in one direction and does not contain any information other than the thickness thank you very much