вторник, 3 ноября 2015 г.

Implemented shader for powerlines

After some digging to unity shaders I found way to make a shader, that has alpha masked, scrollable and self-illuminable.

This helps to make ship looks more alive. Blinking sparks of energy on power lines can tell you, that ship is working and listen to you.





You can see it in action below:



Game need rebalance for new dynamic power ships. I get killed at the end of demonstration. And this is normal difficulty. Maybe I have no enough skill to play, but game must be playable and winnable on normal. Tweaking is interesting part of gamedev.

Sense yourself as Garret from Mass-Effect in endless loop of calibration.

Core mechanics changes enforce to retest and rebalance all scenes, where it applied.

Here is code if you wish to use it:
Shader "Custom/AdditivMaskScrolled" {
         Properties {
         _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
         _MainTex ("Particle Texture", 2D) = "white" {}
         _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
     _ScrollXSpeed ("X Scroll Speed", Float) = 0.05
     _ScrollYSpeed ("Y Scroll Speed", Float) = 0.0
     _EmitLight ("Emission", Float) = 5
     _Specular ("Specular", Range(0,1)) = 0.5
         }
     
         SubShader {
             Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
             Blend SrcAlpha One
             AlphaTest Greater .01
             ColorMask RGB
             Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
             BindChannels {
                 Bind "Color", color
                 Bind "Vertex", vertex
                 Bind "TexCoord", texcoord
             }
             LOD 200
             
             CGPROGRAM
             #pragma surface surf Lambert noshadow noforwardadd
     
             sampler2D _MainTex;
             sampler2D _AlphaMap;
             fixed4 _TintColor;
       fixed _ScrollXSpeed;
       fixed _ScrollYSpeed;
       fixed _EmitLight;
       fixed _Specular;
     
             struct Input {
                 float2 uv_MainTex;
                 float2 uv_AlphaMap;
             };
     
             void surf (Input IN, inout SurfaceOutput o) {
         fixed2 scrolledUV = IN.uv_MainTex;
         fixed xScrollValue = _ScrollXSpeed*_Time;
         fixed yScrollValue = _ScrollYSpeed*_Time;

         scrolledUV += fixed2( xScrollValue, yScrollValue );
         half4 c = tex2D(_MainTex, scrolledUV);

                 o.Albedo = c.rgb*_TintColor;
                 o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_AlphaMap).r;
         o.Specular = _Specular;
         //o.Gloss = 10;
         o.Emission = _EmitLight;
             }
             ENDCG
         } 
         FallBack "Diffuse"
     }