Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by romanklco · Apr 21, 2016 at 02:44 PM · shaderblur

Gradient glow shader

Hey guys. This is driving me crazy, I'm searching for solution for days, but nothing seems to answer my problem. Here is the deal. I need to create aura around low poly planet. So I was looking for shaders to add outline of some kind, but this won't work since with flat shading, normals break the effect.

So basically I need to fake the effect by getting the shape of rendered object in solid color, apply large blur and then maybe in another pass place image of the standard render over it. I don't need any atmosphere-like scattering, just to make it look like the color from the planet bleeds into the space somehow.

I attach picture of what I'm looking for. Can someone maybe guide me on which way to look to achieve this? (Mind, I'm complete shader noob.)

alt text

scene.jpg (101.5 kB)
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 Soraphis · Apr 22, 2016 at 11:52 AM 0
Share

i think you can archive this with the help of this: http://xroft666.blogspot.de/2015/07/glow-highlighting-in-unity.html

it's imho the best way for outlines/glow effects in unity

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Namey5 · Apr 22, 2016 at 10:26 AM

You don't need to do that at all. All you need to do is have the same model at a larger size, and interpolate the alpha based on the fresnel shading technique. The following shader will do all of this, including the size:

 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
     }
     SubShader {
         Tags { "RenderType"="Transparent" }
         LOD 200
 
         Cull Front
         
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Lambert 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;
         fixed4 _Color;
 
         void vert (inout appdata_full v) {
             v.vertex.xyz += v.vertex.xyz * _Size / 10;
             v.normal *= -1;
         }
 
         void surf (Input IN, inout SurfaceOutput o) {
             half rim = saturate (dot (normalize (IN.viewDir), normalize (o.Normal)));
 
             // Albedo comes from a texture tinted by color
             fixed4 c = _Color;
             o.Emission = c.rgb;
             o.Alpha = lerp (0, 1, pow (rim, _Rim));
         }
         ENDCG
     }
     FallBack "Diffuse"
 }
 

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 Namey5 · Apr 22, 2016 at 11:36 AM 0
Share

If you want this to interact with lighting, you can use this:

 Shader "Custom/Atmosphere" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _Size ("Atmosphere Size $$anonymous$$ultiplier", 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
         
         CGPROGRA$$anonymous$$
         // 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 = 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"
 }
 
avatar image odival · Jul 13, 2018 at 02:35 AM 0
Share

I know this question is 2y old but this shader is amazing! Too bad on Unity 2017.2 the mesh gets transparent if the directional light has any shadows, also for some reason my low poly models done on blender gets somewhat weird when I apply the material with this shader. It creates the atmosphere but doesnt fade the edges like the unity-made primitives.... any ideas on how to fix this?

avatar image ctchmos odival · Mar 31, 2021 at 09:08 AM 0
Share

Make sure the normals of the geometry you are using are correct. I had the same problem, and I realized it was because the low poly mesh I was using was exported with flat normals.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is shader hiding some components in front of it but not others? 0 Answers

Convert Blur Shader to work with UniversalRP 0 Answers

Shader breaks on device. 0 Answers

Unity 5 Custom Terrian Shader appears blurry. 1 Answer

Shader blurs only one shader 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