16
2012
Fake Glow Effect Shader
Interesting fake glow shader for unity indie (its based on unity builtin shaders).
(Right image has some linear fog enabled)
Features:
– Adjustable glow range, glow color, glow alpha
– Only works well on spheres..
Problems:
– Currently it only works when viewed from a certain axis direction..
– Not affected by lights yet..
Webplayer:
coming later..
Download source:
coming later..
*Earth map by NASA: http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.jpg
—
Image#2: Bigger glow (planet texture from: http://commons.wikimedia.org/wiki/File:Libya_Montes.jpg )
—
Shader "UnityCoder/GradientGlow2" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _OutlineColor ("Outline Color", Color) = (0,0,0,1) //_Outline ("Outline width", Range (.002, 0.03)) = .005 _Outline ("Outline width", Range (.002, 0.5)) = .005 _MainTex ("Base (RGB)", 2D) = "white" { } // _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } } CGINCLUDE // Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members vpos) #pragma exclude_renderers d3d11 xbox360 // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members vpos) #pragma exclude_renderers xbox360 #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : POSITION; float3 vpos; float4 color : COLOR; }; uniform float _Outline; uniform float4 _OutlineColor; v2f vert(appdata v) { v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal); float2 offset = TransformViewToProjection(norm.xy); o.pos.xy += offset * o.pos.z * _Outline; // o.pos.xyz += v.normal*_Outline; o.vpos = v.vertex.xyz; o.color = _OutlineColor; return o; } ENDCG SubShader { Tags { "RenderType"="Opaque" } //Tags { "RenderType"="Transparent" } // you can replace this pass with something else (rendering the globe) UsePass "UnityCoder/DefaultDiffuse2/BASE" Pass { Name "OUTLINE" Tags { "LightMode" = "Always" } Cull Front ZWrite On ColorMask RGB Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag half4 frag(v2f i) :COLOR { float3 gradientCenter = float3(0,0,0); float3 pos = normalize(i.vpos.xyz-gradientCenter.xyz); float4 c = float4(i.color.rgb,pos.z*i.color.a); return c; } ENDCG } } Fallback "Toon/Basic" }
Shader "UnityCoder/DefaultDiffuse2" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} //_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } } SubShader { Tags { "RenderType"="Opaque" } Pass { Name "BASE" Cull Off CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" sampler2D _MainTex; // samplerCUBE _ToonShade; float4 _MainTex_ST; float4 _Color; struct appdata { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; float3 normal : NORMAL; }; struct v2f { float4 pos : POSITION; float2 texcoord : TEXCOORD0; // float3 cubenormal : TEXCOORD1; }; v2f vert (appdata v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); // o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0)); return o; } float4 frag (v2f i) : COLOR { float4 col = _Color * tex2D(_MainTex, i.texcoord); // float4 cube = texCUBE(_ToonShade, i.cubenormal); // return float4(2.0f * cube.rgb * col.rgb, col.a); return float4(col.rgb, col.a); } ENDCG } } Fallback "VertexLit" }
Related Posts
9 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
Nice work!
I would totally want to use this shader!
I really need this shader , i dont care if it has problems please post the source code or email it to me. Thank you i hope its not too much trouble.
shader sources added, but it doesn’t really work well.. (create 2 shader files for those, assign the “GradientGlow2” shader to the object)
Thanks for your effort. Highly appreciated. I would like to shoot couple of questions.
1. Is this shader optimized for mobile platforms? I have created few shader codes but it seems to act weird in mobile devices.
2. Am trying to create a glow effects in my space ship model. It is for a mobile platform.
1. Not optimized for anything.. its based on toon shaders, so the glow is actually outline..
2. Is that 2D or full 3D?
Hey there,
I get wo errors:
Shader error in ‘UnityCoder/GradientGlow2’: ‘vert’: function return value missing semantics at line 32
Shader error in ‘UnityCoder/GradientGlow2’: ‘frag’: input parameter ‘i’ missing semantics at line 75
Disable dx11 mode or add something like UNITY_INITIALIZE_OUTPUT(Input,o); to the vert()
Volumetric lines
http://forum.unity3d.com/threads/volumetric-lines.181618/
Glow highlighting in Unity:
http://xroft666.blogspot.fi/2015/07/glow-highlighting-in-unity.html