Hi all,
To make sure we’re as optimized as possible, we’ve put together all of our own shaders for the iPhone. Sometimes the layers of fallback shaders make it hard to know if you’re getting the most efficient shader for the iPhone. These are cobbled together from various samples, so I didn’t create them from scratch.
One is a simple diffuse texture for unlit characters with baked lighting in their diffuse texture that supports alpha testing. The other is a lightmap shader.
I’m struggling to write a shader for our lightmapped objects that require alpha testing or alpha blending. The lightmap alpha testing shader would be a combination of these two shaders below. Any help would be appreciated.
Otherwise, I’ve seen requests for these two shaders elsewhere. Enjoy.
Here is our simple “no lighting” diffuse texture shader that supports alpha testing (cutout).
Shader "Unlit Diffuse Alpha" {
Properties {
_Color ("Color Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Cull Off
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="TransparentCutoff"}
Pass {
Alphatest Greater [_Cutoff]
AlphaToMask True
ColorMask RGB
SetTexture [_MainTex] {
Combine texture, texture
}
}
}
}
And here is our simple lightmap diffuse shader that we use for lightmaping our scenes. This is a two pass shader that multiplies the lightmap texture with the color constant and the diffuse text.
Shader "Unlit Lightmap Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white"
_LightMap ("Lightmap (RGB)", 2D) = "white"
}
SubShader {
Cull Back
// Base pass: lightmap
Pass {
Name "LIGHTMAP"
Tags {"LightMode" = "Always"}
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
}
SetTexture [_LightMap] { constantColor [_Color] combine texture * constant DOUBLE }
}
// Second pass: modulate with texture
Pass {
Name "BASE"
Tags {"LightMode" = "Always"}
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord0 // main uses 1st uv
}
Blend Zero SrcColor
SetTexture [_MainTex] { combine texture }
}
}
}
Thanks,
Matthew Scott
Manifest Games