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 gnp89 · May 22, 2014 at 09:05 PM · shadersurfaceprocedural texturing

Using TEXCOORD1 in surface shader

I made a procedurally generated mesh and set values for uv and uv1 properties. I wrote a surface shader that uses both sets of uvs. The shader has two textures, and the mesh has a set of uvs for each one. I should be able to switch between one and another by changing a weight between them.

 Shader "MyShader" {
 Properties {
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _ShineTex ("Shine (RGB)", 2D) = "white" {}
     _ShineOpacity ("Shine opacity", Range (0,1)) = 0
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 sampler2D _ShineTex;
 float _ShineOpacity;
 
 struct Input {
     float2 uv_MainTex    : TEXCOORD0;
     float2 uv_ShineTex    : TEXCOORD1;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * (1-_ShineOpacity) + tex2D(_ShineTex, IN.uv_ShineTex) * _ShineOpacity;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 ENDCG
 }
 
 Fallback "VertexLit"
 }

This is not working, and by the render I can tell that uv_MainTex and uv_ShineTex are both using TEXCOORD0. Any ideas about what's happening?

Comment
Add comment · Show 2
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 rutter · May 22, 2014 at 09:17 PM 0
Share

Just a stab in the dark, I'm afraid, but does this note about variable names do you any good? A similar issue is mentioned on this manual page, though I didn't quite realize its significance at first.

avatar image gnp89 · May 22, 2014 at 09:31 PM 0
Share

I have already tried that, but it didn't work, maybe surfaces have a different behaviour

2 Replies

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

Answer by gnp89 · May 23, 2014 at 04:16 PM

Solved. In the documentation https://docs.unity3d.com/Documentation/Components/SL-SurfaceShaders.html it says "Texture coordinates must be named "uv" followed by texture name (or start it with "uv2" to use second texture coordinate set)."

I didn't know about this naming convention. I think this should be written in a bigger bold red font :P I just changed "uv_ShineTex" to "uv2_ShineTex" and it worked.

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
2

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

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

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

22 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

Related Questions

Unity Terrain - shader for custom post-splat? 0 Answers

CG diffuse shader 1 Answer

how to offset and stretch texture atlas in .shader? 0 Answers

Problem with custom shaders (surface function error) 0 Answers

Pass "external" uv's to shader 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