Unity Alpha



Over the past several years working in Unity many of my projects have involved some kind of mixed reality, augmented reality, transparent MovieTexture, or something of the sort. One custom shader that I have reused a lot for these effects is an unlit alpha mask shader. Alpha masking is simply setting the opacity of a texture’s pixels, usually with a separate texture map.

I’m certainly no Unity shader expert, but creating this shader is relatively straightforward if we start with the right foundation. In this case we’ll be modifying the closest thing to what we want – Unity’s own unlit alpha shader. We’ll start with the completed version and then explain how it was modified from the source.

Sprite Alpha Mask is a Script Package for Unity designed to apply multiple full screen transparency Masks over Sprites.Obtain it from the Unity Asset Store. Unity World Headquarters 1901 NW Blue Parkway Unity Village, MO 64065 816-524-3550. Alphas are the first public releases of a new TECH stream version of Unity. During the alpha phase, we’re progressively adding all the new features that are scheduled to be part of the final release. At the same time, the features get tested collectively for the first.

Unity Shader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Unlit alpha-blended shader.
// - no lighting
// - no lightmap support
// - no per-material color
Shader 'Unlit/AlphaMask'{
Properties {
_MainTex ('Base (RGB)', 2D)='white'{}
_AlphaTex ('Alpha mask (R)', 2D)='white'{}
}
SubShader {
Tags {'Queue'='Transparent''IgnoreProjector'='True''RenderType'='Transparent'}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include 'UnityCG.cginc'
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _AlphaTex;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex= mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord= TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i): SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
fixed4 col2 = tex2D(_AlphaTex, i.texcoord);
return fixed4(col.r, col.g, col.b, col2.r);
}
ENDCG
}
}
}

Important: This shader will only work for Unity 4.5 or newer. Earlier versions will be similar but usually output COLOR from the fragment shader instead of SV_Target.

What we do here is:
  1. Start with the built-in Unity unlit alpha shader (version 4.5.1)
  2. Add a texture sampler for an alpha mask
  3. Apply the color channel from the mask texture to the alpha of the main texture

Since we’re using an unlit shader as our base, our texture’s color will be unaffected by scene lighting since it is ignored. In addition the shader will be more efficient than a normal lit shader since it doesn’t have to calculate light or shadows. And as an alpha shader we can assume it already contains the tags, blending, etc. to render transparency properly.

Free photo printing software for mac. Note: You can find an archive of Unity’s built-in shaders here.

Unity Shader

This is the actual name of the shader that Unity will recognize preceded by its folder path which is used for organization. Regardless of the name of a .shader file, once imported it can be added as the shader of a material via the drop down menu as Folder/Name.

Unity Shader

Unity Alphatomask

_AlphaTex ('Alpha mask (A)', 2D)='white'{}

Here we expose a new alpha channel texture that defaults to a solid white. This is what allows us to dynamically set a texture in the Unity editor like so:

Unity Shader

Unity Alpha

This defines a new sampler2D variable linked to our alpha texture property above. It is used to read a pixel color of the texture, given a UV coordinate.

Unity Shader

fixed4 col2 = tex2D(_AlphaTex, i.texcoord);
return fixed4(col.r, col.g, col.b, col2.r);

Here in the fragment shader is where all the magic happens. By this point variable col contains the rgba color channel data from our main texture. We simply added a second variable col2 to store the color data from our alpha texture. Lastly we return a 3rd new color combining the first two, using the rgb from col and the r from col2 as the alpha. This is then returned by the shader as the pixel color drawn to the screen!

Note: We pull from the r channel of our alpha texture because ideally you want your textures to be as small as possible. Usually a full color texture with alpha is 32-bit rgba (8 bits for each color channel). Although, since only one color channel is needed for our alpha mask, we can use an 8-bit single channel gray-scale texture which, when imported into Unity as a default texture type, lives in the r channel.

Note: The second parameter of tex2D() we are passing a pixel’s UV coordinates. In the example shader we are using the same UV’s as the main texture. If you look up into struct v2f you will see it defined there as TEXCOORD0. If you wanted to use a second UV set for the mask you can define a new variable for it there as well as TEXCOORD1 and then pass that to tex2d() instead.

Unity alpha map
Concluding.

Hopefully you learned a little something about tweaking shaders. This shader is perhaps the most useful because you can use it to add alpha to a MovieTexture, switch the two and have an animated alpha channel, or even use a MovieTexture for both! Cthulhu vst download mac. There are certainly other uses for it and shaders like it though, like sharing pixel data between multiple images or dynamically modifying a texture’s alpha.

Enjoy!

Ben
Alpha

Unity pods were seeded on the surface of Chiron by the disintegrating UNS Unity. Depending on map settings, they are either scattered all over the map or only near original landing zones. Unity pods are almost invariably beneficial to your faction and sending out a couple of scout units to track them down can give you a powerful edge over other factions.

Note that Artifacts which are used to explore pods have a 50% chance of vanishing without a trace.

Background[edit | edit source]

The Unity carried dozens of supply pods: relatively small containers, each . containing a vehicle or piece of equipment, designed to land independently on Planet's surface. The original settlement plan called for the pods to be launched only after a careful orbital survey. This would have allowed their placement in strategic locations, near the chosen site for the initial settlement.

Unfortunately, the Unity disaster scattered them at random across the face of Planet. Supply pods were designed for soft landings, and could even float if they landed in water. They varied considerably in size. The smallest were about 200 cubic feet in volume, and contained computers or automated manufacturing equipment. The largest were about 10,000 cubic feet in size, and weredesigned to land in the shallow water just offshore, carrying Unity Foil craft tothe surface. Some pods carried robotic explorers, which would emerge afterlanding to survey the region or even to begin farming or mining operations.

As the colonists explored Planet in the early decades, they were always on the lookout for supply pods. Unfortunately, the pods often 'irritated' the native life forms around their landing sites. Many an explorer discovered too late that the vicinity of a pod was infested with angry mind worms. Adobe creative cloud download error mac. In some cases, disturbing a pod triggered an outbreak of wild expansion on the part of nearby xenofungus (see main text).

Unity Alpha Map

Pod effects[edit | edit source]

  • Agricultural Pod: Lots of free farms or forests in the area.
  • Alien Artifact: Gives you a free artifact to bring back to a base with a Network Node.
  • Cartographic/Sonar Pod. Shows all land/sea tiles within 5 squares.
  • Data Pod. Free technological advance, restricted to levels 1 and 2.
  • Dimensional Gate/Tidal Wave. “Teleports” unit elsewhere in same continent/sea.
  • New Resource. In normal, non-fungus, non-sea squares this event is as likely as all of the other events combined (i.e. about 50% of pods will be resources), but a “discover resource” pod has a 50% chance of producing one of the other results as well.
  • Earthquake (only if pod is on land). New mountain created here.
  • Fungal Bloom.
  • Hydrology Pod. Creates new river.
  • Materials Pod. Completes production of random item at nearest base.
  • Mind Worms (Isle of the Deep if at sea). This pod is six times more likely than any other pod (except Discover Resource). There is a 1 in 6 chance of a “big mind worms” event (lots of worms all around), otherwise only one worm is discovered. (There is never more than one Isle of the Deep discovered.) This event is ignored when adjacent to a base. If this isn’t the “big mind worms” version, then the event is more likely to be ignored the nearer you are to a friendly base.
  • Mining Pod. Lots of free mines in the area.
  • Monolith.
  • Power Pod. Lots of free solar power in the area.
  • Resupply Pod. 25-200 energy credits (bigger totals more likely at sea and later in game).
  • Sea Farming Pod. Lots of free kelp in the area.
  • Supply Pod. Normally you get a Unity Rover. You may sometimes get a Unity Foil, particularly if your continent is small. If Synthetic Fossil Fuels have been discovered, you have a 1 in 3 chance of finding a Unity Scout Chopper.

Unity Change Alpha In Script

Retrieved from 'https://alphacentauri.fandom.com/wiki/Unity_pods?oldid=6256'




Comments are closed.