12
\$\begingroup\$

Anyone know how to make a glass material in Unity 5?

I can do metal and image textures, but not sure how to create a glass material.

A search on Google would not get me anything for Unity 5 so it must be fairly easy to do.

It's for a shower door and plane glass like this:

glass

\$\endgroup\$
  • \$\begingroup\$ You'll need to either post an image showing what you want or describe it in more detail. Do you want to have refraction? Do you just want a mostly transparent pane? It's not at all clear what you're trying to achieve. \$\endgroup\$ – user1118321 Apr 17 '15 at 2:12
  • \$\begingroup\$ Are you using Unity free or pro? \$\endgroup\$ – Katu Apr 17 '15 at 4:08
  • \$\begingroup\$ Using UNITY 5 Free \$\endgroup\$ – Icewine Apr 17 '15 at 4:09
  • \$\begingroup\$ So you want it to be transparent, slightly darker and have reflections, then? (Just trying to clarify.) \$\endgroup\$ – user1118321 Apr 17 '15 at 5:03
  • \$\begingroup\$ Yes that is correct \$\endgroup\$ – Icewine Apr 17 '15 at 5:07
13
\$\begingroup\$

Here's few things i could gather up, hope this helps you. There's multiple ways to get this done. You can write shaders or if you don't mind about having very simple glass, you can use default shaders and some PNG magic.

  1. Glass Shader made by Alastair Aitchison
  2. Reflective transparent "Glass shader" made by benoculus
  3. Unity asset store search: Glass
  4. Free asset - Breakable glass

EDIT: As this is getting some attention, i decided to add step by step tutorial for very basic window/transparency

  1. Create PNG image with transparency on places, where you need it.
  2. Drag and drop it to your assets inside Unity
  3. Drag it from assets to your gameObject, that you wanna use as glass
  4. Select shader -> Transparent -> Specular ( or any of the choices, i liked specular )
  5. Enjoy

I created simple 64x64 image with full background transparency and added black text on it Transparent PNG

Then i imported it to unity ( dragged it ) and then dragged it over the cube i had there. After that, i selected transparent shader for it. Step by step image

Results ( game is running ) Result cube

After this, you could easily create PNG that has some scratches on it or other similar effects to make it look more real. You can even create borders with some color, that could look like a wood or metal. Try the different transparent shaders to find what looks best.

\$\endgroup\$
5
\$\begingroup\$

For making a glass material in Unity 5, using Unity shaders and materials is very easy. You need to:

  1. Go to "Project" window and press "Create" new "Material".
  2. Name it Glass and put it into "_Materials" folder.
  3. Assign Glass material to a game object sphere.
  4. Select Glass material and in Inspector, change Render Mode to "Transparent".
  5. Change the colour "Albedo" alpha down to 37 (will add transparency)
  6. colour white
  7. Change the Smoothness value to 0.973 (will add sharp reflection)
  8. Change the Metalic value to 0.1 or 0.273 (will add more detail & shadow)
  9. Source to "Metallic Alpha" (will add light in the reflection)
  10. Set "Specular Highlights" and "Reflection" to enable

Done!

If you wish you can add textures that include alpha for much control. for example not clean glass.

\$\endgroup\$
2
\$\begingroup\$

The official Unity blog shared a link to a .zip package here that has example scripts and a shader that use Unity 5's new Command Buffers as an official solution to implement glass refraction and transparency.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to the StackExchange community! Just leaving links doesn't constitute a good answer. To improve the quality of your answer, you can include the relative information to the question in the link to your answer and leave link as a reference. \$\endgroup\$ – Varaquilex Apr 17 '15 at 22:14
  • \$\begingroup\$ Help Center: How to Answer of StackExchange states that: > Provide context for links Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline (emphasis mine). \$\endgroup\$ – Varaquilex Apr 18 '15 at 15:31
2
\$\begingroup\$

I wrote a shader for glass (and translucency or custom lightmaps too) called Standard Plus. I think it does what you want. 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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.