continuing for bigkahunas question-the multitexture stuff is almost but not quite working for me yet:
I need to use one UV map for the textures soo I can tile them and a second UV map for the alpha maps which separate cliff and grass. But wait it doesn’t end there, because I also need a self illuminating (or lightmap) channel which also uses the alpha UV map so I can add self light and shadows into the mix - lol, not asking much then. Is it right that I’m thinking all these things need to be in one shader to get what I’m after?
I noticed in the source of the lightmap shader there is this:
// Ambient pass
Pass {
Name "BASE"
Tags {"LightMode" = "PixelOrNone"}
Color [_PPLAmbient]
BindChannels {
Bind "Vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
Would it be relevant for me to think in terms of somehow trying to combine this with the multitexture stuff?
TIA for any help. On the plus side I wrote my first script today without asking anyone - ha, triggering lights to switch on and off yay
Boxy
Sorry to be persistent, I realise I’m trying to fly at supersonic speed before walking but I’m nearly there
I have used Pete’s mountain shader as a base and have just been experimenting while trying to follow the docs, but I am not understanding what blending method I need to use to make the base rock texture show through. I just know my error will show how spectacularly ignorant I am at writing shaders, but that’s because I (currently) am.
I’d really appreciate any help.
Thanks
Boxy
If I put Blend one one at the beginning of this pass it bleaches the whole effect out, which confuses me because i understand Blend one one to be a multiply whereas the effect is more like a Screen.
Thanks
Boxy
Well, in the slight chance that some other complete ‘cut paste and see what happens’ shade scripting virgin comes across this and is scratching their head, it was a lot simpler than I thought - more a matter of finding the right combination of blends for the masks in Photoshop rather than in code.
Thanks to everyone who helped and provided the code over the last couple of weeks, I can only apologise for being very slow at picking some things up!!
Edit: I have no idea if the code is as it should be but it seems to work as I wanted, so if I have put things in there which are unnecessary please do tell me, gotta learn somehow
Boxy
You may be talking to yourself, but a lot of people are listening (100 views of this one-man thread until now). And I bet that I’m not the only one who is impressed and excited about this new shader.
You might want to upload it to the Unify wiki, for a bit of fame and glory
hey sorry for letting you talk to yourself, boxy! barely been lurking lately. didn’t see the thread. glad you got it figured out and yes, it’s really the way you build masks in pshop/gimp. i used duplicate layer then invert quite a bit. another trick is to draw paths. you can fill/stroke them with black or white for your opposing layers and they’re easy to edit later. use a soft or hard brush depending on the texture transition you want. you can get some cool effects… turn off aliasing for a hard edge or blur one mask but not the other, paint spots at 80% black in the mask for your top texture to create variations like random oil stains on a road… lots of stuff to play with!
the one thing i haven’t gotten around to is playing with the fallback. i was planning to fall back to a 512 or 1024 single texture. i believe the diffuse fallback as it is will just be whatever color is your base color. not sure though and the shader in the mountain track showed fine on an inteligrated 82815 pc. so might not be a worry except for really super old machines.
is your code right? in the immortal words of nicholas… if it looks good, ship it!
[edit: and oh yeah… i was as giddy as a school girl when i got it working! ]
sorry i’m not boxy! but his is based on mine which is 100% based on richard’s work. lerp wasn’t working for me but combine texture * previous did. why? beats me! i was just fiddling til it worked… unity makes me happy!
Hey thanks David, too kind, but I can’t claim any glory for cutting and pasting and scratching my head It should go up on the Wiki as a variation though.
Pete, no problem, actually I’m glad because the things you figure out for yourself are the things you remember. The masking does have a huge lot of potential though, can’t wait to try and get it sorted but I do need to at least play with the idea of a ‘lightmap’ type channel first so I can add baked colour/shadows from C4D. I like texture as fallback idea to.
Bigkahuna - as Pete said, but I couldn’t get either of them working without a bit of tinkering, like changing the order of the passes and removing a ‘Blend one one’. I also have no idea why this should be but isn’t that great the about Unity, you still get results despite knowing nothing
I love this app
This is pretty much everything I wanted to do with the shader. The shadow layer multiply makes things a bit dark but I could adjust the textures I think.
Cheers
Boxy
Boxy,
This is the shader that I use - it is a bit of a hack but does the job for the moment. I did use one with more layers (and consequently more passes) but it killed my frame rate. Thus the one below works well for the “foreground” terrain (I use a much faster material for the distant terrain). I have no lighting on the terrain as I bake all of my lighting.
I would REALLY like to know how to get two more masked layers without adding any more passes.
Richard.
Shader "terrain/Three Tiled Textures with Shadowmap" {
Properties {
_Shadowmap ("Shadow map (RGB)", 2D) = "white"
_PathTex ("Path (RGB)", 2D) = "white"
_PathMask ("- Alpha Mask for Path Layer (A) ", 2D) = "white"
_HillsTex ("Hills (RGB)", 2D) = "white"
_HillsMask ("- Alpha Mask for hills Layer (A) ", 2D) = "white"
_BaseTex ("Base (RGB)", 2D) = "white"
}
SubShader {
Pass {
// Apply base texture
SetTexture [_BaseTex] { combine texture }
// Load in the alpha blending texture
SetTexture [_HillsMask] { combine previous, texture }
// Blend in top layer with base layer using the alpha
SetTexture [_HillsTex] { combine texture lerp (previous) previous }
SetTexture [_Shadowmap] { combine texture*previous }
} // end pass
Pass{ Blend SrcAlpha OneMinusSrcAlpha
// Load in the alpha blending texture
SetTexture [_PathMask] { combine previous, texture }
// Blend in top layer with base layer using the alpha
SetTexture [_PathTex] { combine texture lerp (previous) previous ,previous }
SetTexture [_Shadowmap] { combine texture*previous }
} //end pass
} // end subshader
FallBack " Diffuse", 1
} // end shader
Thanks Richard that looks interesting. When I try it I can only get the shadow map and Path channels to work, do you have a screenshot of what it should look like?
I was wandering whether you could use different blend functions that get blocked/not blocked by different masks in the same pass but I couldn’t get it to work and I don’t know enough to know whether that would solve your problem - but its a good point and the fact that the shader goes on a large terrain probably won’t help frame rates either.
Thanks for the help, please do let us know if you find a way. I would be interested to learn more about this.
Boxy
Boxy,
These shader masks work a little different to the previous version in that they are similar to Photoshop layer masks which I find much easier to use than the previous shader. I am away for the next few days so will post some examples when I get back.
cheers,
Richard.
Definitely starting to get somewhere with this shader, the grass is almost what I want, haven’t yet finished the alpha masks to allow the layer 2 mud patches to show through and the lightmap is a quicky just to test it but very cool.
Interestingly Richard, my game performance has shot up since adding this shader to the terrain, which is an even better surprise considering there are many more polygons in it than the last terrain. (I rebuilt the terrain from a square plane draped over the old one with C4D’s cloth tool to get an even grid UV map so the textures in the shader would not distort as much). It’ll be interesting to see if it also improves play on my TiBook 867mhz, which I consider will be a reasonable lowest common denominator by the time this actually ships as a game
Final post (hope its not a double post, I thought I’d submitted this!!)
A web player of the terrain shader with all three layers active. Its a terrain test so apologies for continued non development of everything else! There will be more tweaking but this works…
The performance shot up noticeably when I replaced the old realtime lit terrain with this self illuminating shader so though the baking process is longer its definitely worth it. Thanks for everyone’s help, now to add that awsome grass script those Unity genii just added
Thanks for sharing! I’ll have to give this a try to see what I can learn from it. This thread has been very helpful and has motivated me to try an write a shader of my own. What I’d like to create will have 2 bump mapped textures and a lightmap, I don’t think a shader has been posted like that yet.
Good one, thanks. Keep a thread of your progress too if you don’t mind, I’d be interested to see how bump mapping looks compared to detail shaders. I wondered if I should try a bump for the mud layer as it currently looks a bit flat, but my head is hurting too much from all the thinking, need a couple of earlier nights I think
Cheers
Boxy
I just want the ability to add another texture and layer mask on top of what’s already available, but I’m not having much luck. This is probably very simple to do but this is the first time I’ve tried to write a shader. Can anyone help?
One of the layers also has a detail texture (that’s how I did the grass because otherwise it always looked tiled no matter how I tried to disguise it), but you can just take that out if you don’t want it. Not sure if I did everything ideally (I’m not much of shader writer), but it works.