- Home /
Lighting and lightmapping - OpenGL ES 1.1?
Hi, I'd like to get some advice regarding multiple platform support.
I'm targeting iPhone 3G and up (I'm also building for Android, but let's stick to iOS for the moment).
In my game I use a realtime vertex point light, which illuminates my level geometry. It's the only realtime light in the game.
If I lightmap my levels using Beast it seems I can only get the point light to work if it is set to a pixel light (rendering set to 'important'). This doesn't work on older 3G devices and anyway pixel light is too slow for my purposes - I only need a vertex point light. It seems 2.0 can't handle this so I am targeting ES1.1.
However it seems it's not possible to have a vertex point light illuminating a Beast lightmapped object in ES1.1 - only a non-beast lightmapped object shows the lighting effect.
Is there a solution that would work for 3G and up that provides?
1 vertex point light Beast Lightmapped level, with mobile/vertex lit shader
and 2.0 seem too different to have a "one size fits all solution" (assuming I want the gfx to look the same on each device). Could I script material / light property changes depending on the device?
Novice with shaders and this field of Unity is not my strong point... any help would be great!
Try using "primary" in the VertexL$$anonymous$$ pass, and please let us know if it works. You'll have to make use of the $$anonymous$$aterial block, of course. Let me know if you don't know how to work with all that. http://unity3d.com/support/documentation/Components/SL-PassTags.html http://unity3d.com/support/documentation/Components/SL-SetTexture.html
Thanks Jessy, I will attempt to write a shader or modify the vertex lit one... stumbling through with this as I haven't touched shaders before really...
Answer by Jessy · Aug 14, 2011 at 02:40 PM
This will work for OpenGL ES 1.1 and 2.0, but you won't get optimal performance in 2.0 without a GLSL shader. Make sure you only bake the lights that can be baked. Also, name it; forward slashes create folders.
Shader "Give this a name you like" {
Properties {
_Color ("Color", Color) = (1,1,1)
_MainTex ("Base", 2D) = "white"
}
SubShader {
Lighting On Material {Diffuse[_Color]}
BindChannels {
Bind "vertex", vertex
Bind "normal", normal
}
Pass {
Tags {"LightMode"="Vertex"}
Material {Ambient[_Color]}
BindChannels {Bind "texcoord", texcoord}
SetTexture[_MainTex] {Combine primary * texture Double}
}
Pass {
Tags {"LightMode"="VertexLM"}
BindChannels {
Bind "texcoord1", texcoord0
Bind "texcoord", texcoord1
}
SetTexture[unity_Lightmap] {Matrix[unity_LightmapMatrix] Combine primary + texture}
SetTexture[_MainTex] {Combine previous * texture Double}
}
}
}
Answer by Recluse · Aug 18, 2011 at 03:00 PM
Thanks Jessy. I will try that shader out.
In the meantime, after following your tutorials and through a process of trial and error I ended up with this shader, which blends two textures (one can be a base texture and the other a lightmapped texture) and also uses vertex lighting. It works well on my iPhone 3G and on my iPhone4. I also managed to cobble together a version which blends in vertex colors as well - however I was unable to get that to work in a single pass. So I am using this currently:
Shader "Mobile/Blend 2 Textures, 1Pass, Lit"
{
Properties
{
_Color ("Color", Color) = (1,1,1)
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
Category
{
Lighting On
Fog { Mode Global }
Material
{
Ambient[_Color]
Diffuse[_Color]
}
SubShader
{
Pass
{
BindChannels
{
Bind "Vertex", vertex
Bind "Color", color
Bind "texcoord", texcoord0
Bind "texcoord1", texcoord1
}
SetTexture[_MainTex]
{
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
SetTexture[_Texture2]
{
Combine texture * previous DOUBLE
}
}
}
} } code here
Your example works with Beast, which is perfect. If I use a beast lightmap with my attempt, it displays correctly in the editor, but not on the device... using a lightmap rendered in Blender works fine with my version though. I wonder why? I'm sticking with yours anyway, many thanks!
$$anonymous$$aybe Unity doesn't allow you to use the "unity_Lightmap" texture directly, on the device. I don't know why they'd let it be emulated, though.
Answer by shinja · Nov 25, 2011 at 09:03 AM
Hi Jessy on the shader that you wrote above was looking for a version with alpha and alpha cutout in it I tried programming it but as usual i am not good at this kind of stuff :(
Your answer
Follow this Question
Related Questions
Vertex colour transparency and Beast lightmapping? 3 Answers
Mobile BEAST lightmapping shader/lighting question 0 Answers
How to calculate light from behind a quad? (and other light positions) 1 Answer
Transparent Vertex Shader Error 1 Answer
Beast Lightmapped object can't be lit by realtime lights? 1 Answer