EDIT:
The depth based color can be done by doing multipling the vertex position by model view matrix UNITY_MATRIX_MV and grabbing the z value which is equal to the depth. Or even better grab the built in shaders pack and find the Camera-Depth****.shader and hack that. Then you can just return lerp(black, color you want, IN.depth * some value);
Fog is a bit slow on mobile platforms but it would be independent of what material and shader you use as long as the shader doesn’t exclude it by tags. You have to consider that if you use a shader you have to make variations for every type of material like transparent and transparent cutout, bumped etc. unless you do this as a post effect.
Rim lighting and SSS are a bit different. You can simulate SSS cheaply by creating a custom color ramp. Normal lighting calculations do a max(0, dot(surface normal, light)) to calculate the brightness. But you can create a texture that goes from flesh color to red (skin) and then do something like
float ndot = max(0, dot(surface normal, light direction));
return tex2D(_SkinColorRamp, ndot);
so _SkinColoRamp would be the texture simulating the SSS.
Also half-lambert shading is gives a much better SSS effect. Just search for it on the forums. Valve uses it on their characters.
Rim lighting is pretty easy to do it’s just taking the dot(view direction, surface normal) and that will give you the “angle” the surface is to what you are looking at. Then you simply add that like a specular value or lerp(col, rim color, rimval);
You don’t need to do the whole thing. dot(UNITY_MATRIX_MV[2], positionInObjectSpace) is all that matters. Whether that actually saves instructions is dependent on hardware and precision.
No point in the max. Just clamp the texture.
Thanks for that Jessy. Actually that brings up a question you can maybe answer for me. My matrix maths is a bit weak.
When I use dot(UNITY_MATRIX_MV[2], normal) for a fresnel effect it works in orthographic but not in perspective cameras. I have to use dot(ObjSpaceViewDir(v.vertex), normal) for perspective. Do you know how to fix this?
That doesn’t make sense to me; MV shouldn’t change based on camera type. If you want to upload a package, I’ll take a look at it.
I really thank you for your answers, but, none of them where usefull to me.
Anyway, I think I’ll stick with the fog value in the rendering settings until I can figure it out a better way of doing it.
Again, thank you very much for your help. I’m sure that it will be usefull at some point.
You thought right; hopefully you can either come to that same belief, or find someone to work with who can. Good luck.
http://www.snopes.com/business/genius/where.asp
Yeah, I knew the joke, it’s a good one and a very realistic one. Fortunately, times have changed and there’s some ppl willing to share his knowledge. Like this this guys here or this one. Mostly copy-paste stuff here and the work is done ![]()
As for the SSS one, I’ve got it at the asset store. for 10 bucks and the deph was solved with the fog shaders and a little bit of lightmapping and smart texturing ![]()
Anyway, like I said, thanks anyway!!
I leave the links just in case someone finds them useful,