Hi,
Is it possible to have a shader that is completely transparent, while still showing a normal map? Doesn’t seem to work with the built-in ones.
NOTE: I asked about this yesterday in the Support forum - sorry, just realized it was the wrong place to ask, so it can be deleted…
It might help if you draw a picture. “Completely transparent” means invisible, and is probably not what you want. Bump maps are usually only visible when they reflect light, although it doesn’t have to be diffuse reflection.
Thanks for the reply!
I should have been more clear with the question. Here’s what I (accidentally) wrote in the support forum:
“…I’d like to do something similar as the leak-patterns in the sewer example, except with normals rather than diffuse texture. I thought it would be as simple as having a completely transparent diffuse texture and just a normal map, but apparently that makes the normal map invisible as well…”
So my goal here is to use simple geometry like a plane on top of some other geometry in order to make it look damaged in the same way the planes in the sewer example make the wall look dirty.
But indeed, as you say a completely transparent diffuse texture will make the object invisible all together - so I guess it cannot be done this way? Are there any other approaches for this?
I haven’t seen the sewer example, but it sounds like that effect might’ve been achieved better with a material that accepts two diffuse textures instead of using layered planes, although it sounds like it works out okay for them.
The absolute simplest way to do this would be to just combine your “damage” normal map with the base wall normal map in photoshop and apply this to the walls that you want to look like damaged in-game.
Next simplest way, assuming you don’t get this to work with layered planes, would be a material that (optionally) accepts two normal and diffuse maps and combines them. You’d have your base normal and diffuse map for regular surface detail (bricks on a wall) and a noisy/damage diffuse and normal map to add the layer of detail. They’d be combined in the shader and the end result would be a wall that retained the brick (or whatever) normals while adding a layer of crap over the top.
You could try the node-based shader editor and see if that lets you prototype some ideas quicker than writing shaders manually, but I’ve yet to try it. It looks a lot like the material editor in the Unreal Engine 3, and achieving what you want here in that material/shader editor would be very straightforward indeed.
Thanks,
The sewer example is here.
What I’m trying to achieve with this, is an efficient way to make “unique” models. For example walls with seemingly unique damage, although they would all be instances of the same model. The transparent damage-decals (the planes) would make the look unique, without the need of actually having separate normal maps for every instance.
Well, no, having planes in front of walls with transparency and multiplied diffuse/normal textures won’t really be any more efficient than the way I described (doing it in the shader) and will potentially lead to confusing geometry and z-fighting. If you want more variation, just change the offset or tiling of the dirt detail materials on a per-wall basis or use world UVs or something, you don’t need hundreds of normal maps. The only way you’re going to get walls that actually looked damaged (instead of just lumpy or dirty) is to model the damage into them and create a set of maybe 10 re-usable walls. Bonus points for making them square and double-sided, as this will give you huge amounts of variations from flipping and rotating the prefabs.
If you want decals, use decals (there are free implementations of this on the forum and a Decal material in Unity that supports an alpha map), and if you want to use planes like this sewer demo then just modify whatever shader they’re using in the sewer demo to support a normal map. You could maybe even use the Projector if you wanted, but I’ve not tried that. I’m not sure how your normal map is supposed to work without a diffuse map (or something) to apply itself to. You want to blend your detail normal map with the surface’s normal map.
The most(?) efficient way to achieve what you want would be to use vertex colours to mask/reveal a secondary dirt layer on the model, so you could essentially paint this dirt layer onto the wall in as many variations as your geometry would allow.
You just pushed me into a still-continuing trip to learn the surface shaders and writing…err, wiring my own. So thanks, I guess 
What’s the correct way of masking a normal map?
I though this would work, but it doesn’t quite give the results I would expect:
// use black and white mask to hide parts of the normal map
float4 myMaskedNormal = lerp (UnmaskedNormal, float4(0.5,0.5,1,1), float4( Mask.a));
Any tips?
I’m still not entirely sure what’s going on here, but are you sure you can’t just leave those parts of the normal map “flat”, so that they don’t have any effect on the lighting when rendered or blended with the base map? I’m unsure why you’d need transparency, or what approach you’ve decided to take here.
Well, I pretty much tried to follow your idea:
“Next simplest way, assuming you don’t get this to work with layered planes, would be a material that (optionally) accepts two normal and diffuse maps and combines them. You’d have your base normal and diffuse map for regular surface detail (bricks on a wall) and a noisy/damage diffuse and normal map to add the layer of detail. They’d be combined in the shader and the end result would be a wall that retained the brick (or whatever) normals while adding a layer of crap over the top.”
But even simpler for now. I just gave the shader 2 normal map and a separate mask input. One of the normal maps is meant to be the overall, allways visible map and the other is the “damage map”, which would be controlled by the mask to show and hide different parts on different walls - isn’t this (roughly) what you suggested?
I think I was able to combine the 2 normal maps correctly using add and normalize, at least the effect made sense when I tried with the same map on both inputs (stronger depth), but it’s that masking part for the damage map that I haven’t got to work yet.
At first I tried to just multiply the damage map by the alpha of the mask, but then I realized the masked parts need to be 128,128,255 and not zero, so I found lerp but am I using it wrong?
Hmm, is there a special function for normalizing normal maps?
I think I finally figured out what is the problem - I put my combined map as the albedo and it looks ugly - way too deep blues in parts of it, while the background seems to be the correct 128,128,255 - so I’m guessing the simple interpolation and normalizing code doesn’t quite cut it for normal maps, as it does for diffuse textures - right?
Do you mean something like distorted refraction?
@AcidArrow, I’m afraid I’m too n00b to even know what that means…
@xomg, Thanks! I need to dig into that.
Just out of curiosity - how does Unity map the blue channel in normal maps? I found this and thought it might be related to my normalizing problem.
From the site:
“Since normals all point towards a viewer, negative Z-values are not stored (they would be invisible anyway). In Blender we store a full blue range, although some other implementations also map blue colors (128-255) to (0.0 - 1.0). The latter convention is used in “Doom 3” for example.”