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
0
Question by Kajos · Apr 24, 2013 at 04:52 PM · shadertextureskinnedmeshrenderer

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!

alt text

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:

alt text

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 9 · 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 Kajos · Apr 24, 2013 at 05:32 PM 0
Share

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.

avatar image Kajos · Apr 24, 2013 at 06:33 PM 0
Share

I added an example. The white square with blacks is the cliptex.

avatar image whydoidoit · Apr 24, 2013 at 06:53 PM 1
Share

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...

avatar image whydoidoit · Apr 24, 2013 at 07:39 PM 1
Share

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?

avatar image whydoidoit · Apr 24, 2013 at 08:03 PM 1
Share

G'd no. Just another game programmer :)

Show more comments

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

12 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

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


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