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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by inkspot · May 30, 2013 at 10:46 PM · shadertransparentpnginverted

[Solved] Shader: cutout shader over a texture

Hello community,

Currently i'm trying to make a shader that has a main texture + a transparent(cutout) texture/layer on top of it. Imagine this as a 'skin & eyebrow' situation the main texture is the skin. The eyebrow texture is suppose to be the transparent overlaying part of the shader.

The current code only seem to show the material color as it's base, the code as below does need an extra texture my question is, how to swap the material color as the background layer and use a texture instead in order to get a (png eyebrow) over a skin texture. It is a really basic concept but i've just started looking into the whole shader department so if anyone can help me on my way, please do ;) Here is what the shader code currently looks like:

 Shader "custom/headshader" {
 
     Properties
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGBA)", 2D) = "white" {}
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 250
     
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         struct Input
         {
             float2 uv_MainTex;
             float2 uv_DecalTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
             o.Albedo = lerp(_Color, c.rgb, c.a);
             o.Alpha = 1;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }
Comment
Add comment · Show 2
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 fafase · Jun 02, 2013 at 04:10 PM 0
Share

Isn't Decal what you are describing? Note that I am not familiar with shaders but decal is simply having one main texture and a tetxure to apply on top of it.

avatar image inkspot · Jun 05, 2013 at 10:20 AM 0
Share

Hi fafase, yes it was decal which i was looking for but with a alpha channel for the second texture, the code by electricsause in the answers below solved it.

1 Reply

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

Answer by electricsauce · Jun 01, 2013 at 03:44 PM

I think you're trying to display a one texture on top of a background texture but what you're doing is using the cloud alpha to cutout the background.

Try this instead: http://answers.unity3d.com/questions/273680/transparent-cutout-shader.html

Comment
Add comment · Show 6 · 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 inkspot · Jun 01, 2013 at 09:08 PM 0
Share

Thank you for your reply, i tried that thread one before somehow it doesn't work on the specific model (it does on others) It is the same idea what i want to achieve i've noticed that the previous code above didn't seem to work for me anymore the new code above[edited post] is the one i'm currently using which is almost doing what i want except it uses the material color as 'base texture' for the transparant texture.

avatar image electricsauce · Jun 01, 2013 at 09:38 PM 0
Share

Do you have any pics of the effect you're looking for and what you have so far?

avatar image inkspot · Jun 02, 2013 at 02:11 AM 0
Share

Sure here it is; alt text

example.jpg (186.1 kB)
avatar image electricsauce · Jun 02, 2013 at 04:46 AM 0
Share

I don't do surface shaders much, but try this:

 Shader "Custom/z_BlendTex_Test" { Properties
 {
 //we're not using color in this shader
 //_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
 _$$anonymous$$ainTex ("Base (RGBA)", 2D) = "white" {}
 _DecalTex("Decal Texture (RGB)", 2D) = "white" {}
 _BlendAmount("Blend Amount", Range(0.0, 1.0)) = 1.0
 
 }
 SubShader
 {
 //rendertype opaque means we're not using a transparent shader
 Tags { "RenderType"="Opaque" }
 LOD 250
  
 CGPROGRA$$anonymous$$
 #pragma surface surf Lambert
  
 sampler2D _$$anonymous$$ainTex;
 sampler2D _DecalTex;
 fixed _BlendAmount;
 //fixed4 _Color;
  
 struct Input
 {
 float2 uv_$$anonymous$$ainTex;
 float2 uv_DecalTex;
 };
  
 void surf (Input IN, inout SurfaceOutput o)
 {
 fixed4 c = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex);
 fixed4 cd = tex2D(_DecalTex, IN.uv_DecalTex);
 //switch the order of c and cd in the lerp function to change the cutout effect
 o.Albedo = lerp(cd, c.rgb, c.a * _BlendAmount);
 //we don't need to pass the alpha since we're not using transparency
 //o.Alpha = 1;
 }
 ENDCG
 }
 Fallback "Diffuse"
 }
 
avatar image inkspot · Jun 02, 2013 at 03:24 PM 0
Share

Hi thanks a lot for looking into it, and putting up some side notes. it worked exactly how i wanted it after switching the order of c and cd around (line 35). It was kind of weird as without switching the order around it didn't filter out the transparent part of the png file out. - Anyway it works thanks again!!

Show more comments

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

14 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

Related Questions

apply transparent png, material color shine through 3 Answers

Models becoming transparent 1 Answer

Remove white edges on texture help 2 Answers

PNG or TGA32 for semitransparent material 2 Answers

About shader! 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