• 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 /
  • Help Room /
avatar image
0
Question by YoYo89 · Sep 04, 2017 at 06:26 PM · unity 5shaderemissiondecalz-fighting

Emissive Blended Decal

Hey All,

I've been trying to get an emissive blended decal with a texture to define the emissive map, color and intensity settings working.

I've gotten it working so far in the sense that the decal now accepts an emissive map, emits light and sets intensity and color properly. My problem now is that I've lost the z-fighting fix and transparency of the shader I based this on. The original BlendedDecal is from the BootCamp demo I believe. Thanks in advance all!

I'm not using the standard shader as a cutout because of z-fighting and my target is WebGL.

 Shader "Custom/EmissiveBlendedDecal"
 {
     Properties
     {
         _Color ("Tint", Color) = (1,1,1,1)
         _MainTex ("Texture", 2D) = "white" {}
         _Emissive("Emissive", 2D) = "black" {}
         _EmissiveColor("EmissiveColor", Color) = (1,1,1,1)
         _EmissiveIntensity("EmissiveIntensity", Range(0,10) ) = 0.5
     }
     
     SubShader
     {
         Lighting On
         ZTest LEqual
         ZWrite Off
         Tags { "Queue" = "Transparent" }
         LOD 250
         Pass
         {
             Alphatest Greater 0
             Blend SrcAlpha OneMinusSrcAlpha
             Offset -1, -1
             SetTexture [_MainTex]
             {
                 ConstantColor[_Color]
                 Combine texture * constant
             }
         }
 
         CGPROGRAM
         #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap halfasview
 
         inline fixed4 LightingMobileBlinnPhong(SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
         {
             fixed4 c;
             c.rgb = (s.Albedo * _LightColor0.rgb + _LightColor0.rgb) * (atten*2);
             c.a = 0.0;
             return c;
         }
 
         sampler2D _MainTex;
         sampler2D _Emissive;
         float4 _EmissiveColor;
         float _EmissiveIntensity;
 
         struct Input 
         {
             float2 uv_MainTex;
             float2 uv_Emissive;
         };
  
         void surf(Input IN, inout SurfaceOutput o) 
         {
             fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
             o.Albedo = tex.rgb;
             o.Gloss = tex.a;
             o.Alpha = tex.a;
         
             float4 Tex2D1=tex2D(_Emissive,(IN.uv_Emissive.xyxy).xy);
             float4 Multiply0=Tex2D1 * _EmissiveColor;
             float4 Multiply2=Multiply0 * _EmissiveIntensity.xxxx;
         
             o.Emission = Multiply2;
         }
         
         ENDCG
     }
     FallBack "Custom/BlendedDecal"
 }

Edit: I wrote another shader based on the decal example in the manual, here is the result posted below if anyone else is looking for a setup like I was.

Edit 2: Added a toggle for emission so it can be toggled via script.

 Shader "Custom/EmissiveDecal" 
 {
   Properties 
   {
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _Emissive("Emissive", 2D) = "black" {}
     _EmissiveColor("EmissiveColor", Color) = (1,1,1,1)
     _EmissiveIntensity("EmissiveIntensity", Range(0,10) ) = 0.5
     [Toggle(EMISSION)]
     _ToggleEmission ("Emission", Float) = 0
   }
 
   SubShader 
   {
     Tags 
     { 
         "RenderType"="Opaque" 
         "Queue"="Geometry+1" 
         "ForceNoShadowCasting"="True"
     }
     LOD 200
     Offset -1, -1
     
     CGPROGRAM
     #pragma surface surf Lambert decal:blend
     #pragma shader_feature EMISSION
     
     sampler2D _MainTex;
     sampler2D _Emissive;
     float4 _EmissiveColor;
     float _EmissiveIntensity;
 
     struct Input 
     {
         float2 uv_MainTex;
         float2 uv_Emissive;
     };
 
     void surf (Input IN, inout SurfaceOutput o) 
     {
         half4 c = tex2D (_MainTex, IN.uv_MainTex);
         o.Albedo = c.rgb;
         o.Alpha = c.a;
 
         #ifdef EMISSION
         
         float4 Tex2D1=tex2D(_Emissive,(IN.uv_Emissive.xyxy).xy);
         float4 Multiply0=Tex2D1 * _EmissiveColor;
         float4 Multiply2=Multiply0 * _EmissiveIntensity.xxxx;
     
         o.Emission = Multiply2;
 
         #endif
     }
     ENDCG
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

218 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 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 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 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 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 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 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 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

Low particle emission rate 1 Answer

Shadows Weird Triangles on my character 1 Answer

Changing color on specific tile in texture at runtime 0 Answers

Is it possible to create a shader, where only a certain part of it changes color when, for example, an object with that shader collides with another object? 0 Answers

Does Unity Plus allow you to use shaders that unity gives (example, the toon shader), or full screen effects? 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