- Home /
Skinned Mesh Renderer: How are the texture coordinates
I am trying to apply a shader to a Skinned Mesh Renderer. However I have no idea how Unity calculates the Texture coordinates for Skinned Mesh Renderers. I have the feeling some sort of atlassing is used. Can someone give me an example or an explanation on the texture coordinates of a Skinned Mesh Renderer?
Preferably I am looking for a texture coordinate which isn't used twice (so not mirrored), but any help would be great either way!
Shader "Clipping/Texture Clipped" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _ClipTex ("Clip (RGB)", 2D) = "white" {} _InnerTex ("Inner (RGB)", 2D) = "white" {} } SubShader { Pass { Cull Back
CGPROGRAM
#pragma exclude_renderers gles
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
float4 color : COLOR0;
};
uniform sampler2D _InnerTex;
uniform float4 _InnerTex_ST;
uniform sampler2D _ClipTex;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
v2f vert( appdata_base v ) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = v.texcoord;
o.uv[1] = v.texcoord;
o.uv[1].x /= 2.0;
// lighting from single directional light + ambient
float4 color = UNITY_LIGHTMODEL_AMBIENT;
float3 lightDir = mul( glstate.light[0].position.xyz, (float3x3)UNITY_MATRIX_IT_MV );
float ndotl = max( 0, dot( lightDir, v.normal ) );
color.xyz += glstate.light[0].diffuse * ndotl;
o.color = color;
return o;
}
void frag(v2f IN, out float4 finalColor : COLOR) {
float a = tex2D(_ClipTex, IN.uv[1].xy);
if (a < 0.1)
discard;
finalColor = IN.color * tex2D(_MainTex, TRANSFORM_TEX(IN.uv[0].xy, _MainTex));
}
ENDCG
AlphaTest Greater 0.1
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
SetTexture [_ClipTex] { Combine previous, texture }
}
Pass {
Cull Front
CGPROGRAM
#pragma exclude_renderers gles
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
float4 color : COLOR0;
};
uniform sampler2D _InnerTex;
uniform float4 _InnerTex_ST;
uniform sampler2D _ClipTex;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
v2f vert( appdata_base v ) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv[0] = v.texcoord;
o.uv[1] = v.texcoord;
o.uv[1].x /= 2.0;
// lighting from single directional light + ambient
float4 color = UNITY_LIGHTMODEL_AMBIENT;
float3 lightDir = mul( glstate.light[0].position.xyz, (float3x3)UNITY_MATRIX_IT_MV );
float ndotl = max( 0, dot( lightDir, v.normal ) );
color.xyz += glstate.light[0].diffuse * ndotl;
o.color = color;
return o;
}
void frag(v2f IN, out float4 finalColor : COLOR) {
float a = tex2D(_ClipTex, IN.uv[0].xy);
if (a < 0.1)
discard;
finalColor = IN.color * tex2D(_InnerTex, TRANSFORM_TEX(IN.uv[0].xy, _InnerTex));
}
ENDCG
AlphaTest Greater 0.1
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
SetTexture [_ClipTex] { Combine previous, texture }
}
}
Fallback "VertexLit"
}
If I divide uv[[1]].x by 2 I get this however:
Answer by whydoidoit · Apr 24, 2013 at 05:01 PM
There is no difference between texture coordinates in MeshRenderers and SkinnedMeshRenderers and no atlasing is performed automatically by Unity. The uvs of a mesh are associated with vertices and all a SkinnedMeshRenderer does is apply the bone weights to reposition the vertices, the uv coordinates move with them.
Thank you for your reply. I would think so too. However when I use the texture coordinates on another texture which is blitted with the original, the result shows something else. I will attach my shader and a screenshot.
I added an example. The white square with blacks is the cliptex.
I've never seen or tried to write a shader that was only a vertex program - so I'm not sure how that might be affecting it - having the fragment be some fixed function thing...
Well the fragement part is the bit that is using the interpolated uvs - so it actually does matter ;)
You got some kind of tiling going on? UV loops or something on the model?
Your answer

Follow this Question
Related Questions
Transparency and texture atlases, shader calls affecting performance? 2 Answers
Changing Eye Colour (Colour only non-white parts of a texture?) 2 Answers
Change particle tint color via script 1 Answer
Object space normal map warning the texture is not a normal map 1 Answer
My mesh didn’t appear in Unity 0 Answers