Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Autonoma · Apr 22, 2016 at 05:26 AM · shadershaderstexturesshader programmingshader writing

Possible for a shader to have two decal slots?

Is it possible to have a shader like shown below? A shader that has two slots for transparent textures. I want one texture to be lower than the other - like the decals are applied in layers. I've tried probably 10 different decal shaders and none of them can do what I'm asking for here. Some accept multiple textures but then will not allow both textures to have transparency. Also I need offset/tiling access to both layers (independently - my meshes have two UVs if that will help)

Anyone have any ideas on how I can accomplish this? The technique I'm using below is functional but isn't as optimized as I believe a dedicated shader would be.

alt text

decals.png (243.2 kB)
Comment
Add comment · Show 3
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 Namey5 · Apr 22, 2016 at 10:04 AM 0
Share

You could have a custom shader with, say, 3 textures. One as the main albedo and 2 as the decals. In the application of the albedo texture, add the 2 other textures to the main albedo. If they have black in the transparent (should work with transparent though) they should blend.

avatar image Autonoma Namey5 · Apr 22, 2016 at 11:56 AM 0
Share

Here's what I have so far. This is taking two textures, both which can be transparent, but they are controlled by the slider. What I need is to have the two textures to just have their alpha transparent, and to be able to tell one to stay on top of the other. Does that require adding an albedo texture?

 Shader "Custom/z_BlendTex_Test" 
 { 
     Properties{
         _Blend("Blend", Range(0,1)) = 0.5
         _$$anonymous$$ainTex("Tex1", 2D) = ""
         _$$anonymous$$ainTex2("Tex2", 2D) = ""
     }
 
     SubShader
     {
         Lighting On
         Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
         Pass{
             Blend SrcAlpha One$$anonymous$$inusSrcAlpha
             SetTexture[_$$anonymous$$ainTex]{
                 Combine texture
             }
             SetTexture[_$$anonymous$$ainTex2]{
                 ConstantColor(0,0,0,[_Blend])
                 Combine texture Lerp(constant) previous
             }
         }
     }
     Fallback "Diffuse"
 }
avatar image Namey5 Autonoma · Apr 22, 2016 at 12:01 PM 0
Share

Didn't realise you're working in shaderlab, can't really help you there, sorry. I also thought you were doing everything (including base texture work) in one shader.

2 Replies

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

Answer by Autonoma · Apr 22, 2016 at 01:58 PM

Figured it out - this requires two passes, but I'm fine with that. I was mainly trying to avoid having to have multiple meshes.

 Shader "Custom/Priority Transparent" {
     Properties{
         _Color("Main Color", Color) = (1,1,1,1)
         _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
         _SecondTex("Base (RGB) Trans (A)", 2D) = "white" {}
     }
 
     SubShader{
         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
         LOD 200
 
         CGPROGRAM
         #pragma surface surf Lambert alpha:fade
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf(Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
 
         CGPROGRAM
         #pragma surface surf Lambert alpha:fade
 
         sampler2D _SecondTex;
         fixed4 _Color;
 
         struct Input {
             float2 uv_SecondTex;
         };
 
         void surf(Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_SecondTex, IN.uv_SecondTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     }
 
     Fallback "Legacy Shaders/Transparent/VertexLit"
 }
Comment
Add comment · 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
0

Answer by neufoctobre · Oct 17, 2017 at 02:15 PM

Hi,

This Shader is perfect for what I need, is this shader is good for mobile performance ?!

Thanks !

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding a clip() to the default shader? 0 Answers

Shader - What is float3.xy? 1 Answer

How to add Emission to my custom shader? 2 Answers

Drawing silhouette shader 0 Answers

Shader: Modify XY Position of Texture 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