• 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
0
Question by JonPQ · May 01, 2019 at 04:30 PM · shadermaterialmaskscrollview

Why can't I alter a Texture offset on a material, if its used in a Mask or Scroll rect?

using unity 5.6.3p3 We have several prefab inserts that are placed into a scrolling layout. (imagine a leaderboard) I have a shader (that works with unity masks) to scroll a layer on one of those items to make a sheen/s$$anonymous$$ning effect. It scrolls the texture's uv offset on a material. The material is on a "Image" its the background for the Ui object. T$$anonymous$$s works great everywhere in the game except if you put it inside a $$anonymous$$erarchy with a mask (scroll layout also needs a mask ) I even tried passing a custom scroll value to the shader... but unity somehow also resets t$$anonymous$$s.

If my object is outside the mask it works fine. If its inside the mask, its as if my uv's are all locked to 0,0,width,height.

If I hard-code a u,v offset in the shader.. it renders with those offsets ok. So unity is blocking those values being sent to the shader somwehow. How does it do t$$anonymous$$s ? and why ? Or is there some extra code I need to add to support masks with texture offsets ? Is there any way to get around t$$anonymous$$s issue ?

Thanks in advance for any insight/help into t$$anonymous$$s issue.

Comment
Add comment · Show 1
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 Deftoy · Dec 28, 2019 at 12:39 PM 0
Share

Did you find a solution? I need to know aswell...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by xibanya · Dec 30, 2019 at 02:15 AM

Try using a RawImage object, when scrolling UVs in a MaskableGrap$$anonymous$$c (the type used in the UI system) RawImage handles t$$anonymous$$s much more gracefully

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
0

Answer by Wappenull · Aug 13, 2020 at 11:07 AM

If it is under Mask, its material will be modified on the way in UI render pipeline to setup for mask rendering.

Thus

 Image m_Image; // Target image that we are modifying its material
 
 // Accessing to t$$anonymous$$s material has no effect now if it is under Mask
 m_Image.material
 
 // Instead access to generated "output" material
 Material m = m_Image.materialForRendering;
 Vector2 offset = m.mainTextureOffset;
 offset.x += 0.1f;
 m.mainTextureOffset = offset;



(Advanced usage) For a quick and dirty check, you can also check if that image component is under such magical material pipeline. Compare its original material with materialForRendering and pick correct material to modify.

 /* Script head ////////////////////*/
 Image m_Image;
 Material m_Instanced;
 
 /* In update function ////////////////////*/
 
 Material modifying;
 if( m_Image.materialForRendering != m_Image.material )
 {
     // It is under mask or somet$$anonymous$$ng that modify material instance
     modifying = m_Image.materialForRendering;
 }
 else
 {
     // Access to original material instead
     // But if we use m_Image.material directly, t$$anonymous$$s will modify to original "Asset" version of material
     // W$$anonymous$$ch is bad if you share it with several images, and it will trigger asset dirty every play.
     // To really make a copy of it. new Material first
     if( m_Instanced == null )
     {
         m_Instanced = new Material( m_Image.material );
         m_Instanced.name = m_Instanced.name + "cloned"; // Alter it name a bit so we know
         m_Image.material = m_Instanced; // Change Image to use t$$anonymous$$s new copy
     }
     modifying = m_Instanced; // We will modify the copy instead of real asset one
 }

 // Proceed to modify as usual
 Vector2 offset = modifying.mainTextureOffset;
 offset.x += 0.1f;
 modifying .mainTextureOffset = offset;

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

180 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 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

UI/Default stencil buffer for only parent? 0 Answers

Custom UI material with Mask ? 2 Answers

UI mask with shader 5 Answers

Transparent shader mask in URP 0 Answers

How to mask on a shader , limit a shader to an area in a ScrollView? 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