- Home /
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?
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.
I have already tried that, but it didn't work, maybe surfaces have a different behaviour
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.
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" {}
Your answer
Follow this Question
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