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 shionyr · Nov 05, 2012 at 01:13 PM · materialstexturesshaderlab

ShaderLab: can I specify a portion of a texture?

Greetings,

I'm writing a custom shader. Currently, my shader accepts several materials, layered on top of one another to create an interesting 2D play on light and shadow.

 _MainTex ("Main Diffuse", 2D) = "white" {}
 _SubTex ("Secondary Diffuse", 2D) = "white" {} 
 _ShadowTex ("Shadow Texture", 2D) = "white" {}

However, this requires 3 separate images.

What I'd like to do, is place all three textures on one bigger texture, with one sub-texture in each quadrant. The shader would then use three quadrants of the bigger texture, instead of three separate, smaller textures.

This would theoretically be accomplished with three texture fields (extreme pseudo code, dunno if this is possible):

 // Quadrant samples
 _MainTex ("Main Diffuse", 2D) = "white" { 0,0,0.5,0.5 }
 _SubTex ("Secondary Diffuse", 2D) = "white" { 0,.5,.5,1 } 
 _ShadowTex ("Shadow Texture", 2D) = "white" { .5,0,1,.5 }

Or, it could be accomplished through sub-shader code:

 SetTexture [_MainTex]{
     quadrant (0,0,.5,.5)  // Doesn't exist
     combine constant lerp (constant) texture
 }

This may require a fragment shader, which I'm trying to avoid for compatability reasons.

I'm continuing to research it myself, but any advice would be appreciated. Thanks!

Comment
Add comment · Show 1
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 Paulius-Liekis · Nov 06, 2012 at 01:54 PM 0
Share

You should not put comments as answers...and you should mark the answer that solved your problem as correct ;) Welcome to Unity Answers!

1 Reply

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

Answer by Paulius-Liekis · Nov 05, 2012 at 02:39 PM

You can do it as long as your UVs are in 0-1 range.

If you want to do it in fixed pipeline shaders you ahve to use texture UV matrix (http://docs.unity3d.com/Documentation/Components/SL-SetTexture.html) to scale and offset texture UVs.

Comment
Add comment · Show 3 · 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 shionyr · Nov 06, 2012 at 01:32 PM -1
Share

This was the exact article I needed. I cobbled together a decent matrix generator, and it's now working great. Thanks!

avatar image Sonaten · Nov 06, 2012 at 01:58 PM 0
Share

Bad conduct to mark your own answer as the solution. Honor those who have helped you.

avatar image shionyr · Nov 06, 2012 at 04:39 PM 0
Share

I'm sorry, it wasn't my intention to do that. It actually was Paulius' answer that fixed my situation, but I marked my own as the answer by accident. Thank you for pointing that out, I'll try to be more careful in the future.

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

How to create a shader that makes the texture look far away? 0 Answers

Help with GUI, Textures and Materials (Health Circle) 1 Answer

How to quickly change the texture on a material? 1 Answer

How do I change the default material size in ProBuilder? 0 Answers

Applying materials/textures on imported fbx, dae, etc 2 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