I’m afraid my shader knowledge is poor but is it possible to make a shader which reduces the alpha of a texture as the position goes u?. So that an object fades out as it goes towards the sky?
You don’t need shader knowledge to do this so long as you use an existing shader that has a tint colour, you can read material.color, and set the .a value.
http://unity3d.com/support/documentation/ScriptReference/Material-color.html
I played around with some shaders and the Shader Lab reference, and ended with a Frankenstein creature: it’s based on the last Shader Lab reference example and has some parts stolen from Transparent/Diffuse and others.
It’s a surface shader with a vertex program that converts the vertex coordinates from model to world space and calculates alpha based on the Y value. This alpha is passed to the finalcolor program and sets the final color a component.
The alpha value is interpolated by the graphics unit and makes the object vanish according to the Y coordinate. The parameters Opaque Y and Transparent Y set the heights where the magic starts and ends. If Opaque Y is higher than Transparent Y, you get the opposite effect (object vanishes at low Y).
To use this shader, copy and paste it in any text editor, then save it in some Assets subfolder as Y-Vanishing.shader (or other name.shader of your choice). You can then create a new material and select this shader (FX/Y Vanishing).
Shader "FX/Y Vanishing" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_LoY ("Opaque Y", Float) = 0
_HiY ("Transparent Y", Float) = 10
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
// define finalcolor and vertex programs:
#pragma surface surf Lambert finalcolor:mycolor vertex:myvert
struct Input {
float2 uv_MainTex;
half alpha;
};
sampler2D _MainTex;
half _LoY;
half _HiY;
void myvert (inout appdata_full v, out Input data) {
// convert the vertex to world space:
float4 worldV = mul (_Object2World, v.vertex);
// calculate alpha according to the world Y coordinate:
data.alpha = 1 - saturate((worldV.y - _LoY) / (_HiY - _LoY));
}
void mycolor (Input IN, SurfaceOutput o, inout fixed4 color) {
// set the vertex color alpha to the value calculated:
color.a = IN.alpha;
}
void surf (Input IN, inout SurfaceOutput o) {
// simply copy the corresponding texture element color:
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}