• 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
0
Question by jhmadden · Oct 04, 2017 at 06:28 PM · shadersshadowsglow

Interacting a facing glow with light

I'm trying to get a object to have an inner glow but only where there is light hitting it. I found a shader that can create an inner glow with a surface that doesn't interact with light like this... alt text

and I also found a shader from @Namey5 that has an inner glow and reacts with light but doesn't allow for a surface to be underneath it. I've tried placing it over another sphere and adjusting the cull settings but could not get it working properly. alt text

I'd like to have a shader that combines the option to have an underlying surface of the first one with the ability to interact with light from the second one. It should be similar to the facing layer weight blender has.

I've attached the code for each shader below. Thanks in advance!!

First shader

 Shader "Custom/ItemGlow" {
     Properties {
         _ColorTint("Color Tint", Color) = (1,1,1,1)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _BumpMap("Normal Map", 2D) = "bump" {}
         _RimColor("Rim Color", Color) = (1,1,1,1)
         _RimPower("Rim Power", Range(1.0, 20.0)) = 3.0
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Standard fullforwardshadows
 
         // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
 
 
         struct Input {
 
             float4 color : Color;
             float2 uv_MainTex;
             float2 uv_BumpMap;
             float3 viewDir;
         };
 
         float4 _ColorTint;
         sampler2D _MainTex;
         sampler2D _BumpMap;
         float4 _RimColor;
         float _RimPower;
 
 
         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
         // #pragma instancing_options assumeuniformscaling
         UNITY_INSTANCING_CBUFFER_START(Props)
             // put more per-instance properties here
         UNITY_INSTANCING_CBUFFER_END
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             IN.color = _ColorTint;
             o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.color;
             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
             half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
             o.Emission = _RimColor.rgb * pow(rim, _RimPower);
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

Second shader

  Shader "Custom/Atmosphere" {
      Properties {
          _Color ("Color", Color) = (1,1,1,1)
          _Size ("Atmosphere Size Multiplier", Range(0,16)) = 4
          _Rim ("Fade Power", Range(0,8)) = 4
          _Light ("Lighting Power", Range(0,10)) = 1.4
          _Ambient ("Ambient Power", Range (0,6)) = 0.8
      }
      SubShader {
          Tags { "RenderType"="Transparent" }
          LOD 200
  
          Cull Front
          
          CGPROGRAM
          // Physically based Standard lighting model, and enable shadows on all light types
          #pragma surface surf NegativeLambert fullforwardshadows alpha:fade
          #pragma vertex vert
  
          // Use shader model 3.0 target, to get nicer looking lighting
          #pragma target 3.0
  
  
          struct Input {
              float3 viewDir;
          };
  
          half _Size;
          half _Rim;
          half _Light;
          half _Ambient;
          fixed4 _Color;
  
          void vert (inout appdata_full v) {
              v.vertex.xyz += v.vertex.xyz * _Size / 10;
              v.normal *= -1;
          }
  
          half4 LightingNegativeLambert (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
              s.Normal = normalize (s.Normal);
  
              half diff = max (0, dot (-s.Normal, lightDir)) * _Light + _Ambient;
  
              half4 c;
              c.rgb = (s.Albedo * _LightColor0 * diff) * atten;
              c.a = s.Alpha;
              return c;
          }
  
          void surf (Input IN, inout SurfaceOutput o) {
              half rim = 1.0 - saturate (dot (normalize (IN.viewDir), o.Normal));
  
              // Albedo comes from a texture tinted by color
              fixed4 c = _Color;
              o.Albedo = c.rgb;
              o.Alpha = lerp (0, 1, pow (rim, _Rim));
          }
          ENDCG
      }
      FallBack "Diffuse"
  }

screen-shot-2017-10-04-at-20856-pm.png (198.8 kB)
screen-shot-2017-10-04-at-21117-pm.png (155.6 kB)
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
1
Best Answer

Answer by Namey5 · Oct 05, 2017 at 08:10 AM

My shader was originally made for a different scenario (although I don't remember the specifics). If you want it to look like the first one, you can make a simple modification to make the rim lighting interact with the diffuse lighting.

      Shader "Custom/ItemGlow" {
          Properties {
              _ColorTint("Color Tint", Color) = (1,1,1,1)
              _MainTex ("Albedo (RGB)", 2D) = "white" {}
              _BumpMap("Normal Map", 2D) = "bump" {}
              _RimColor("Rim Color", Color) = (1,1,1,1)
              _RimPower("Rim Power", Range(1.0, 20.0)) = 3.0
          }
          SubShader {
              Tags { "RenderType"="Opaque" }
              
              CGPROGRAM
              // Physically based Standard lighting model, and enable shadows on all light types
              #pragma surface surf Standard fullforwardshadows
      
              // Use shader model 3.0 target, to get nicer looking lighting
              #pragma target 3.0
      
      
              struct Input {
      
                  float4 color : Color;
                  float2 uv_MainTex;
                  float2 uv_BumpMap;
                  float3 viewDir;
              };
      
              float4 _ColorTint;
              sampler2D _MainTex;
              sampler2D _BumpMap;
              float4 _RimColor;
              float _RimPower;
      
      
              // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
              // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
              // #pragma instancing_options assumeuniformscaling
              UNITY_INSTANCING_CBUFFER_START(Props)
                  // put more per-instance properties here
              UNITY_INSTANCING_CBUFFER_END
      
              void surf (Input IN, inout SurfaceOutputStandard o) {
                  IN.color = _ColorTint;
                  o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.color;
                  o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
                  half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
                  o.Albedo += _RimColor.rgb * pow(rim, _RimPower);        //This is the line that has changed
              }
              ENDCG
          }
          FallBack "Diffuse"
      }

If this isn't what you need, I'm happy to rewrite the lighting of mine into a new shader.

Comment
Add comment · Show 1 · 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 jhmadden · Oct 05, 2017 at 03:30 PM 0
Share

This works perfectly for what I want thank you!

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

78 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

Related Questions

Strange shadow/texture issue on Save Scene 0 Answers

Doom Classic Effect - Realtime Pixelated Shadows 1 Answer

Shadows looks different in editor than in build 1 Answer

Hiding a sprite partially (shader? masking?) 0 Answers

2D drop shadows with faded edges and no additive alpha blending 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