• 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 hgKevin · Aug 20, 2015 at 12:19 PM · materialunity5normal map

SetTextureOffset & Standard Shader

Hi, i'm trying to set the offset of the secondary normal map (Unity 5 Standard Shader) using

 rend.material.SetTextureOffset("_DetailNormalMap", new Vector2(offset, offset));

but the offset doesn't change. Perhaps "_DetailNormalMap" is not the correct property name? I found it using the inspector debug view. Also, i can set the main normal using "_MainTex" / "_BumpMap" just fine.

This is how the material is set up in the editor:

Any idea what's wrong?

shader.jpg (45.1 kB)
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

2 Replies

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

Answer by Youri1er · Aug 20, 2015 at 01:05 PM

You can't. rend.material.SetTextureOffset() doesn't work because it's for the main texture i think.

Try to download the standard shader , change code to put a property available for designer in shader.

_OffsetX ("OffsetX", Float) = 0

_OffsetY ("OffsetY", Float) = 0

You put in code:

uv.x += _OffsetX;

uv.y += _OffsetY;

If you declare your vairable _OffsetX and _OffsetY in Properties , you can set via code C#.

Comment
Add comment · Show 1 · 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 hgKevin · Sep 08, 2015 at 02:39 PM 0
Share

That worked. Thanks a lot.

avatar image
1

Answer by Elecman · Sep 25, 2016 at 05:31 AM

Here is how to do the same thing, but a bit more detailed and with support for tiling in addition to offset.

-Download build in shaders.

-Copy “Standard.shader”, rename to “StandardShift.shader”, and put into project in the same folder called Shaders.

-Copy the following files and put into project in a folder called Shaders. Note that only the file “UnityStandardInput.cginc” from this list will be modified, but all other files are needed, otherwise it won’t work.

 UnityStandardInput.cginc
 UnityStandardCore.cginc
 UnityStandardCoreForward.cginc
 UnityStandardCoreForwardSimple.cginc
 UnityStandardMeta.cginc

-Open StandardShift.shader.

-Modify the first line to:

 Shader "StandardShift"

Place this code just below the line "_DetailNormalMap("Normal Map",..."

 _EmissionTileOffset("EmissionTileOffset", Vector) = (1,1,0,0)

-Open UnityStandardInput.cginc.

Place this code just below the line "sampler2D _EmissionMap;"

 half4        _EmissionTileOffset;

-Search for this function:

"half3 Emission(float2 uv)"

-Place this code just above the line "return tex2D(..."

 uv.x *= _EmissionTileOffset.x;
 uv.y *= _EmissionTileOffset.y;
 uv.x += _EmissionTileOffset.z;
 uv.y += _EmissionTileOffset.w;

-Create a material and set the shader to StandardShift.

-Add the material to an object.

-Create a script and add the script to the object.

-Add this code to the script:

 rend = GetComponent<Renderer>();
 rend.material.SetVector("_EmissionTileOffset", new Vector4(0.5f, 0.5f, 0f, 0f));

The vector format is:

Tile X, Tile Y, Offset X, Offset Y

Note that you can only set the shader properties in code, not in the Editor.

If it doesn’t work, make sure all required files are copied to the Shader folder. Then go to Unity->Assets->Reimport All. After that, select the StandardShift shader -> Inspector -> compile and show code.

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 ivank · Sep 28, 2016 at 11:19 AM 0
Share

@Elecman Thanks for the detailed answer!

Is this possible for the primary textures as well? Thats the questionwhich bothers me quite a long time...

$$anonymous$$y that per-texture UV tile+offset (quite logical feature, common in any 3D modeling sw used for object creating for Unity) is not present in the Standard shader directly.

Exactly the same "pity" applies to lack of ability to set per-texture UV channel...

avatar image Youri1er · Sep 28, 2016 at 12:24 PM 0
Share

Yes it's possible for the primary texture, but you need to modify the shader.

Yes, unity is always late with shader features. You can do easily yours shader with shader forge if you don't know CG.

You can apply what @Elecman says, matter how many textures you have.

avatar image Elecman · Mar 03, 2017 at 01:16 PM 0
Share

Unfortunately this doesn't work with Unity 5.5 anymore. No error is thrown, it's just that SetVector() has no effect. I don't know why. Any ideas?

Edit: I updated the post with a fix so it now works for Unity 5.5+. Also tested in Unity 2017.3

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

[Unity5]how to change alpha by using shader. 1 Answer

Normal map not showing correctly on 2d sprite 0 Answers

Unity 5 - assign Sprite to Material 4 Answers

Unity 5 materials and reflections 3 Answers

Marmoset + Unity 4 vs Unity 5 Lighting 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