I can’t really find a way to make the mobile vertexlit shader works with lightmaps.
What i need is simple, mobileVertexlit + lightmap (simultaneously).
I got a bunch of tiny (or sub-divided) meshes that doesn’t really need any pixel light, they can do fine with vertex. So i’ve decided to mod the build-in mobile vertexlit, but without any success. If anyone can point me to the right direction, will be really appreciated.
Take a look at a pre-compiled surface shader by adding #pragma debug to the top of the CGPROGRAM block. Then click “Open compiled shader” in the inspector. In the comments, you will see the generated passes and how everything is implemented, including lightmaps.
Tanks Daniel,
I’ll give it a try.
I can’t get a good view of this code on my iPhone, but this stuff I offered might be helpful.
Tanks Jessy.
Where i can find the sources for LightModes in VertexLit renderpath? I need to create a new lightMode. I really badly need VertexLit and lightmaps. I’ve debugged the desktop VertexLit but it is no funny browsing 2000 lines of codes of compiled shader in asm.
Could you guys add an other pass for VertexLit rendering path? Kind of VertexLML (which stands for LightMapped and Lit). VertexLM and VertexLMRGBM doesn’t apply any real-time lighting.
I’m completely stuck and i need it badly.
I’m not sure what you mean by that. Googling “unity3d lightmode” has been helpful to me. I don’t remember where I learned the term - probably just from reading through the ShaderLab docs.
It’s a pass tag for the rendering path.
I know this. Your last response didn’t come through as I was writing mine. Non-baked Vertex lights are still active even in VertexLightmapLM or VertexLightmapRGBM. Where does your problem lie?
Oh, my bad then. ^^
Well, once i lightmap my meshes i still need to lit them dynamically (with VertexLights).
I still don’t understand where your problem lies; here’s a shader that shows that all the rendering paths you need are already there. It’s easiest to view if you set the rendering path to Forward (and that will get you better performance if you use GLSL instead of fixed function shaders). Then you can switch between graphics emulation; the first SubShader will just add the color of the brightest directional light to the lightmap, and the second will add full vertex lighting to the lightmap.
Shader "" {
// OpenGL ES 2.0
SubShader {Pass {
Tags {"LightMode"="ForwardBase"}
GLSLPROGRAM
varying mediump vec2 lightmapUV;
#ifdef VERTEX
uniform mediump mat4 unity_LightmapMatrix;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
lightmapUV = vec2(unity_LightmapMatrix[0].x, unity_LightmapMatrix[1].y) * gl_MultiTexCoord1.xy
+ unity_LightmapMatrix[3].xy;
}
#endif
#ifdef FRAGMENT
uniform lowp sampler2D unity_Lightmap;
uniform lowp vec4 _LightColor0;
void main() {
gl_FragColor = texture2D(unity_Lightmap, lightmapUV) + _LightColor0;
}
#endif
ENDGLSL
}}
// OpenGL ES 1.1
SubShader {Pass {
Tags {"LightMode"="VertexLM"}
BindChannels {
Bind "vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0
}
Lighting On Material {Diffuse (1,1,1)}
SetTexture[unity_Lightmap] {
Matrix[unity_LightmapMatrix]
Combine texture + primary
}
}}
}
Awesome Jessy,
Gonna try that and post some results later.
PS: I wasn’t aware of forwardbase lightmode, complettly missed that. Just what i need.
Cheers,
Simply, when i bake lights, vertexLit surfaces doesn’t get lit by dynamic lights anymore. They only shows diffuse and lightmap.
I’ve tryed to mod the template you’ve provided but again, no succes.
Upload a package; I’ll try to tell you what’s not set up appropriately in it.
I’m going to create a test scene for you as I was using my current project (which i can’t upload).
@Jessy,
Tanks for your interest in helping me out with my issue. I’ve ended up paying someone to fix my garbage. I wast really spending too much time on this (had to move on mind you).
Tankyou anyway for your tips/hints.
Ok I’m looking for the same exact thing here. I am using Legacy Vertex Lit Rending Path in Unity 5. I am using the Mobile/VertexLit shader. I bake lightmaps and I want a dynamic light to affect the surface. The Dynamic light has no effect because the surface has baked lighting information (detailed shadows). When I remove the lightmap, dynamic lights now work again, but the detailed shadows are gone.
Is there a shader / solution to allow these Vertex Lit baked surfaces to still respond to dynamic lights?
Looking to hire a shader expert for this: https://www.upwork.com/jobs/~011d067dac4bd00d0a