Transparent water for indie

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

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:

col.a = water.a;

at end of fragment program and

MOV r0.a, r2.a;

at end of R9000 fragment assembly shader

14310–484–$fx-water_nonreflectalpha_199.shader (3.38 KB)

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. :wink:

TIA!
Daniel

You can just do something like

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. :slight_smile:

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 :sweat_smile: should be in the standard assets if it isn’t. cough but then again… i didn’t look! :sweat_smile:

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.

Thanks Rez. I think I found the perfect consistancy for my water. It looks great!

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. :frowning:

check your vid drivers or if your card isn’t good enough. doubt the shader’s broken. more likely something with your card.

Moldorma: what is your video 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.