Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
18
Question by DanjelRicci · Jul 01, 2015 at 03:29 PM · ui3dmaskmaskingscroller

Mask 3D objects inside UI ScrollRect

I have a ScrollRect containing a list of cars with 3D models inside every entry of the list itself. The cars are placed in front of the whole UI. It's working as expected, except obviously for the masking of the 3D models:

alt text

The masking is done with the standard UI Mask component. Is it possible to mask them with a shader, somehow? I'd like to avoid using RenderTextures or dirty pieces of UI sticked above the cars just to cover them strategically. I'd also like to keep the Canvas set to Screen Space - Camera (current setup of the whole UI).
I tried applying UI shaders on the cars, but they just render wrong and never get correctly masked.

Thanks for any help!

scrollrect3dmask.png (54.3 kB)
Comment
Add comment · Show 10
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 Kornikolia · Sep 29, 2015 at 09:45 PM 0
Share

Hi! I'm not sure, that it's the best variant and will it work for you at all, but what if you will render your cars with additional camera to RawImage on UI or something like this, i.e. using two cameras?

avatar image saarwii · Sep 29, 2015 at 09:58 PM 0
Share

From what i have found in the last hour. I think it does not mask due to the shader. I think the shader have to support and/or set the stenceling to comply with something in the UI...but i could be wrong

avatar image a175818202 · Oct 18, 2016 at 08:53 AM 0
Share

Did you solve this ?

avatar image DanjelRicci a175818202 · Oct 18, 2016 at 09:02 AM 1
Share

Yes, in a different way; with an additional camera I render the cars only, then created a script that sets the view rect of that camera to be the same area of the scroll view.

This will work if you are ok with a rectangular mask (which is my case), but won't work if you need to mask things behind rounded corners or complex shapes.

avatar image a175818202 DanjelRicci · Oct 18, 2016 at 09:05 AM 0
Share

nice ! Thank you very much. :-)

Show more comments
avatar image dandepeched · Jan 15, 2018 at 02:54 PM 0
Share

Hi @DanjelRicci . I have tried to do the same approach with additional camera, but had no success with it. Can you please share camera parameters and script that sets the view rect for that camera?

avatar image DanjelRicci dandepeched · Jan 15, 2018 at 03:05 PM 0
Share

I can't open and check the project now, but this is the script that does what I said earlier, just attach it to a new camera. GUI3DCameraFitter.cs

avatar image dandepeched DanjelRicci · Jan 16, 2018 at 08:42 AM 0
Share

Thank you! Works perfect! The only changes from my side is to replace Update function with Start, because this calculations probably needed once.

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Rodrysson · Nov 04, 2018 at 03:19 AM

Hello! I know that the question is too old, but I had the same problem with 3D objects in the UI, so I would like to help. I found some website where there is a solution (https://alastaira.wordpress.com/2014/12/27/using-the-stencil-buffer-in-unity-free/).


However, I think it's a little bit confusing, so I'm going to explain what I did:


  1. First of all, you need 2 different shaders. (Create >> Shader >> Standard Shader). I called them 'Portal' (the space to see the objects) and 'Backobjects'.


  2. Here are the 2 shaders (I just copied the examples in the page that I mentioned before) alt text


  3. Now you need to create 2 different materials which use these shaders (Create >> Material >> Shader: Custom/Portal OR right click on the shader, and create material).


  4. The last step is to apply the materials to the objects and it's done! alt text


I hope this will help everyone who reads this answer. :D


portal-backobjects.png (50.2 kB)
result.png (50.1 kB)
Comment
Add comment · Show 2 · 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 unitylicense21 · May 07, 2019 at 04:59 AM 1
Share

Can you tell where to apply these materials as for given question?? Scroll rect viewport or scroll objects( car as in above Question)?

avatar image Adore20 · Mar 12 at 10:36 AM 0
Share

Hey man how can I add texture to this shader i have properties for texture and color but it just white and doesn't render texture or color

avatar image
1

Answer by maxizrin · Oct 06, 2019 at 07:02 AM

You can assign a mesh to the canvas renderer (manually through script), then the mask component will work on that as expected.

Comment
Add comment · 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
1

Answer by stevencr4z · Sep 16, 2020 at 11:27 PM

Sebastian Lague has a super-simple tutorial on creating a system like Rodrysson referred to. Here's the link: https://www.youtube.com/watch?v=xkcCWqifT9M&t=283s

Comment
Add comment · 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
1

Answer by kaksaveksaka · Dec 08, 2021 at 10:27 PM

Yo, I found a solution by rendering the objects into a image via secondary camera and making the camera and image child of ui and making the secondary camera and all the 3D objects away from primary camera. It worked flawlessly for me.

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 TreseBrothers · Dec 08, 2021 at 10:30 PM 0
Share

Agreed here -- you can use a second camera to write to a render texture and then use an Image to display that texture. Then you can mask the image regularly.

avatar image Adore20 · Mar 10 at 11:37 PM 0
Share

Can specify the steps a bit more?

avatar image kaksaveksaka Adore20 · Mar 11 at 11:45 AM 0
Share

this might help https://youtu.be/28JTTXqMvOU

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

34 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

Related Questions

UI mask with a 3D object 1 Answer

'Invert' UI mask 3 Answers

How to see UI image (static) only trough specific UI element of the Scroll Rect? (Scroll View) 0 Answers

Ring with changeable diameters 1 Answer

How would you mask a UI canvas like you would mask a sprite? 1 Answer


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