Home Unreal Engine

UE4 polarized colored reflections

polycounter lvl 9
Offline / Send Message
Mik2121 polycounter lvl 9
Searched but couldn't find anything. Sorry if this has been asked before (wouldn't be surprised). Also hope I got the "polarized colored reflections" term correct.

How would you guys go about making this kind of reflections in UE4?

stock-photo-rainbow-reflection-of-an-oil-slick-on-dirty-concrete-1282585.jpg

15D_beetles.jpg

In UE3 you could just simply add the colors on the specular without having to modify the diffuse so the colors would only show up when light would hit it. With UE4 (4.4 and 4.5 tried), I tried keeping my shaders as always (roughness and all that) but connecting a rainbow-looking texture onto the specular. I know the specular node isn't really used anymore except for some very minor control in some cases, but for things like this I thought they still would keep the UE3 use (ie, colors from the specular showing up in the reflection).

I assume now things must be done in a more "physical" way, but.. how do these reflections work? Is there an easy way to go about it or I'm looking at some fairly complex nodes?

Thanks in advance. I'll keep trying here and post if I also find something.



PS: I already found this:

https://www.dropbox.com/s/nk0i7fyj8x0zixu/Screenshot%202014-04-26%2000.54.55.png

https://www.dropbox.com/s/jfgtprgflrdxq6z/Screenshot%202014-04-26%2000.55.15.png
https://www.dropbox.com/s/cg80dszx2kbm3vl/Screenshot%202014-04-26%2000.55.20.png
https://www.dropbox.com/s/gr92kihugm6xad5/Screenshot%202014-04-26%2000.55.27.png
https://www.dropbox.com/s/l0gf8ysg5p6o9jf/Screenshot%202014-04-26%2000.55.45.png

This seems to be the closest thing, but.. is there any other way? Thanks again.

Replies

  • ZacD
    Offline / Send Message
    ZacD ngon master
    I don't have much advise, but I did see a thread talking about that effect in Marmo 2.

    http://www.polycount.com/forum/showthread.php?p=2145719

    http://en.wikipedia.org/wiki/Newton's_rings

    Maybe you can find some tech docs about what causes the effect and recreate it.
  • Mik2121
    Offline / Send Message
    Mik2121 polycounter lvl 9
    ZacD, thanks. I knew about the Newton's Rings, but I don't think that's the way all of this work (or maybe it is?). I don't really know much about the theory behind this kind of reflections.

    Anyway, I will see if I can get something done. Thanks!
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    These phenomena are all forms of iridescence, and they are similar to Newton's rings.

    The oil slick is typically known as a "thin film" effect. Light partly reflects from the surface, and partly passes through the thin film, then reflects from the layer underneath. Different colors arise when the film thickness is an even multiple of half the wavelength of that color. The wavelengths constructively interfere and so a color stands out, other wavelengths tend to cancel as they interfere destructively.

    Beetle shells are a similar phenomena, but the shell itself is comprised of many many layers of chitin stacked together like shale. The microscopic structure of thee chitin plates reflects light in a similar way as the oil slick, as each layer of chitin is subtly separated from the others by a sort of organic adhesive. Since there is a boundary between materials, reflection and refraction can occur. The substructure of the chitin also winds up polarizing the light. There's a species of golden beetle who's chitin plates stack in a spiral pattern, which circularly polarizes the reflected light, rather than linearly. Other beetles may be similar.

    All that is why EQ says "Iridescent/pearlescent are sort of their own thing, and would likely require a custom shader."

    You could likely get passable results by using a dot product from camera to normal, using that as the UV input to a color ramp that held the colors you wanted, then combining that with a mask onto the iridescent parts of the model in the diffuse channel, and making sure the metalness was way up for those areas.

    that will get the iridescent effect to follow the viewer correctly (the colors correspond to the relative thickness of the chitin normal to the viewing angle) but also reflect nicely due to smoothness and in proper color shift due to metalness.
  • Drew++
    Offline / Send Message
    Drew++ polycounter lvl 14
    Here's a simple "Newtons Rings" / "Iridescence" material. Just requires 1 'rainbow' spectrum gradient texture. I also included an option to shift the hue to match your ideal material.

    ThinFilm_Iridescence_UE4.png
    ThinFilm_Iridescence_UE4_Material.png
  • Rooster128
    Offline / Send Message
    Rooster128 polycounter lvl 8
    Wow- this is awesome! I've been trying to figure out how to replicate pearlescence too. This is super helpful! Awesome explanationVailias and Drew!
  • cmc444
    Offline / Send Message
    cmc444 polycounter lvl 11
    This is fantastic! Thanks for sharing:smiley:
  • Christian Cunningham
    Offline / Send Message
    Christian Cunningham polycounter lvl 10
    Trying to make something like this, I really need some help here. And the links seem to be broken. Any tips?
  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    @Christian Cunningham
    Not sure if you have found a solution. I started to try and create one this weekend and gathered some links that you might find useful.

    Uses UE4's material editor. google translate

    Fake, but looks nice using Octane renderer

    Used by Unity3d and the one I am trying to implement/port.
    Seems to be popular
    Discussions
    I am using a custom shading model. I think that might be the best way to go about it since you can use a custom BRDF and fresnel? You can use this website (http://blog.felixkate.net/2016/05/22/adding-a-custom-shading-model-1/) to add one.
    The current results are completely wrong, but at least it's a start.



  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    Continuing on from my previous post. I managed to fix the colours so that they are sort of the same given the same inputs and did some validation against BRDF explorer. The problem was because there was no skylight calculation happening for the shading model.

  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    Following from the previous post. I fixed the issue with the noise. Unfortunately i had to go with a brute force solution and just take random samples, I found that 32 samples gives similar results, but it is still really expensive. Maybe someone knows a better way?

    I also did some playing around with the shader and tried creating some materials with it. 

    Supposed to be a holofoil card.

    A sequin cloth thing.
  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    stororokw said:
    Following from the previous post. I fixed the issue with the noise. Unfortunately i had to go with a brute force solution and just take random samples, I found that 32 samples gives similar results, but it is still really expensive. Maybe someone knows a better way?

    I also did some playing around with the shader and tried creating some materials with it. 

    Supposed to be a holofoil card.

    A sequin cloth thing.

    Heya , you think youd be able to share how you went about some of these materials?
  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    I will post up the shading model when I have some time to work on this again. There are still three issues to resolve:
    1. How to properly sample the light direction for a skylight, otherwise the shader is too expensive.
    2. The vertex instruction count is unusually high (100+) for some reason.
    3. How to share the code easily.
  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    I managed to finish this up. Turns out that this does not require a new shading model:

    I found out a couple days ago that you can include custom shader files from a material custom node.

    Also, the model only uses the mirror direction to evaluate the reflectance.

    This allows you to use it with other shading models like the clear coat, anisotropic etc.
    To use:
    Copy 'ThinFilmIridescence.ush' to 'UnrealEngine\Engine\Shaders\Private\'.
    Copy 'ThinFilmIridescenceMtl.uasset' to the project 'Content' folder.

    Here is the material network in case the uasset does not work:


  • apq
    Offline / Send Message
    apq polycounter lvl 5

    Wow, brilliant work!

    Thank you so much for sharing this with us!

    One question; if I understand correctly, the Dinc value is the thickness of the thin film? If so, would it be possible to remap it to a nm value instead? Is it just a factor of thousand maybe?

    I'm trying to match the material examples in the paper you based the shader on. I can't seem to be able to use their values though. I understand that you omitted the clear coat layer, but that shouldn't make it differ too much, right?

    Would be cool to be able to use the clear coat shader model for this, but it only accepts a float value as it seems.

    Again, great work, and thanks for sharing!

    I created a pearl material for fun:


  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    I think Dinc refers to the distance the ray has travelled from the incident point of the first interface to the second interface.

    To use the thickness, d, as a parameter you need to change

    OPD = Dinc*cosTheta2;
    to
    OPD = 2 * eta_2 * Thickness * cosTheta2;

    Yes. It is a factor of 1000.

    As for matching the images I think it is best to download brdf explorer or mitsuba since it is possible that the pdf contains typos.
    I used the values from page 5 of the supplementary pdf.
    The first one I had to change the value of Dinc to 910nm and the last two images I had to change eta3 to three to match it. Again not sure if its a typo or not.


    For the thickness values d. Using values supplied in page 8 d=350nm to d=650nm. 

    When varying values of k3 they do not match up with the images in the paper. You would have to compile mitsuba and try the values for yourself.

    You should be able to use the clear coat material for this. I have been using it with an anisotropic shader and that seems to be working fine.
  • Linkuno
    Offline / Send Message
    Linkuno null
    I am new to unreal and am trying to make a moonstone material. Like the pearl material only a solid blue iridescence. I am trying to mess with the files stororokw gave and am really lost as to what to edit in order to keep the iridescence while changing the base color to a more creamy white. If anyone here could help with that it would be greatly appreciated.

    Thanks
  • houlland
  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Looking at the Supplementary pdf and your materials at a glance, in your material you have Eta2, Eta3 and Kappa 

    Im confused with which of the material parameter names corresponds to what names in the supplementary.pdf 

    Eta2= n2? 
    eta3 = n3
    and kappa = K3?
    also with the code update I did 

    OPD = Dinc*cosTheta2;
    to
    OPD = 2 * eta_2 * Thickness * cosTheta2;
    I noticed that the Dinc doesn't work anymore, and im having trouble figuring out how to match page 6 7 and 8 with the thicknesses d.

    if thickness is 350 nm from the PDF, it would be 0.35 in the material? 

    maybe I broke something changing the code? not sure though, but nothing matches up whatsoever.
    I tried to manually eyeball and tweak the thickness d together with Eta2, Eta3 and kapa, but no combinations seem to work. 
  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    eta2 == n2
    eta3 == n3
    kappa = k3
    If your using thickness as a parameter then trying to use Dinc is meaningless.

    if the thickness is 350nm then you would input 0.35 for the thickness.

    As far as matching up the supplementary material goes it should match the behaviour and colours. There is a limitation with using the custom material nodes instead of writing a custom shading model. The first is that fresnel is applied from the default shading model. Also the reflection captures will appear with the wrong colours and the sky lighting wont work correctly. If you need to match the colours more accurately then you need to write a custom shading model.

    Here are my settings for page 7, fifth column, and first row.

  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Thanks man that's very helpful, 1 last question, in your material list was the Dinc just replaced by the FresnelBias like so?

    float eta_2 = lerp(1.0, eta2, smoothstep(0.0, 0.03, Dinc));
    changed to:
    float eta_2 = lerp(1.0, eta2, smoothstep(0.0, 0.03, FresnelBias));

    and than plug in a scaler paramotor?

    Or is that completely new code for that? Over here I just swapped out all instances for Dinc to FresnelBias, and my default is .5 for that right now.

    Edit: Hmm actually wait that's not right, ouch
    Edit 2: I'm just not getting that golden color in any of the materials.
    I've done all of them in pages 5 - 8

    Here are my mats for the 600nm, notice the farther right that it lacks the gold and red colors.




  • stororokw
    Offline / Send Message
    stororokw polycounter lvl 3
    You just need to change the following lines as below, then recompile the custom material node.
    117 float3 IridescenceBRDF(float3 L, float3 V, float3 N, float 
    The fresnel bias was just my attempt to remove the fresnel from the default lit shading model, so you can disregard it.
  • owii
    I know this is a bit old by now, but I've been trying to recreate iridescence like a Boelen's python or Brazilian rainbow boa would have, would this shader work for that or do you possibly have some suggestions on how to achieve that effect?
Sign In or Register to comment.