• 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 sanjit447 · Feb 10, 2016 at 12:48 PM · shaderemission

Is it possible to add RimLight to standard shader??

Hello everyone I'm a newbie to shaders, I'm customizing standard shader to achieve rim light to the character. I'm using albedo and emissive maps to get proper highlights on the character(its night mode). To get proper rim light i believe we should use emission color property for rim color. As I'm using emission texture, the emission color of the emission channel is also using the same property. Due to this reason, I'm not able to achieve both of them at once. If I'm changing the Rim color the same color is being applied to emission color also. Is there any workaround for this?? Can we use any other property to achieve rim color?

Here's what I've tried so far,

Shader "RimLightingStandard" {

 Properties {
     _Color ("Color", Color) = (1,1,1,1)
     _MainTex ("Albedo (RGB)", 2D) = "white" {}
     _Glossiness ("Smoothness", Range(0,1)) = 0.5
     _Metallic ("Metallic", Range(0,1)) = 0.0
     _RimColor ("Rim Color", Color) = (1,0.140625,0,1)
     _RimPower ("Rim Power", Range(0.01,8.0)) = 3
     _Emissive("Emission", 2D) = "black" {}
     _EmissiveColor("Emission Color", Color) = (1,1,1,1)
     _EmissiveIntensity("Emission Intensity", Range(0,10) ) = 1
     _DetailMask("Detail Mask(A)",2D) ="gray"{}
     _Detail ("Detail (RGB)", 2D) = "gray" {}          
   
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 200
     
     CGPROGRAM
     #pragma surface surf Standard fullforwardshadows
     #pragma target 3.0

     sampler2D _MainTex;    
     sampler2D _Detail;
     sampler2D _DetailMask;
     sampler2D _Emissive;
     
         
     
     struct Input {
         float2 uv_MainTex;
         fixed3 viewDir;
         float2 uv_Detail;
         float2 uv_DetailMask;             
         float2 uv_Emissive;

     };

     half _Glossiness;
     half _Metallic;
     fixed4 _Color;
     fixed4 _RimColor;
     fixed _RimPower;
     float4 _EmissiveColor;
     float _EmissiveIntensity;        
     

     void surf (Input IN, inout SurfaceOutputStandard o) {
         fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
          fixed4 mask = tex2D(_DetailMask, IN.uv_DetailMask);
          fixed4 detail=tex2D(_Detail,IN.uv_Detail);
          c.rgb *= detail.rgb*2;
          o.Albedo = c.rgb;
          
          o.Metallic = _Metallic;
          o.Smoothness = _Glossiness;
          o.Alpha = c.a;
         
         
          float4 Tex2D1=tex2D(_Emissive,(IN.uv_Emissive.xyxy).xy);
             float4 Multiply0=Tex2D1 *_Color.xyxy;
             float4 Multiply2=Multiply0 * _EmissiveIntensity.xxxx;
          o.Emission = Multiply2 ;
   
          
     // Rim
         fixed3 view = normalize(IN.viewDir);
         fixed3 nml = o.Normal;
         fixed VdN = dot(view, nml);
         fixed rim = 1.0 - saturate(VdN);    

         //This comment should be remove to work RIM COLOR         
         //o.Emission = _RimColor.rgb * pow(rim, _RimPower);
         
         
         
         
     }
     ENDCG
 } 
 FallBack "Diffuse"

}

Any help would be appreciated..

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by brentporter1 · Aug 17, 2016 at 12:47 AM

I was trying to do the same thing. I took what you have here and just did o.Emission = (Multiply2 + _RimColor.rgb) * pow(rim, _RimPower); and it worked.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How would I exclued parts of a texture from the lighting system? 0 Answers

Unity 5 Shader : Pulsing Emission range via scripting 2 Answers

Cannot implicitly convert from 'const float2' to 'float4' 0 Answers

Shader with emission texture 0 Answers

Shader Help : Add emission to my shader. 2 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