I want to realize some very basic normalmapping on iOS and have some strange problems.
The first thing is, that I would like to have the position of lets say four lights in worldspace. Or to make it even simpler just one light. So I read that there now is unity_LightPosition[4], I declared it in my shader and used it, but it doesn´t seem to be set, as it is always 0. Then I found _WorldSpaceLightPos0, which results in green, independant of the lights position → also not set. The last try was gl_LightSource[0].position.xyz, which results in blue, independant of the lights position :).
My scene has only one light and I defined Tags {“LightMode” = “Always”}, but also tried ForwardBase, which didn´t change anything.
I can of course pass the lights position myself, but WTF?
The next thing is that unity wants a texture to have the texture type normalmap, if I assign it to a sampler called _BumpMap. If I do this, sample it and output the color, all I see is the normalmap as greyscale image. No normals… I can of course use it as “Texture”, which then just works, but again WTF?
And the last problem just turned out to be more a general math and precision problem in combination with mipmaps in my shader, than something unity related :).
It would be great if someone could explain me the described behaviour and tell me what I am doing wrong, or if it just really doesn´t work correctly…
I’m in the process of writing a wikibook about GLSL shaders in Unity, have a look, you might find one or two answers: GLSL Programming/Unity - Wikibooks, open books for an open world (note that this is work in progress, currently I’m testing only on Windows; neither on MacOS X nor iOS; let me know if the code doesn’t work for you).
Well, I don´t want to render lights in several passes, as that is a really bad idea on iOS.
However, nice work on that wiki book :). Reminds me on the really good book “Shaders for Game Programmers and Artists” which is probably still the best book to get started on shaders with…
Thanks for the book recommendation, I’ll have a look.
As far as I know, if you use the Forward Rendering path, four “vertex lights” are provided in the ForwardBase pass (in addition to the main directional light as described in the wikibook) with the following uniforms (at least in OpenGL on Windows, I’m not sure whether the same names are available in a shader for iOS):
You should compile one of the built-in shaders (e.g. the “Decal” shader) to see how they are used (and which uniforms are used for OpenGL ES). However, I’m not sure whether any directional lights or spot lights are ever specified this way. And I don’t think you have access to cookies for these lights.