How would I go about making a transparent versoin of the non-reflective/refractive water that comes with Unity indie? I've been using unity for a few months now and I'm sill desperately lost when it comes to shaders. I'm trying to use the fresnel effect in the water shader to conrol alpha as well as color, and I can't figure out how. Has anyone else tried this?
Here's the modified Non-reflective water shader from Unity 1.5, made to be transparent based on fresnel. Just add this to project and select new shader in water material. The changes were: added Code (csharp): Tags { "Queue" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha ColorMask RGB at start of each SubShader; this puts water into Transparent objects rendering queue, sets up standard blending and sets it to not modify alpha (just in case you'll want glow...). Then I set both fragment program and R9000 subshaders to output fresnel into alpha: Code (csharp): col.a = water.a; at end of fragment program and Code (csharp): MOV r0.a, r2.a; at end of R9000 fragment assembly shader
What is the correct way to modify the fresnel influence? Let's say I want the surface to maintain some level of opacity regardless of the angle relative to the camera? I've modified it by multiplying the water.a (col.a=water.a*2 for example), which works but I am fairly certain it is a dirty and dangerous practice. I will read up on the shaders ASAP, but in the meantime I would be very thankful for some hints. TIA! Daniel
You can just do something like Code (csharp): col.a = 0.5; Or better yet, expose it as a color property that can be tweaked. Otherwise, the fresnel is read from the Color/fresnel texture; if you want alpha to be different from fresnel maybe it makes sense to expose a new texture that just controls alpha.
Your original idea is exactly what I would do. Except - I wouldn't multiply by 2, but instead modify the lookup textures. If you think about it: The color gradients used in the value are used for exactly that purpose; to change appearance depending on viewer angle-of-incidence. Since you're talking about the indie water, there are no reflections to be affected by the gradient alphs - knock yourself out and make a nice gradient for your transparent. And besides; With shaders, if it looks good, ship it!
Many thanks! Will look into how to expose properties to enable me to tweak a gradient for the alpha. Will definitely post the shader and source stuff if I make something spectacular. Thanks again!
I know this is sorta gravedigging, but how would you go about changing the amount of alpha on this shader? Sorry, I'm terrible with that ShaderLab language. >.< Thanks!
You don't need to touch the shader. The alpha is controlled by the "oceangradient" image's alpha channel, which you can easily alter in Photoshop. One idea I've been toying with is inverting the alpha and using a upside-down duplicate of the scene for limited reflection effects.
>>I know this is sorta gravedigging not at all! this is a great water shader for indie. i didn't look should be in the standard assets if it isn't. *cough* but then again... i didn't look!
Hey Reznic. What exactly am I supposed to do with the Alpha channel? I tried messing around with the Channel settings, changing numbers and such, but it didn't really have any effect.
I suppose I could use a little help here, too. I'd like to alter it so the angle of incidence is not so extreme, but I don't quite understand how the gradient affects it.
To access the incidence gradient you look in Standard Assets/Water/Sources/oceangradient. If you bring that into Photoshop (I'm not sure about substitutes) you can alter the color of the gradient and/or alter the alpha of the gradient by going to the "Channels" tab of the layer window. You can run Brightness/Contrast, Curves, or anything else on the alpha to change the steepness of the incidence angle. you can even create a completely different gradient for different effects. Of course, if part of the image is white it be completely opaque, or completely transparent if it's black. You can make it so that the water is always slightly opaque by making sure the lowest value is something lighter than black. I'm not sure precisely how the opacity/intesity of the "Horizon Color" property is conrolled, but it too seems to be tied to the incidence gradient.
Editing the gradient and the horizon color allow some interesting effects, for sure. Is there a way I can get it so, when viewed from directly above, the ripples aren't invisible right in front of the camera? I can tell it must have something to do with what's being done to viewDir, but the code is opaque to me.
I had to transfer my files between computers and on my current computer the Shader is broken. It isn't translucent and there are no waves on the surface.
check your vid drivers or if your card isn't good enough. doubt the shader's broken. more likely something with your card.
GeForce 2 MX. I didn't even think about that. This computer is two or three years older than the other one, and I never upgraded the video card.
Is there a special way to prepare the transparent water material to use it with a different mesh? I'm getting this "smearing" effect when I apply it to an imported mesh, as if its uvs were weird.
How do you apply it? The easiest way to change the water mesh is described here - just changing the mesh used. If you're setting up water from scratch, you also have to add all required cameras, scripts etc.
I'm not quite sure how the shader handles the texture, but it seems to be a planar projection. The problem you're having is that your 3D app loks at the axes differently than unity. In your 3D app (which one are you using by the way?) you may have to rotate the water mesh 90 degrees on one of the axes (most likely x), re-export it and correct the rotation in unity.
I'm not having any issues applying the water material to arbitrary objects here. Actually it's pretty darn cool-looking; I hadn't really thought of using anything other than a plane before. Wonder if I can find some use for that.... --Eric
Thanks. I was just plopping the material onto other meshes and thinking it would work. I suppose this is a classic case of using something without understanding how it runs!
Sorry to super-gravedig, but I want to use this in Unity and I can't seem to get it transparent anymore. I've changed the Alpha channel on that image, but nothing happens. I have an Intel iMac now, so Graphics Card shouldn't be a problem. Shed some light Unity Community! Thanks!
lowers the alpha value (opacity, transparency, trnaslucency,) to .5 (the values range from 0.0 to 1.0, 0.0 being fully transparent). Think RGBA color values.
It would seem that this shader doesn't work in Unity 2. I'm messing with the new Water Shader to see if I can gift it transparency, but I'm pretty bad at ShaderLab.
The water used in Island Demo that comes with Unity actually uses a transparent water. You might try just using that (it's in Water folder in the project IIRC).
The reason it is not is because water often tends to be a large object. And large transparent objects can cause all sorts of transparency sorting problems when there are multiple transparent objects in the scene. In island demo the water is about the only thing that is transparent, so there are no problems. But in general case it might not be that useable.
Hi, I'm a newbie I'm afraid and I'm having some trouble wuth this. I get a load of error messages and the waves don't move: Could you give me some more detailed instructions? Unity Indie 2.5 Thanks a million!