I need some of these elements to fade in or out. Is there any way to adjust this shader so that the texture value is multiplied by the object’s distance from camera.
I would usually just use SetColor of the material, but I want the elements to batch.
Try checking out the shaders of PuzzleBloom at http://robert.cupisz.eu/.
It’s a great example of shaders that do what you want. They have a part where the blooming part starts from one point in the scene and goes out based on the distance from that point.
They are for the “regular” Unity editor and not the iPhone version, but it should work.
I think…
If these elements are 2D, SpriteManager 2 yields this functionality (ability to set the color/alpha arbitrarily) without breaking batching. You can find out more here: http://www.anbsoft.com/middleware/sm2
Apart from that, I’m not sure it is possible to do this using a shader on iPhone as the iPhone only has a fixed function pipeline. Then again, I’m not a shader expert, so perhaps it can be done using fixed function?
I am not sure how this can be made but there is a builtin var inside shaderlab: _ObjectSpaceCameraPos
which is the Camera’s position in object space
that you can access inside your shader, so I would somehow get the distance from that vector and use it for whatever you like…
I know that to get the magnitude of a vector you need to get the sqaure root of xx+yy+z*z but I don’t know how you can do it inside an iPhone shader.
I would only need the z component of _ObjectSpaceCameraPos and multiply the texture values by that so no need for calculations. I just have no idea how this could be applied to this shader.
I was planning on getting Sprite Manager 2 for my next game when its released, but for this game the interface is almost done, I just wanted some stuff to fade in and out.