Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Which material shader will demonstrate glass of vehicle?

Discussion in 'Editor & General Support' started by EndUser, Nov 10, 2014.

  1. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51
    Salut!

    I have a coloured texture of a vehicle.

    I decided to put transparency windows on the diffuse texture for glass windows.

    But the shader "Transparent/Cutout/Diffuse" either makes windows non-transparent completely (if Alpha < Alpha Cutoff), or transparent completely (if Alpha > Alpha Cutoff) without any shade of the glass.

    On the other hand "Transparent/Diffuse" makes the glass visible and transparent (semi-visible :)), but completely destroys the mesh making half of it transparent too.

    "Transparent/Soft Edge Unlit" makes the glass semi-visible, but the vehicle have no rendered light and shadows.

    What shader should I use to get "Diffuse" for solid parts of a vehicle, and at the same time get semi-transparent hue of glass windows marked by alpha-channel of the texture?

    Thank you!
     
  2. oysterCAKE

    oysterCAKE

    Joined:
    Dec 3, 2012
    Posts:
    150
    Cutout won't help you - what cutout does is make areas either 100% visible or 100% invisible. Good for things like chain link fences or icons or whatever, not so much for anything else.

    Transparent/Diffuse is what you want. BUT, you need to set your model up to use different materials on different parts of the mesh.

    What 3D editor are you using? In, say, Blender, it's as simple as assigning a new material on the desired faces in the editor. Then, you'll get a new material slot in Unity's mesh renderer, and can create a transparent material & drop it on to the model's windows for happy results.
     
    EndUser likes this.
  3. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51
    Thanks!

    Yes, it is Blender. Mostly I am a programmer, not a designer.

    Therefore I don't know how to work with materials in Blender. Please, don't feel offended by my comment, but I really thought there is a sexy combined shader to display solid parts and semi-transparent parts at the same time.

    So, my way is:
    1) Blender: to separate window polygons into sub-mesh;
    2) Blender: to create two materials, no matter which ones;
    3) Blender: to assign one material to entire mesh. Assign second material to window sub-mesh;
    3) Unity3D: to use two automatically created slots for two materials in that entire-mesh, Diffuse for entire vehicle, and Transparent/Diffuse for semi-transparent windows.
    Correct?
     
  4. oysterCAKE

    oysterCAKE

    Joined:
    Dec 3, 2012
    Posts:
    150
    Right, sorry for delay in responding. Put together a little tutorial to help guide things. Image heavy post coming up. Sorry if it comes across at all patronizing, didn't want to miss anything!


    So, to start off we've got our model, in blender. For the sake of argument, we've got both the transparent and solid areas on the same texture. If they're not on the same texture, then simply applying different textures to different parts of the UV in blender will give you multiple materials. But we'll go this route, it's better for learning.

    So this is the inspector that we get from the above model (having disabled animations in the importer). 1 Material slot, and by default it's using the diffuse shader.

    Most straight forward answer is to set the transparency in the texture image. Then, all we need to do is to change the material's shader to Transparent/Diffuse.

    This gives us the results we want... but it's probably not the best way to go about things. As they are, we can't adjust the transparancy in the editor without affecting the solid areas. We'd also have problems if we want a half decent specular or bump mapped effect anywhere. Much nicer would be to set the model up with two materials for this. For this, we *don't* need transparancy in the source texture.

    Back to Blender. We'll need two materials, so - create material slot, then add a new material. Doing this twice, of course.

    Select the solid areas of the model, select the first material & click assign. Then select the transparent areas, chose the 2nd material and assign that. Save and flip back to Unity.


    Woo, now we've got our 2x texture slots in the Materials dropdown. Just need to set up the transparent material.

    Find & duplicate the material thats already being used on the model. Change shader to Transparent/Diffuse, then drop the alpha down (can fine tune this later!)

    Assign it to the correct materials slot on the model...

    And Hurrah! It's all good now.
     
    Last edited: Nov 11, 2014
    EndUser likes this.
  5. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51
    Man, this is a ready to use tutorial, and that is great not only for me, but for the entire community!
    Thank you very much!
    I will follow your instructions step-by-step and will report if any unresolved issues occur.
     
  6. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51
    1) I haven't found "Assign material to selected vertices". Could you describe it?

    I separated window vertices into independent mesh (Vertices/Separate/Selection), assigned a material and then joined windows back to hull.
    The result is the same: two material slots for the hull mesh.

    Excellent! The result is Diffuse for hull and an independent shader for windows.

    2) Is there any way to make window polygons two-sided? They are semi-transparent when looking from outside, and totally invisible when looking from inside. They look like one-sided.

    Thank you!
     
  7. oysterCAKE

    oysterCAKE

    Joined:
    Dec 3, 2012
    Posts:
    150
    Hey - sorry. Been travelling past few days.

    Assign material to selected vetices - is that in the blender? You don't need to seperate things apart - once you've created the material, just select the appropriate faces and click the assign button.

    Window polygons... you could create a shader for that, I believe (unfortunatly shader coding is a skill thats beyond me)... but the easiest way is just to duplicate the faces in blender and hit "W" -> flip face normals.
     
    EndUser likes this.
  8. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51
    Roger!
     
    oysterCAKE likes this.
  9. EndUser

    EndUser

    Joined:
    Aug 12, 2013
    Posts:
    51