Simple water ripple shader

Hi guys,

I have searched for a long time and just cant find it. Was hoping one can help me out…

I am looking for a simple water shader that distorts a maintexture to get a refraction effect like:

I don’t need reflections, specular etc, just a slight transparent plane with a texture that gets distorted with a certain speed so it fakes little waves (moving) water…

Does anyone know where I can find this?

Thanks :slight_smile:

Take a look at the shader in the standard Glass Refraction (Pro Only) package that comes with Unity, or try the Refraction shader from the Unity Wiki.

It’s not physically accurate of course, but it works well enough in most simple cases. I use something similar for my own water shader.

To refract _MainTex in stead of _GrabTexture, apply the perturbation to regular uv coordinates, in stead of the projected(uvrefr) ones.

1 Like

I tried to use the refraction shader, but when I applied it to a material, it just made the material purple. No refraction or distortion going on. Wat do?

More info: Click on shader, says Shader has errors or not compatible with GPU. I doubt it’s compatibility as my PC is beast. It says surface shader: no. Then also it says error: parse error: syntax error.

Code where error is = line 8.

// Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
// Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
// Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP'
// Upgrade NOTE: replaced 'glstate.matrix.texture[0]' with 'UNITY_MATRIX_TEXTURE0'
// Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D'
// Upgrade NOTE: replaced 'texRECTproj' with 'tex2Dproj'
 
// Uses geometry normals to distort the image behind, and
// an additional texture to tint the color.
 
Shader "FX/Refraction Distort" { 
Properties {
  _BumpAmt  ("Distortion", range (0,128)) = 10.0
  _MainTex ("Tint Color (RGB)", 2D) = "white" {}
}

I had some ellow errors too, so I changed:

CGPROGRAM
// profiles arbfp1
// vertex vert
// fragment frag
// fragmentoption ARB_precision_hint_fastest
// fragmentoption ARB_fog_exp2

to

CGPROGRAM
// profiles arbfp1
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma fragmentoption ARB_fog_exp2

It said I should use ‘#pragma target’ instead of ‘profiles’, but I couldn’t do ‘#pragma target arbfp1’, so I don’t know. The red error persist. I have no idea what I’m doing. I suck at shaders. This shader doesn’t work.

You know what, you’re absolutely right, I didn’t check the wiki version, it’s absolutely ancient.
Just try the version that comes with Unity. (Assets > Import Package > Glass Refraction (Pro Only)). That one definitely works.

I’m sure it would work wonderfully…

Is that sarcasm? If it is, I’m gonna need help to understand what’s wrong.

…if I had pro.

Well… yeah, Render Textures are kind of important to create refraction effects, because you need to move pixel colors from the original scene around, which is hard if you can’t store the data you need to modify. I believe there are some tools available on the Asset Store that create similar effects using the CPU, but I can’t really help you with that.

Even the wiki example uses GrabPass, which requires RenderTexture support.

I had one I used in unity free 3.x, but it doesn’t work anymore.

What did you use in Unity Free 3.x?

I found it: Here It’s actually a heat distortion, but I modified it for underwater.

Oh man, mess with regular uvs, not projected! this is what I love about shader talk, you can blow my mind with four words :slight_smile: