• 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 kobunketsu · Dec 03, 2012 at 08:35 AM · uv

different second uv usage cause _mainTex_ST redefinition.Need Help

hi, I have a shader like this. struct Input { float2 uv_MainTex; float2 uv2_MainTex; float4 color : COLOR; }; void surf (Input IN, inout SurfaceOutput o) { float2 uv = IN.uv_MainTex * IN.uv2_MainTex; o.Albedo = tex2D(_MainTex, uv).xyz; o.Alpha = 1; } the compile says: GLSL vertex shader:409:ERROR:'_MainTex_ST':redefinition at line xxx

if I want my second uv to be a scale for my first uv, or other usage(not for sampling), how can i solve the redefinition error?

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 whydoidoit · Dec 03, 2012 at 08:53 AM 0
Share

Sounds like the output of the surface shader is screwy CG - you might want to rewrite that as a fragment shader and handle it yourself or you could try doing:

    IN.uv_$$anonymous$$ainTex = IN.uv_$$anonymous$$ainTex * IN.uv2_$$anonymous$$ainTex;


There's info on writing both types of shaders on Unity Gems

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by pavel_krupala · May 17, 2015 at 07:22 AM

SOLVED!

Lol.. it is written in manual however there is another problem corresponding with this.... when u have 1 texture and more UV maps (http://forum.unity3d.com/threads/problems-with-shader-utilizing-uv2.151702/, http://answers.unity3d.com/questions/358176/different-second-uv-usage-cause-maintex-st-redefin.html)

causes error:

struct Input {
  float2 uv_MainTex : TEXCOORD0;
  float2 uv2_MainTex;
} 

solution:

struct Input {
  float2 uv_MainTex : TEXCOORD0;
  float2 uv2_MainTex2;
} 

AND YES you have to create new parameter for that!!! Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _MainTex2 ("Albedo (RGB)", 2D) = "white" {} _MainTex3 ("Albedo (RGB)", 2D) = "white" {}

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 Clement_Shimizu · Jul 13, 2013 at 07:28 PM

I think your bug is because the surface shader, when it gets compiled, generates _MainTex_ST to transform the UVs. If you convert your shader to a vertex/pixel shader the problem will go away because you are expected to specify "_MainTex_ST" and then use the TRANSFORM_TEX macro...

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 Paulius-Liekis · Dec 03, 2012 at 03:30 PM

I think it's a bug on Unity side. As a hack you could add another texture and define that you use uv2 with it. As long as you do not modify Scale&Offset of these texture (or keep them the same) - it should be fine.

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 kobunketsu · Dec 06, 2012 at 03:24 PM

Thanks a lot. I also think it is a bug. In fact, in order to simply the problem, I just simply the shader code, my real shader is:

      CGPROGRAM
      #pragma surface surf Lambert 
      sampler2D _MainTex;
      sampler2D LayerMap0Sampler;
      sampler2D LayerMap1Sampler;  
      half4 g_uvAnimationFactor;
      struct Input {
       float2 uv_MainTex;
       float2 uv2_MainTex;
       float4 color : COLOR;
      };

      void surf (Input IN, inout SurfaceOutput o) {

           half3 blendMask = float3(IN.color.w, IN.uv2_MainTex.x, 1- IN.uv2_MainTex.y);      
           o.Albedo = tex2D(_MainTex, float2(IN.uv_MainTex * g_uvAnimationFactor.x)).xyz;

           half4 cLayerMap0 = tex2D(LayerMap0Sampler, float2(IN.uv_MainTex * g_uvAnimationFactor.y));
           o.Albedo = lerp(o.Albedo.xyz, cLayerMap0.xyz, blendMask.x);

           half4 cLayerMap1 = tex2D(LayerMap1Sampler, float2(IN.uv_MainTex * g_uvAnimationFactor.z));
           o.Albedo = lerp(o.Albedo.xyz, cLayerMap1.xyz, blendMask.y);

           o.Albedo *= IN.color.xyz;
           o.Alpha = 1;             
      }

      ENDCG

I use mesh's second uv and vertex alpha to blend other texture for my terrain shader.(vertex color is used to change terrain color);

I have tried to sample another tex by uv2, but it doesn't work...

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 whydoidoit · Dec 06, 2012 at 03:52 PM 0
Share

Have you tried actually updating the value of IN.uv_$$anonymous$$ainTex? I wondered if that might get around the output bug, although the _ST is probably already set up and I'm not sure what the effect would be of updating a variable in any case.

avatar image kobunketsu · Dec 07, 2012 at 03:11 AM 0
Share

I have tried, but didn't work. If i rename the IN.uv2_$$anonymous$$ainTex to IN.uv2_xxTex, the bug is fixed, but the uv2 texcoord Info is lost too. I think I should write a vert/frag shader for it to get around the bug. But I really want to use surface shader...

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

13 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

Related Questions

Assigning UV Map to model at runtime 0 Answers

Can I feed ShaderGraph a UV map? 0 Answers

UV issue on pixel pallet from Blender 0 Answers

Mirror UVs for normal maps 3 Answers

Translate World transform data to UV offset 2 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