Unlit Lightmap Shader - needs a check

I wasn’t pleased with the build in lightmap shaders, as they still seem to also accept vertex lighting from within unity? Since I am after maximum perfomance, and also don’t use a single unity light, I wrote a new lightmap shader that doesn’t accept those lights.

Now, I am utterly utterly bad at this. Really. I am an artist and I am having a hard time writing these shaders. I did succeed in the end, after hours of messing, and it works exactly like I want it to work, however, I may have done somethings wrong or in a slow way so it would be nice if someone could give it a look and see if it could be speed up further?

I am really after maximum perfomance. However the looks it gives now has to be preserved. I currently added the lightmap onto the texture twice (I think…) which is the intention, with just 1 pass it looked very dull. So I added it again to make it brighter and cooler. I believe I used two passes for this plus a third pass to add the actual texture? This may be rather slow on old hardware?

Thanks!

Shader "Lightmapped/Diffuse2" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_Color2 ("LM Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_LightMap ("Lightmap (RGB)", 2D) = "lightmap" { LightmapMode }
}

SubShader {
	LOD 300
	Tags { "RenderType"="Opaque" }
	Blend AppSrcAdd AppDstAdd
	Fog { Color [_AddFog] }

	// Base pass: lightmap
	Pass {
		Name "BASE"
		Tags {"LightMode" = "Always"}
		BindChannels {
			Bind "Vertex", vertex
			Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
		}
		SetTexture [_LightMap] { constantColor [_Color] combine texture * constant }
	}
	
		// Base pass: lightmap
	Pass {
		Name "BASE"
		Tags {"LightMode" = "Always"}
		BindChannels {
			Bind "Vertex", vertex
			Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
		}
		SetTexture [_LightMap] { constantColor [_Color2] combine texture * constant }
	}
	

	
	// Second pass: modulate with texture
	Pass {
		Name "BASE"
		Tags {"LightMode" = "Always"}
		BindChannels {
			Bind "Vertex", vertex
			Bind "texcoord", texcoord0 // main uses 1st uv
		}
		Blend Zero SrcColor
		SetTexture [_MainTex] { combine texture }

	}
}

Fallback "VertexLit", 1

}

Without any lights, the default Lightmapped/Diffuse shader requires one draw call. I encourage you to experiment with shaders, but the fastest and most artist friendly way to deal with this issue is to put your lightmapped geometry on a separate layer and use Culling Masks to make sure any lights in the scene do not affect them:

I tried to mass replace mine with the default one but perfomance was identical pretty much. The default one is also really dark and dull. The lightmaps really don’t lit up the environment like a lightmap should.

If you want to optimize it further - don’t use a lightmap shader :slight_smile:

Just bake everything (including shadows) into a single texture
in your 3d app or combine it in photoshop any way you like,
then use a self-illuminating/unlit shader.

lightmaps dont light the enviroment up, a lightmap is a how much an object is lit, with no lights, anything that also lights up enviroment is done manually with lights

Extremely impressive portfolio Hourences :wink: By pure coincidence I saw one of your environments in this Gamasutra article earlier today:

Here’s a link to an earlier discussion about a better lightmap shader:

http://forum.unity3d.com/viewtopic.php?t=24070

Thanks a lot Antenna :slight_smile:

I will see how the other one works and how it looks. Will also just mess some more with mine or perhaps try a combination between the two or something.

Loor, certainly, but it just reduces the texture quality a bit too much for my liking. Too much of a sacrifice.

G3David, lightmaps are suppose to lit up the environment. That is their whole point and how it is done in many games. It is also way better for performance like that, and your own workflow.