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 JoelAtMoodkie · Nov 03, 2010 at 07:11 PM · shaderuvoverlay

Modifying my shader to overlay rather than blend.

Hiya all.

I've modified the LayerShader from Unify so that it maps two textures (with alphas) to one mesh using two different UV maps.

Is there any way I could modify it so that instead of combining MainTex with PathTex, it overlays MainTex over PathTex? The source is below:

Shader "DoubleUV2" {

Properties { _Color ("Color", Color) = (1,1,1) _Blend ("Blend", Range (0,1)) = 0.5 _MainTex ("Main Texture", 2D) = "" _PathTex ("Path Texture (RGB)", 2D) = ""

}

Category { Material { Ambient[_Color] Diffuse[_Color] }

 SubShader {
     Pass {
     BindChannels
     {
         Bind "Vertex", vertex         
         Bind "texcoord1", texcoord0
         Bind "texcoord", texcoord1
         Bind "Color", color
         Bind "Normal", normal
     }

         SetTexture[_PathTex]

         SetTexture[_MainTex]
         {
             combine texture * previous, previous + texture
         }

     }

     Pass {
         Lighting On
         Blend DstColor SrcColor
     }
 }

}

}

Regards, Joel.

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 skovacs1 · Nov 03, 2010 at 07:48 PM

You should really check the docs on Texturing in ShaderLab.

In the example there, they define a texture blend shader with

combine texture lerp (texture) previous

There are any number of kinds of functions you can use for combining textures and your use of terminology is unspecific.

//multiply (what you're already doing) combine texture * previous

//add combine texture + previous

//Alpha blend (previous's alpha will be used to blend previous over texture). combine previous lerp(previous) texture

Based on the fact that you have a "blend" property, it would seem you want to control using that property. I did something like that here.

SetTexture[_PathTex]
SetTexture[_MainTex]
{
    ConstantColor (0,0,0, [_Blend])
    combine previous lerp(constant) texture
}

or if you wanted it to be more of an additive combiner, you could do something like:

SetTexture[_PathTex]
SetTexture[_MainTex]
{
    ConstantColor ([_Blend],[_Blend],[_Blend],[_Blend])
    combine previous * constant + texture
}
Comment
Add comment · Show 4 · 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 JoelAtMoodkie · Nov 03, 2010 at 08:18 PM 0
Share

Sorry, the blend property was left-over code from the LayerShader code and isn't relevant to what I want. I'll explain what I mean a bit better. Lets say my two textures are different transparent images with a series of random solid lines going through it. At the moment it draws the PathTex texture, and then draws the $$anonymous$$ainTex texture. If a line in $$anonymous$$ainTex overlaps a line in PathTex, it will combine the colours of the PathTex image and the $$anonymous$$ainTex image. How could I make it so that ins$$anonymous$$d of doing this it draws the $$anonymous$$ainTex lines on top of PathTex lines without combining the colours? Thanks.

avatar image skovacs1 · Nov 03, 2010 at 08:56 PM 0
Share

That would be an alpha blend shader exactly as described above and given in the docs. Replace 'combine texture * previous, previous + texture' with 'combine texture lerp(texture) previous, previous + texture' in your shader and it should do what you describe.

avatar image skovacs1 · Nov 03, 2010 at 08:59 PM 0
Share

That of course assumes that your "solid" areas have an alpha of 1. If they don't then that's something that you should have mentioned in the question and becomes much trickier.

avatar image skovacs1 · Nov 03, 2010 at 09:02 PM 0
Share

You would get better results where they overlap and either of their alphas are not 1 if you didn't overwrite the alpha with previous + texture.

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

No one has followed this question yet.

Related Questions

UI shader; get simple UV 0 Answers

TexGen'ed UVs - how to access in surface shader? 1 Answer

Apply an affine transformation 2 Answers

How to scale and offset UV coordinates from the center of the texture? 1 Answer

Shaders: Overwrite something? 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