Dear great community! After importing the Madfinger Demo to see how things are going on there i found a shader that made me thinking and testing all day without getting a clear result how that one was done. It's about the transparent borders shown in the picture below (right one). I tried to reproduce the effect by importing my own plane (left one) after i put the same shader/material on it. But somehow without luck. I still think it's done by the shader. But how should the plane be prepared so that the shader does this smooth transparent borders on any kind of a similar object. I am really confused how they did that. Respect to Madfinger Games. The guys there are freaking tuff. Normally i am able to reproduce things. O_O Am i that blind? O_O here is the shader, so if someone wants to reproduce the effect too: Code (csharp): Shader "MADFINGER/Environment/Scroll 2 Layers Sine AlphaBlended" { Properties { _MainTex ("Base layer (RGB)", 2D) = "white" {} _DetailTex ("2nd layer (RGB)", 2D) = "white" {} _ScrollX ("Base layer Scroll speed X", Float) = 1.0 _ScrollY ("Base layer Scroll speed Y", Float) = 0.0 _Scroll2X ("2nd layer Scroll speed X", Float) = 1.0 _Scroll2Y ("2nd layer Scroll speed Y", Float) = 0.0 _SineAmplX ("Base layer sine amplitude X",Float) = 0.5 _SineAmplY ("Base layer sine amplitude Y",Float) = 0.5 _SineFreqX ("Base layer sine freq X",Float) = 10 _SineFreqY ("Base layer sine freq Y",Float) = 10 _SineAmplX2 ("2nd layer sine amplitude X",Float) = 0.5 _SineAmplY2 ("2nd layer sine amplitude Y",Float) = 0.5 _SineFreqX2 ("2nd layer sine freq X",Float) = 10 _SineFreqY2 ("2nd layer sine freq Y",Float) = 10 _Color("Color", Color) = (1,1,1,1) _MMultiplier ("Layer Multiplier", Float) = 2.0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } Blend SrcAlpha OneMinusSrcAlpha Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } LOD 100 CGINCLUDE #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma exclude_renderers molehill #include "UnityCG.cginc" sampler2D _MainTex; sampler2D _DetailTex; float4 _MainTex_ST; float4 _DetailTex_ST; float _ScrollX; float _ScrollY; float _Scroll2X; float _Scroll2Y; float _MMultiplier; float _SineAmplX; float _SineAmplY; float _SineFreqX; float _SineFreqY; float _SineAmplX2; float _SineAmplY2; float _SineFreqX2; float _SineFreqY2; float4 _Color; struct v2f { float4 pos : SV_POSITION; float4 uv : TEXCOORD0; fixed4 color : TEXCOORD1; }; v2f vert (appdata_full v) { v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); o.uv.xy = TRANSFORM_TEX(v.texcoord.xy,_MainTex) + frac(float2(_ScrollX, _ScrollY) * _Time); o.uv.zw = TRANSFORM_TEX(v.texcoord.xy,_DetailTex) + frac(float2(_Scroll2X, _Scroll2Y) * _Time); o.uv.x += sin(_Time * _SineFreqX) * _SineAmplX; o.uv.y += sin(_Time * _SineFreqY) * _SineAmplY; o.uv.z += sin(_Time * _SineFreqX2) * _SineAmplX2; o.uv.w += sin(_Time * _SineFreqY2) * _SineAmplY2; o.color = _MMultiplier * _Color * v.color; return o; } ENDCG Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // #pragma fragmentoption ARB_precision_hint_fastest fixed4 frag (v2f i) : COLOR { fixed4 o; fixed4 tex = tex2D (_MainTex, i.uv.xy); fixed4 tex2 = tex2D (_DetailTex, i.uv.zw); o = tex * tex2 * i.color; return o; } ENDCG } } }
They are using vertex color. When you create your mesh, make the outer vertices as transparent as needed with vertex colors. Like that you can easily get this effect.
Yep the shader uses vertex alpha to control the transparency amount and vertex colour to control the darkening/orange tint at the smoke source.
It's not a madfinger thing, it's a really old technique used heavily since DX7 / opengl quake 2 days. Easy to see how it seems to be new though. These tricks are used all the time, naughty dog love tricks like this on ps3. These kinds of tricks aren't going away, they are staple development classics, regardless of hardware. People always assume it's shader magic but really its about doing less work whenever you can to get the same effect. Even on next gen consoles, it's not a time to be lazy so exploring these tricks will serve you well. Take world of warcraft, half of all it's special effects are alpha mesh tricks like this - uv scrolling fire etc. I do it in The Other Brothers for vignetting, for flowing slime and so on. You should explore what vertex colours can give you for your shaders, think about vertex attributes being just values you can use for embedding information the shader can use for other things. For example you might use vertex alpha as flexibility for plant deformation.