Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Loken_01 · Nov 07, 2014 at 12:14 AM · shadershadowlightmappingcutout

Unity Custom CutOut Shader

Hey guys!

I've been searching Google, Unity forums and Unity Answers, all looking for a simple solution to my problem.

I downloaded the latest source files for built in shaders.

I then adapted the Cutout Diffuse/Spec/Normal/NormSpec shaders to use a custom texture for my alpha. This is primarily for carpet edges, fade out effects, etc.

The problem I've come across is that for lightmapping, it seems to always want to use the Alpha Channel of "_MainTex", regardless of how I have set up the surface shader.

In a previous thread I read that downloading the Extended Lightmapper plugin would help, but I didn't see any settings that would help with this case.

So is this to do with Unity's internal workings, or is it because of the fallback shader handling the shadow casting.

If it's the latter, how do I fix this?

Here's the Cutout Diffuse Shader. You can see how little of a change I made.

 Shader "Fade/Diffuse"
 {
     Properties
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _AlphaTex ("Alpha", 2D) = "white" {}
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
     }
 
     SubShader
     {
         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
         LOD 300
         
         CGPROGRAM
         #pragma surface surf Lambert alphatest:_Cutoff
 
         sampler2D _MainTex;
         sampler2D _AlphaTex;
         fixed4 _Color;
 
         struct Input
         {
             float2 uv_MainTex;
             float2 uv_AlphaTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             fixed4 MAIN = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             fixed4 ALPHA = tex2D(_AlphaTex, IN.uv_AlphaTex);
             o.Albedo = MAIN.rgb;
             o.Alpha = ALPHA;
         }
         ENDCG
     }
 
     FallBack "Transparent/Cutout/Diffuse"
 }


Thanks!

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 Fattie · Jul 07, 2020 at 12:12 AM 0
Share

$$anonymous$$ay help future googlers:



https://stackoverflow.com/questions/62766057/simple-cutout-i-e-mask-shader-based-on-ordinary-standard-shader-and-a-mask/62766227#62766227



1 Reply

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

Answer by atolver · Nov 07, 2014 at 03:21 PM

If you just want the alpha from your alpha texture, you should use ALPHA.a.

Unless you are trying to calculate alpha from the RGB values as well. In such a case, you would need to tell the shader which calculation to use (like adding the RGB values together or using the dot product).

Comment
Add comment · Show 3 · 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 Loken_01 · Nov 07, 2014 at 04:06 PM 0
Share

Hey atolver!

In terms of the actual display of the end material, it looks great.

I'm referring to the Beast Lightmapping issues.

No matter how the surface shader is set up, no matter where the end alpha comes from, etc, Beast still tries to use the non existent(blank) alpha channel of _$$anonymous$$ainTex.

avatar image atolver · Nov 07, 2014 at 05:04 PM 0
Share

Ah, gotcha. I don't know much about Beast.

This is just specualation, but it sounds like Beast is looking to use the alpha from something called "$$anonymous$$ainTex". Have you tried simply switching the names of the variables? That is, get your alpha value from $$anonymous$$ainTex and then get your color values from _AlphaTex. It's not uncommon for shaders to use predefined variable names.

avatar image Loken_01 · Nov 08, 2014 at 03:19 PM 0
Share

Hey atolver!

I've already stated in my main question that Beast uses "_$$anonymous$$ainTex.a", but for some effects I was looking to be able to use an entirely different texture.

I can't swap out the variables names because _$$anonymous$$ainTex is being used for diffuse, which is also passed to the fall back shader.

I'm asking if anyone knows how to get beast to accept a different texture for alpha.

I want to know if it's possible, or if it's a limitation.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there any double sided shadow casting transparent cutout shader? 3 Answers

Toon Shader Working With Multiple Spotlight Shadows (Pro) 0 Answers

(SOLVED) How to bake lightmaps with transparent cutout shader ? 2 Answers

Shader: Cutout behavior mixed with masking behavior 0 Answers

Can I turn off realtime shadows and use a shader to cast realtime shadows? 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