I upgraded to Unity 3.x and was surprised to see that my shader didn’t work any more. It turns out that Unity had commented out almost everything! Guess that’ll teach me to upgrade without reading all the documentation. Unfortunately, I’m not much good at shading and what I had before was pretty much cobbled together from bits and pieces of other things and I have no idea how to upgrade it. Can anyone help out a bit?
Shader "Terrain/DynamicGlobe" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Ocean (RGB)", 2D) = "white" {}
_MainTex2 ("Shoreline/Sand (RGB)", 2D) = "white" {}
_MainTex3 ("Grass (RGB)", 2D) = "white" {}
_MainTex4 ("Mountains (RGB)", 2D) = "white" {}
_Mask ("Ocean/dirt/grass/mountain Mixing Mask (RGBA)", 2D) = "gray" {}
_PolarMask ("Size of polar ice caps Mixing Mask (RGB)", 2D) = "white" {}
}
// Calculates lighting per vertex, but applies
// light attenuation maps or spot cookies per pixel.
// Quite fine for tesselated geometry.
Category {
/* Upgrade NOTE: commented out, possibly part of old style per-pixel lighting: Blend AppSrcAdd AppDstAdd */
Fog { Color [_AddFog] }
// ------------------------------------------------------------------
// ARB fragment program
#warning Upgrade NOTE: SubShader commented out; uses Unity 2.x per-pixel lighting. You should rewrite shader into a Surface Shader.
/*SubShader {
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "Always" /* Upgrade NOTE: changed from PixelOrNone to Always */}
Color [_PPLAmbient]
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma fragment frag
#pragma multi_compile_builtin_noshadows
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
struct v2f {
float4 uv[6] : TEXCOORD0;
float4 diff : COLOR0;
};
uniform sampler2D _MainTex : register(s0);
uniform sampler2D _MainTex2 : register(s1);
uniform sampler2D _MainTex3 : register(s2);
uniform sampler2D _MainTex4 : register(s3);
uniform sampler2D _Mask : register(s4);
uniform sampler2D _PolarMask : register(s5);
half4 frag (v2f i) : COLOR
{
// get the four layer colors
half4 color1 = tex2D( _MainTex, i.uv[0].xy );
half4 color2 = tex2D( _MainTex2, i.uv[1].xy );
half4 color3 = tex2D( _MainTex3, i.uv[2].xy );
half4 color4 = tex2D( _MainTex4, i.uv[3].xy );
// get the mixing mask texture
half4 mask = tex2D( _Mask, i.uv[4].xy );
// get the polar mixing mask texture
half4 polarMask = tex2D( _PolarMask, i.uv[5].xy );
half4 c;
// mix the four layers
c.xyz =
(
(color1.xyz * mask.r + polarMask.r) +
(color2.xyz * mask.g + polarMask.r) +
(color3.xyz * mask.b + polarMask.r) +
(color4.xyz * mask.a + polarMask.r)
) * i.diff.xyz * 2;
c.w = 0;
return c;
}
ENDCG
SetTexture[_MainTex] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
SetTexture[_MainTex2] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
SetTexture[_MainTex3] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
SetTexture[_MainTex4] {constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
SetTexture[_Mask] {}
}
// Vertex lights
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
Lighting On
Material {
Diffuse [_Color]
Ambient [_Color]
Emission [_PPLAmbient]
}
SetTexture [_MainTex] { constantColor [_Color] Combine texture * primary DOUBLE, texture * constant}
}
// Pixel lights
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
Material { Diffuse [_Color] }
Lighting On
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
// TODO: need vertex-lighting emulation here!
#pragma fragment frag
#pragma multi_compile_builtin_noshadows
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#ifdef POINT
#define LIGHTING_COORDS float3 _LightCoord : TEXCOORD5;
uniform sampler3D _LightTexture0 : register(s5);
#ifdef SHADER_API_D3D9
#define LIGHT_ATTENUATION(a) (tex3D(_LightTexture0, a._LightCoord).r)
#else
#define LIGHT_ATTENUATION(a) (tex3D(_LightTexture0, a._LightCoord).w)
#endif
#endif
#ifdef SPOT
#define LIGHTING_COORDS float4 _LightCoord : TEXCOORD5; float4 _LightCoord2 : TEXCOORD6;
uniform sampler2D _LightTexture0 : register(s5);
uniform sampler2D _LightTextureB0 : register(s6);
#define LIGHT_ATTENUATION(a) (tex2Dproj (_LightTexture0, a._LightCoord.xyz).w * tex2D(_LightTextureB0, a._LightCoord2.xy).w)
#endif
#ifdef DIRECTIONAL
#define LIGHTING_COORDS
#define LIGHT_ATTENUATION(a) 1.0
#endif
#ifdef POINT_NOATT
#define LIGHTING_COORDS
#define LIGHT_ATTENUATION(a) 1.0
#endif
#ifdef POINT_COOKIE
#define LIGHTING_COORDS float3 _LightCoord : TEXCOORD5;
uniform samplerCUBE _LightTexture0 : register(s5);
#define LIGHT_ATTENUATION(a) (texCUBE(_LightTexture0, a._LightCoord).w)
#endif
#ifdef DIRECTIONAL_COOKIE
#define LIGHTING_COORDS float2 _LightCoord : TEXCOORD5;
uniform sampler2D _LightTexture0 : register(s5);
#define LIGHT_ATTENUATION(a) (tex2D(_LightTexture0, a._LightCoord).w)
#endif
struct v2f {
float4 uv[5] : TEXCOORD0;
LIGHTING_COORDS
float4 diff : COLOR0;
};
uniform sampler2D _MainTex : register(s0);
uniform sampler2D _MainTex2 : register(s1);
uniform sampler2D _MainTex3 : register(s2);
uniform sampler2D _MainTex4 : register(s3);
uniform sampler2D _Mask : register(s4);
half4 frag (v2f i) : COLOR
{
// get the four layer colors
half4 color1 = tex2D( _MainTex, i.uv[0].xy );
half4 color2 = tex2D( _MainTex2, i.uv[1].xy );
half4 color3 = tex2D( _MainTex3, i.uv[2].xy );
half4 color4 = tex2D( _MainTex4, i.uv[3].xy );
// get the mixing mask texture
half4 mask = tex2D( _Mask, i.uv[4].xy );
half4 c;
// mix the four layers
c.xyz = (color1.xyz * mask.r + color2.xyz * mask.g + color3.xyz * mask.b + color4.xyz * mask.a) * i.diff.xyz * (LIGHT_ATTENUATION(i) * 2);
c.w = 0;
return c;
}
ENDCG
SetTexture[_MainTex] {}
SetTexture[_MainTex2] {}
SetTexture[_MainTex3] {}
SetTexture[_MainTex4] {}
SetTexture[_Mask] {}
SetTexture[_LightTexture0] {}
SetTexture[_LightTextureB0] {}
}
}*/
// ------------------------------------------------------------------
// Radeon 7000 / 9000
#warning Upgrade NOTE: SubShader commented out; uses Unity 2.x style fixed function per-pixel lighting. Per-pixel lighting is not supported without shaders anymore.
/*SubShader {
Material {
Diffuse [_Color]
Emission [_PPLAmbient]
}
Lighting On
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "Always" /* Upgrade NOTE: changed from PixelOrNone to Always */}
Color [_PPLAmbient]
Lighting Off
SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
}
// Vertex lights
Pass {
Name "BASE"
Tags {"LightMode" = "Vertex"}
SetTexture [_MainTex] {Combine texture * primary DOUBLE, primary * texture}
}
// Pixel lights with 2 light textures
Pass {
Name "PPL"
Tags {
"LightMode" = "Pixel"
"LightTexCount" = "2"
}
ColorMask RGB
SetTexture [_LightTexture0] { combine previous * texture alpha, previous }
SetTexture [_LightTextureB0] { combine previous * texture alpha, previous }
SetTexture [_MainTex] {combine previous * texture DOUBLE}
}
// Pixel lights with 1 light texture
Pass {
Name "PPL"
Tags {
"LightMode" = "Pixel"
"LightTexCount" = "1"
}
ColorMask RGB
SetTexture [_LightTexture0] { combine previous * texture alpha, previous }
SetTexture [_MainTex] { combine previous * texture DOUBLE }
}
// Pixel lights with 0 light textures
Pass {
Name "PPL"
Tags {
"LightMode" = "Pixel"
"LightTexCount" = "0"
}
ColorMask RGB
SetTexture[_MainTex] { combine previous * texture DOUBLE }
}
}*/
}
Fallback "VertexLit", 2
}
