• 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 Rimply · Apr 19, 2017 at 10:10 PM · shadertextureuv

Why are the UV's in my texture array shader always zero?

I'm currently working on a surface shader that uses a texture array. For some reason, the uv's being passed to the surf function appear to always be (0,0,0), even though I've confirmed that the uv's on the mesh (a simple quad) are [ (0,0,8) , (1,1,8) , (1,0,8) , (0,1,8) ].

I'm certain the texture array and mesh themselves are fine, because everyt$$anonymous$$ng worked correctly when I used a vert/frag shader, but I want to switch it to a surface shader so I could easily have lighting.

Here is my shader code:

 Shader "Rimply/TextureArray"
 {
     Properties
     {
         _MyArr ("Tex", 2DArray) = "" {}
     }
 
     SubShader
     {
         Tags { "RenderType"="Opaque" }
 
         CGPROGRAM
         #pragma surface surf Lambert
         #pragma target 3.5
 
         #ifndef SHADER_TARGET_SURFACE_ANALYSIS
         UNITY_DECLARE_TEX2DARRAY(_MyArr);
         #endif
 
         struct Input
         {
             float3 uv_MyArr;
         };
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             #ifndef SHADER_TARGET_SURFACE_ANALYSIS
             half4 c = UNITY_SAMPLE_TEX2DARRAY(_MyArr, IN.uv_MyArr);
             o.Albedo = c.rgb;
             #endif
         }
         ENDCG  
     }
     Fallback "Diffuse"
 }
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
0

Answer by Bunny83 · Apr 19, 2017 at 10:37 PM

Well, i guess that the surface shader compiler simply has trouble / doesn't support mapping a texture coordinate channel to texture arrays. The example used an explicit semantic (TEXCOORD0). However i'm not sure if you can specify that in a surface shader. Though as far as i know you can actually mix a surface function with custom vertex and fragment shaders. However i've never done that.

The macro UNITY_DECLARE_TEX2DARRAY looks like t$$anonymous$$s and does two t$$anonymous$$ngs:

 #define UNITY_DECLARE_TEX2DARRAY(tex) Texture2D_Array tex; SamplerState sampler##tex

First it declares a Texture2D_Array with the provided name. Second it declares a SamplerState with the name "sampler" + yourProvidedName

So in your case it would be:

 Texture2D_Array _MyArr;
 SamplerState sampler_MyArr;

It could be that the uv coordinate is bound to the sampler name, but that's just a guess. You could try:

 uv_sampler_MyArr

though i doubt that it works ^^.

Comment
Add comment · Show 1 · 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 Rimply · Apr 20, 2017 at 04:27 AM 0
Share

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Alpha Texture Deserves a Separate File? 1 Answer

Visible seams on borders when tiling texture 1 Answer

Shader and Texture Scrolling depending on Direction 1 Answer

uv not being passed through from vertex to surface shader 1 Answer


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