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 Fadi · Jun 14, 2015 at 10:11 AM · shadersmask

shader MainTex.width ?

hi...

I'm trying to make a Shader ....

all that I need , to split the Main texture to two parts( as mask )

example : sampler2D MainTex;

sampler2D FirstHalf; sampler2D SecondHalf;

MainTex contain the main texture

FirstHalf = from 0 to MainTex.width/2

SecondHalf = from MainTex.width/2 to end of the texture ( 1 )

how can I do that ??

thank you

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 Fadi · Jun 16, 2015 at 12:37 PM 0
Share

alt text

that's what I want to do

the shader i use has two textures, one for the normal image and other for the alpha image , i need to put them at the same image

soizickeytest-400.jpg (47.9 kB)

1 Reply

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

Answer by Jessespike · Jun 16, 2015 at 08:25 PM

Calculate the UV.

     float4 FirstHalf = tex2D(_MainTex, i.uv.xy * float2(0.5, 1) );

http://docs.unity3d.com/Manual/ShaderTut2.html

Comment
Add comment · Show 2 · 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 Fadi · Jun 17, 2015 at 10:27 AM 0
Share

thank you so much , but how can I get the second half ?

it's hard to write a shader , specially there's no autocomplete :(

avatar image Jessespike · Jun 17, 2015 at 05:00 PM 0
Share

second half is the same thing, but has an offset.

         float2 uv1 = i.uv.xy * (_$$anonymous$$ainTex_ST.xy * float2(0.5, 1)) + _$$anonymous$$ainTex_ST.zw;
         float2 uv2 = i.uv.xy * (_$$anonymous$$ainTex_ST.xy * float2(0.5, 1)) + _$$anonymous$$ainTex_ST.zw + float2(0.5, 0);

On a separate note, if I were writing this shader, I would keep the two textures separate and they would both use the same UV coords. I presume the idea of the combined texture was to optimize for performance, but I don't think there is any benefit. There are still two texture samplers being called, only difference now is the combined texture stores half the data that a separate texture can. Which might cause artifacts and reduced visual quality, depending how it's being used.

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI mask does not work on children with different Canvas component and particles 0 Answers

Shader For cut hole and alpha blend 1 Answer

Some blender transitonal questions! 0 Answers

Depth Mask Shader Not Working As Intended 2 Answers

Does [PerRendererData] works for ShaderLab Pass Tags? 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