3
2016
Fake Tube Light Shader

Tried to test idea about tube lights (or “line light”), by using custom lighting in shader,
you could sample the light several times from different positions/angles,
so that it looks like the light is not just a single point. (not really working here properly yet, but kind of gives the effect, so it might be possible)
Source: *Light direction is animated in shader to show the effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "Custom/FakeTubeishLight" | |
| { | |
| Properties | |
| { | |
| _MainTex ("Texture", 2D) = "white" {} | |
| } | |
| SubShader | |
| { | |
| Tags { "RenderType"="Opaque" } | |
| LOD 100 | |
| CGPROGRAM | |
| #pragma surface surf SimpleSpecular | |
| half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) { | |
| half4 c = half4(0,0,0,0); | |
| int steps = 16; | |
| // sample light many times with different values | |
| for(int i=0;i<steps;i++) | |
| { | |
| half3 l = lerp(half3(1,1,i),half3(i,1,1),fmod(_Time.x*10,1)); | |
| half3 h = normalize (lightDir*l + viewDir); | |
| half diff = max (0, dot (s.Normal, lightDir*l)); | |
| float nh = max (0, dot (s.Normal, h)); | |
| float spec = pow (nh, 10.0); | |
| c.rgb += (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten; | |
| } | |
| c.rgb /=steps; | |
| c.a = s.Alpha; | |
| return c; | |
| } | |
| struct Input { | |
| float2 uv_MainTex; | |
| }; | |
| sampler2D _MainTex; | |
| void surf (Input IN, inout SurfaceOutput o) { | |
| o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; | |
| } | |
| ENDCG | |
| } | |
| } |
If you want real Area Lights, check:
– UnityLabs : https://labs.unity.com/article/real-time-polygonal-light-shading-linearly-transformed-cosines
– Lux : http://forum.unity3d.com/threads/lux-an-open-source-physically-based-shading-framework.235027/page-23#post-2618971
Related Posts
Leave a comment
Recent posts
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
- Convert LAS/LAZ/PLY pointclouds to GLTF (GLB) Point Meshes (standalone converter)
Recent Comments
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
- on UI Scroll View automatic Content height
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by











