I’m working on my first iPhone project (first Unity project as well, love it so far), and I’m running into a little shader issue. I have the following shader, which purpose is to have a colored object, with a lightmap/occlusion texture, and a reflected environment. But it seems I can’t have a combine lerp instruction on each texture stage (to keep my shader in one pass). It works and displays correctly in Unity, even with iPhone graphic emulation, but not on my 2G iPhone (it looks like the second texture stage is not processed)… Any ideas ? Is it because my phone is old ?
// SIMPLE COLOR SHADER
// occlusion means lightmap for me :-)
Shader "ColorOcclusionReflection_1P"
{
Properties
{
_BaseColor ("Base Color", Color) = (1,0,0,1)
_OcclColor ("Occl Color", Color) = (0,0,0,1)
_OcclMap ("Occlusion Map (RGB)", 2D) = "white" {}
_EnvMap ("Environment Map (RGB)", 2D) = "black" { TexGen SphereMap }
_ReflValue ("Reflection intensity", Range(0, 1)) = 0.5
}
SubShader
{
Pass
{
Name "COLOR"
Color [_BaseColor]
ZWrite On
Blend Off
Lighting Off
BindChannels {
Bind "vertex", vertex
Bind "normal", normal
Bind "texcoord", texcoord0
Bind "texcoord1", texcoord1
}
SetTexture [_EnvMap] {
constantColor (0, 0, 0, [_ReflValue])
combine texture lerp(constant) previous
}
SetTexture [_OcclMap] {
// bugged on iphone 2G ? so no occlColor, or 2 passes...
constantColor [_OcclColor]
combine previous lerp(texture) constant DOUBLE
// this is my workaround, but I loose the occlusion color
combine texture * previous DOUBLE
}
}
}
}
…so a lerp combine counts for 2 operations ? I think I don’t really get what a texture op is in regard to the SetTexture instructions…
I have two textures used, on two SetTexture instruction groups, but using lerp in both adds more operations ? Is that correct ? Thanks for the enlightening
No. You have two texture stages to work with on your device. Those stages can use any of the two-operator calculations, or lerp. The other three-operator ones are not supported.
I tried to improve the shader but I can’t tell what you’re trying to do. All I can tell you is that you don’t need to bind normals if you’re not using lighting. Might as well not import them, therefore.
what I think is the problem here is the use of the constant colors (there should be a thread on that already that it will disallow it to work on 3G if you use a different color on each step)
Cause they must be represented somehow in the pipeline and the options are only vertex color and constant color textures.
neither of the two would allow this shader to run in a single pass, as you either need more than 2 textures for the blending or more than 1 mesh
@Jessy : thanks for taking the time. My goal is to have a reflective lightmapped shader, where you can set a base color and a lightmap color (to fake colored radiosity). I use no lights in my scene, everything is baked in this lightmap. I thought that as I only need 2 textures (the lighmap itself and the reflection map/environment) I could handle all this in a single pass…
But it looks as it’s not possible because as dreamora said there are limitations also in the use of constant colors… I can get away without coloring my lightmap so it’s not a very big deal ; I just didn’t get why it could not work, I thought I was still within limitations of the 2 texture stages.