Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Draco18s · Aug 09, 2014 at 08:24 PM · materialpropertyblock

MaterialPropertyBlock Main Texture Offset?

I've gotten into the habit of using MaterialPropertyBlocks to tweak shader properties at runtime, as to avoid creating new material instances for simple things.

The question I have, though, is how can I do this to tweak the material's main texture offset, so I can use a spritesheet of icons and not end up with a bunch of instanced materials (as that would cause the icons not to batch).

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
3

Answer by il88 · May 17, 2016 at 12:57 PM

I've found that you can modify texture transforms (offset and tiling) by setting _STs (uniform float4 _MainTexture_ST for example) like any other Vector4:

propertyBlock.SetVector("_MainTex_ST", new Vector4(0.5f, 0.5f, 0.25f, 0.25f));

Comment
Add comment · Show 7 · 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 Dargon_huihui · Apr 22, 2019 at 05:40 AM 0
Share

so good!!!

avatar image billw2011 · Sep 28, 2020 at 10:56 AM 1
Share

The order of the values to pass to SetVector is scale.x, scale.y, offset.x, offset.y, e.g. propertyBlock.SetVector("_$$anonymous$$ainTex_ST", new Vector4(scale.x, scale.y, offset.x, offset.y));

avatar image Draco18s billw2011 · Sep 28, 2020 at 01:16 PM 0
Share

Not for a $$anonymous$$aterialPropertyBlock it isn't. $$anonymous$$aterialPropertyBlocks use strings to reference a shader value. https://docs.unity3d.com/ScriptReference/$$anonymous$$aterialPropertyBlock.html

avatar image billw2011 Draco18s · Sep 28, 2020 at 01:33 PM 0
Share

I mean that is the order of the values for the vector.

Show more comments
avatar image Wothanar · Nov 25, 2020 at 04:46 PM 0
Share

im doing this and is not working to me , I'm using standard shader , whats wrong with what I'm doing I cant understand but I don't see the offset to be changed so far :S

avatar image chadfranklin47 · Apr 14, 2021 at 02:16 AM 1
Share

If you're using URP, use "_BaseMap_ST" rather than "_MainTex_ST".

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

26 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

Related Questions

A node in a childnode? 1 Answer

Camera target 1 Answer

How to make an ingame weapon/ammo shop 0 Answers

Change the value of a Key in animation (via code) 0 Answers

Collision Detection in Capsule Collider 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