Environment mapping on the iPhone

I’ve been experimenting with spherical/cubic environment mapping on the iPhone. As far as I can tell:

  • TexGen SphereMap is supported
  • UV transform matrix in SetTexture is not supported (BTW why isn’t this documented?)
  • TexGen CubeNormal is not supported

Can someone from Unity please confirm this? Is there any way to get uv transform working?

My current shader is as follows (alternate between SetTexture [_SphereTex] and SetTexture [_CubeTex]):

Shader "BlobShader" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_Tex1 ("Tex1", 2D) = "white" { }
		_SphereTex ("Reflection (Sphere Map)", 2D) = "white" { TexGen SphereMap}
		_CubeTex ("Reflection (Cube Map)", Cube) = "white" { TexGen CubeNormal}
	}
	SubShader {
		Pass {
			SetTexture [_Tex1] {
				constantColor [_Color]
				combine texture lerp(texture) constant
			}
 			SetTexture [_SphereTex] {
				constantColor (1,1,1,1)
				combine texture + previous Matrix [_ReflectionMatrix]
			}
		}
	} 
}
  • Spherical mapping is supported (TexGen SphereMap)
  • UV transform matrix should work on iPhone. If you have a case where it doesn’t, please submit as a bug.
  • Cube mapping is not supported by iPhone hardware.
  1. The “nature” of spherical mapping is limited to single fixed camera direction. That is a limitation comparing with cube-maps. You don’t need any additional UV transformation matrix to get spherical mapping. Just use SphereMap TexGen and that’s it.

  2. Just for clarity - in case of cube-maps, shouldn’t _ReflectionMatrix be actually _Reflection?

Thanks for clearing that up! :smile:

  1. I wasn’t aware of that. But now that I think about it it’s pretty obvious. :sweat_smile: However, what I’m trying to do is a very specific effect for a quasi 2d game, and thankfully I found a better way do do it using only a texture transform matrix.

  2. No, “_ReflectionMatrix” is just the name I use to set the transform matrix from my code (someMaterial.SetMatrix(“_ReflectionMatrix”, someMatrix)). May be confusingly named though.

As for the bug where texture transform doesn’t work on the iPhone, the above shader will reproduce it. Seeing as I’m skipping all the spheremap stuff, I rewrote the shader from scratch, after which I don’t get that bug anymore. It might be that texgen spheremap + uv transform doesn’t work because Unity figures “hmm, that doesn’t make sense”… Though even in light of what you said about spherical env mapping, you might still conceivably want to transform the uvs in order to make a wobbly displacement of your reflection for instance.

Not on a fixed function hardware.
spheremaps can not be transformed, they don’t care about UVs