Search Unity

Transparent colored plastic-ish material

Discussion in 'General Graphics' started by Raitoning, Jun 1, 2016.

  1. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Hello everyone,

    I'd like to know how to create some transparent colored plastic-ishmaterials like this picture:
    Source: http://www.hunterlab.com/images/content-images/PLASTIC_Preforms_Overview.png

    Most glass material makes objects completly transparent and usually refractive, but I can't find a way to have this result.

    Thanks for reading me, I hope someone will find a solution :)
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I usually ignore the refractive properties and render it in two passes. The first pass outputs the color which is multiplied with the backbuffer. The second pass is additive and renders the reflection. So I use these two blend modes:
    Code (csharp):
    1.  
    2. Blend Zero SrcColor
    3. // Output color
    4. Blend One One
    5. // Output reflection
    6.  
     
  3. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Hi, thanks for replying.

    Unfortunately, I don't know anything about writing shaders. It's a thing I've planned to learn later, but it seems that I'll have to learn that now... Got any good tutorial ?

    Thanks for replying :)
     
  4. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    If you don't care about the refraction you could get reasonable result using the standard shader.

    Set rendering mode to transparent, then give it a fully blue albedo color with alpha set around halfway.

    Metallic to 0, and smoothness quite high.

    Not perfect, but if you add a reflection probe (or even use screen space reflections) it won't look half bad.
     
    martinmarty likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Screen space reflections don't work on transparent materials.
     
    Adam-Bailey likes this.
  6. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    Ah, hadn't tried that. Good to know!
     
  7. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Hi, sorry for late replying.

    I've already tried to put the standard shader on transparent rendering and it is not that good. It seems that sometimes other objects overlap it even if they are behind it. I will put a screenshot when I'll be on my computer.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Unity's batching screws with the sort order of transparency some, but the short version is real time transparency is an unsolved problem.

    http://forum.unity3d.com/threads/render-mode-transparent-doesnt-work-see-video.357853/#post-2315934

    There are a couple of recent techniques that "solve" the issue of "order independent" (properly sorted) transparency, but they more accurately approximate it better, and really they just have a different set of artifacts. They're also all much more expensive.
     
  9. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    To be more precise, I'd like to have the very same material as the PS2 bios:

    source: http://motkar.pl/e64news/pcsx2.jpg

    The standard shader doesn't seems to fit this, and the refractive glass shader given in the standart assets package make the object completly transparent and add refractions that are a real FPS killer. What I'd like is a transparent material but not 100%, with a diffuse color. The tubes I've put in the first message are transparent but you still can see them because those got a blue diffuse color. Just like the PS2 Bios, the cylinder-like floating things are transparent but got a blue diffuse.

    I hope someone got a solution :) Thanks for reading and answering me :)
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    More accurately those have an environment map gloss, possibly just a strong fresnel, and a blue tinted refraction. There's no actual lighting on those at all, just a lot of fakery.
     
    Adam-Bailey likes this.
  11. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    I quickly mocked up this, does it look along the right lines? :)



    The attached image has the material settings I used. The only other thing I used was a reflection probe with the intensity set up to 20, to get nice bright glints.
    example.png
     
    Last edited: Jun 8, 2016
    Quast, Raitoning and neoshaman like this.
  12. Raitoning

    Raitoning

    Joined:
    Dec 13, 2014
    Posts:
    100
    Wow, so many thanks ! How did you managed to found a way to achieve this result ? I've played for hours with the material settings before giving up. Mine doesn't look as good as yours but is nearly the same. I got a slight FPS drop when the camera is near the cylinder, maybe dropping from 30fps to 20-25fps, but it is good enough.

    I'm still impressed that an old PS2 could handle this kind of material and refractions in real time, because my laptop can't handle this really well. I got a frame drop from 60fps to around 20fps when I use a refractive material. I know that there's a lot of things that are different between a console and a computer, but well, it's still impressive!

    Thank you so much again !
     
  13. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    Refractive materials will hurt performance, my example doesn't use any. The ps2 was really quite powerful in terms of fill rate, so it did well with effects that layered on top of each other.
     
  14. leitecunha

    leitecunha

    Joined:
    Jun 26, 2013
    Posts:
    7
    Hi everybody, I wrote a shader for glass (and translucency or custom lightmaps too) called Standard Plus. I think it does what you want because you can just put the refraction to zero. My glass has various controls on refraction, as well as fresnel. And on top of that, you can use thickness map to count for the model different thickness, producing much better results, because the thickness will affect not only the refraction but the glass color as well. And on top of that, it has the same functionality of the standard shader.
    Take a look! https://www.assetstore.unity3d.com/en/#!/content/93745
     
    Adam-Bailey likes this.
  15. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Well, that all depends on the accuracy. A simple one time refracted ray that looks up in a cubemap does not hurt performance much at all. Raytracing 16 bounces in 3 colors would be a lot more accurate and still no problem for desktop hardware. I tried this once years ago, 2009. (I should really make a new version of that in Unity...)

    (Sorry it's from before the HD time.)
     
    Adam-Bailey likes this.
  16. martinmarty

    martinmarty

    Joined:
    Sep 19, 2017
    Posts:
    7
    4.5 years later, Thanks!
     
  17. UnanchoredStudios

    UnanchoredStudios

    Joined:
    Jan 26, 2020
    Posts:
    6
    I found that using a reflection probe really helps.