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
1
Question by Vicas · Oct 23, 2014 at 11:48 AM · shaderblendinghighlight

Shader: Add one image's alpha to the other while keeping it unlit

I'm trying to get the top texture to blend onto the gold bar and make it shine, but I cannot figure out the right combination of blendmode and SetTexture.

alt text

I have tried to read up on SubShader but I cannot get it to work. The code:

 Shader "Unlit/AlphaWithHighlight"
 {
     Properties
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _DecalTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     }
 
     SubShader
     {
         Tags 
         {
             "Queue"="Transparent"
              "IgnoreProjector"="True"
               "RenderType"="Transparent"
           }
         LOD 200
        
         //ZWrite On
         Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
 
         Pass
         {
             SetTexture[_MainTex]
             {
                 combine texture
             }
 
             SetTexture[_DecalTex]
             {
                 combine previous * texture alpha
             }
 
             // Add color in the end
         }
     }
 
     Fallback "Diffuse"
 }


Comment
Add comment · Show 4
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 screenname_taken · Oct 23, 2014 at 12:16 PM 0
Share

It looks as if your shine texture isn't set as transparent. It should look ok if the black is set as transparent and the shine brighten up a bit and just alpha blended on top.

avatar image Vicas · Oct 23, 2014 at 12:24 PM 0
Share

Do you mean that I have to edit the shine in a photo editing tool or how do I "set it as transparent"? :-)

avatar image screenname_taken · Oct 23, 2014 at 04:55 PM 0
Share

What i mean is, open that shine texture in Photoshop or any other graphics editing software you like, set the black as transparent, and then in Unity's import panel for that texture, tick the box about reading the file's alpha channel.

avatar image Vicas · Oct 25, 2014 at 12:28 PM 0
Share

Not helping, are you sure I'm doing it right?

alt text

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by _Yash_ · Oct 25, 2014 at 01:46 PM

This Fragment Shader should work.

 Shader "Custom/Shine" {
     Properties {
         
         _Color("Color",Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Detail("Detail(RGB)",2D) = "white" {}
         _Speed("speed", Float) = 1
       
     
     }
     SubShader {
         Tags { "Queue"="Transparent" "IgnoreProjector"="True"  }
         Blend SrcAlpha OneMinusSrcAlpha
         
         //Cull Off 
         //ZWrite Off
         
         Pass
         {
             
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma fragmentoption ARB_precision_hint_fastest        
             
             #include "UnityCG.cginc"



              sampler2D _MainTex;
              
              Float _Speed;
             sampler2D _Detail;
              fixed4 _Color;
                 struct v2f
                 {

                     float4 pos : SV_POSITION;

                      float2 uv: TEXCOORD0;
                     
                 };
             
                 v2f vert(appdata_full v)
                 {
                     v2f o;
                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                     float2 uv = v.texcoord.xy;
                      
                      o.uv = uv;
                
                     return o;

                 }
             
             
             fixed4 frag(v2f i) : COLOR {
             
                 float2 uv = i.uv;
                     // scrolls shine texture in x direction
                 uv.x += _Time.x * _Speed;
                     // scrolls shine texture in y direction
                     //uv.y += _Time.x * _Speed;
                 fixed4 t1 =  (tex2D(_MainTex,i.uv)) * _Color;
                     t1 = (t1 +tex2D(_Detail,uv))*t1.a;
                 return t1;
                 
                 
             }

             ENDCG
         }
     } 
     FallBack "Unlit/Transparent"
 }
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 Vicas · Oct 25, 2014 at 03:30 PM 0
Share

Well I don't know, but my point is that it seems perfectly possible to make it without using a CGProgram, so that is really my question. I already have a working fragment shader, but I wanted to port it.

avatar image _Yash_ · Oct 25, 2014 at 03:52 PM 0
Share

Since I don't know more about surface shader. this is what i did in fragment shader.

ColorOfGoldBar + ColorOfShintDetailImage

Animate UV of that black image with time.

As far as i know Surface shader is converted into vertex and fragment shaders, so writing vertex and fragment shder directly is more efficient.

Refer:http://docs.unity3d.com/$$anonymous$$anual/ShadersOverview.html

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

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

Related Questions

Blending parts of texture on 3d object with skinned mesh 0 Answers

Blending normal texture and texture made with shader 0 Answers

How can I make rim lighting appear in front of everything? 1 Answer

shader cg blending two textures 1 Answer

Additional blending when using properties rather than hard-coded values for colors 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