Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by KuboS0S · Nov 29, 2017 at 08:22 PM · shadermaterialrenderertransparencytransparent

Rendering an entire object as transparent

I have a problem when I want a certain object to render as transparent. I previously solved the issue by looping through all renderers and their materials, making new materials for each material (but with a trannsparent rendering mode and with a bit less opacity). Though it doesn't feel right to create an entirely new material for each material in the object, so I thought that I'd make a narrower selection of materials (one for each colour) and the same selection of transparent materials. Making all materials transparent makes the object look a little weird in certain cases, because if two transparent materials are rendered behind one another, they overlap and both surfaces end up being visible. Is it possible to bypass this problem somehow? I thought of doing something like rendering the object alone using its own camera and then overlaying the picture on top of the screen, but more transparent, (which would make the object render in front of everything else though). I also thought, if there is a way to do this using shaders (though I cant use them yet).

Anyway, should I stick to replacing materials, or is there a way to render a GameObject and its children as transparent using shaders?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by mafima · Nov 29, 2017 at 08:50 PM

Well, a Material is using 1 shader. this shader can have multiple textures and parameters, but ultimately 1 material uses 1 shader. there are shaders, that just make your object transparent, but you need to change your shader for that. so you COULD create 2 shaders and just change the shader for all your materials into the other transparent shader in your script. that way you dont create materials, but just replace shader.

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public Shader shader1;
     public Shader shader2;
     public Renderer rend;
     void Start() {
         rend = GetComponent<Renderer>();
         shader1 = Shader.Find("Diffuse");
         shader2 = Shader.Find("Transparent/Diffuse");
     }
     void Update() {
         if (Input.GetButtonDown("Jump"))
             if (rend.material.shader == shader1)
                 rend.material.shader = shader2;
             else
                 rend.material.shader = shader1;
         
     }
 }

https://docs.unity3d.com/ScriptReference/Material-shader.html

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KuboS0S · Nov 29, 2017 at 09:05 PM 0
Share

So it is possible to just replace the shader for each material and they will all render as transparent? If yes, how do I make such shader? (I never worked with them.)

avatar image mafima KuboS0S · Nov 30, 2017 at 01:58 PM 1
Share

if you have a correct shader, yes. but most of the shaders render something. it comes down to the question: what do you want to do? more performance? why dont you just change the alpha of the transparent material?

alt text

avatar image KuboS0S mafima · Dec 09, 2017 at 11:08 AM 0
Share

Alright, if I don't notice performance drops, I'll go with just creating new materials out of the old ones and transparifying them. One thing I've noticed though is that I can't directly replace the materials in the Renderer.materials array, but I had to replace the entire array, that's just a heads-up for anyone who has the same problem.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a shader in Unity that prevents transparent parts from overlapping? 1 Answer

Changing two different objects renderer colour 1 Answer

How can I make a transparent ground, that hides other objects beneath it? 1 Answer

Adding Transparency to a Diffuse / Spec / Normal Shader 0 Answers

How to set pre-render properties to UGUI Image? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges