• 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

How to hide GUI text behind 3d object? 1 Answer

Removing the mirror effect in Reflection probes 0 Answers

Why I couldnt control alpha in Surface shader? 3 Answers

Is it possible to add RimLight to standard shader?? 1 Answer

Standard Shader Emissive Warning? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges