Anyone seen a 3xlayer shader+Lightmap?

Hi there,

I was pretty sure I had seen a shader that could tile three textures together and also have a lightmap. I cant seem to find it though. Maybe I was thinking of Jessys 2xLayer shader plus Lightmap shader, but if any one knows of a three layer one, or if the concepts impossible (for iPhone) and I’m imagining things then please advise?

Thanks
Aaron

This thread might help:
http://forum.unity3d.com/viewtopic.php?t=2959&postdays=0&postorder=asc&highlight=layer&start=0

If you need to use texture masks to blend, I don’t think it’s possible to do better than this. It’s an extension of this other thing I think you were referring to. If you can use vertex color alpha to blend in one of the textures, then we can eliminate a pass on the old GPUs. (As it is, this shader runs in one pass on the 3GS+ and three on the old stuff.) Is that a possibility or not? Also, I assume you are using two UV sets, but we can also make this more efficient if you’re only using one, or if the 2nd UV set is nothing but a scaled version of the first. What is the situation with that?

Here are the instructions to test this out as-is:
Use RGB textures for “Texture 2” and “Texture 3”. (PVRTC 2 bpp if it’s not too ugly.)
The lightmap contains a mask to blend between “Texture 2” and “Texture 3”. (I figure the lightmap is higher resolution than Textures 2 and 3, and if so it’s a better place for a mask.)
“Texture 1”'s alpha channel is a mask to blend between it and the result of the Texture 2-3 blend. That is to say, if you were painting masks in Photoshop, this would be the top layer. Make this the texture that you want to look the best, because you may need to use PVRTC 4 bpp compression on it, as 2 bpp masks are crummy (though it might not matter in this case – definitely use 2 bpp if it’ll do), and you’ll probably want a higher resolution for the mask.

EDIT: Hold on, I screwed up the Texture 1 blend on the old cards. (I forgot to actually test with something with two different UV maps and I was tired.) Fixing.

345671–12058–$blend_3_lightmapped_textures_213.shader (1.91 KB)

Meh. I wasn’t able to come up with any trickery to make this shader work in less than four passes on the old cards. (It’s unchanged, and works in 1, on the later cards.) The instructions remain unchanged. Please do answer the questions from the first paragraph, though.

346191–12070–$blend_3_lightmapped_textures_141.shader (1.49 KB)

@Jessy - Haven’t tried your shader yet, but wouldn’t it be better / easier to set it up like this:

texture 1 - RGB
texture 2 - RGB
texture 3 - RBG
blend - RGB (each color component = a blend alpha map)
lightmap - Alpha

versus yours:

texture 1 - RGB
blend - Alpha
texture 2 - RGB
texture 3 - RGB
lightmap - RGB
blend 2 - Alpha

Or did I miss something? I’m still a noob at shaders so I may be completely wrong on this…

Unfortunately, there’s no way to extract RGB channels for alpha blending in the fixed function pipeline.

However, if the lightmap can be greyscale, as you suggested, then you’d only need three textures for this shader, not four. Won’t eliminate any passes, but it will save on texture memory. You want a modified shader that uses a greyscale lightmap, Aaron?

Edit: Here it is regardless.

346239–12073–$blend_3_grey_lightmapped_textures_446.shader (1.57 KB)

Hey thanks Jessy these are both a couple of cool handy shaders.

I was asking because the artist on the team asked me, and then he didn’t have the motivation/budget to test them in the end, hence the delay in responding, but I just did a test today and they will definitely be handy in future.

Thanks for going to the trouble of posting these!

Cheers
Aaron

Thanks Jessy that last one was perfect!
Aaron

Hey Really usefull, and i want to ask, is there any chance to change this shader to add a Spec and normal map channel? i need it to use it in unity 3.0 free because the legacy shaders/lightmapped Bumped/Spec do not work any more like in 2.6, im really new to shaders scripting and i really need help.

thanks!!