problem with simple sine wave shader

So I have this shader and it simply wont compile on my machine giving some weird error saying type name expected at token “.” at line 20.

Shader “Underwater Effect” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}

Pass {

CGPROGRAM
#pragma vertex vert

#include “UnityCG.cginc”
#include “AutoLight.cginc”

uniform float4 _MainTex_ST;

vert (appdata_base v)
{
float Waviness = 5.0f;
v.vertex.x += Mathf.Sin(Time.time + v.vertex.y * 0.1f) * Waviness;
}
ENDCG

}

Fallback “Diffuse”

}

Basically i just want to displace the vertex position to have a sine wave.
Any help appreciated.

Thx

Cg is completely and totally separate from the rest of Unity (it’s only for graphics cards), so you can’t use C# syntax, Mathf, Time.time or anything. There is a _SinTime but I haven’t looked into how to use it. You probably want to have a look in the manual about writing shaders; there’s a rather large section about it. Although there is much that is still mysterious. :wink:

–Eric

Cg definitely has a sin function (lowercase s). To vary the wave’s phase with time, you should add a property called “phase” (or whatever) to the shader and animate it directly from the Update method of a Unity class. I don’t think there is a good way to vary a property with time directly in the Cg code, but I’d love to be shown otherwise.

There was the WindyGrass.shader + waves.cginc doing sin-wave vertex deformation with an early nature demo package. I’ve used that as a starting point for stuff like this. Attached a zip with the files.

/P

79874–3073–$grass_103.zip (2.11 KB)

I think it should work if use the time function which returns time in integer value.rest should be taken care of by the sin function shouldn’t it?

Yes, sorry - I just didn’t know about the built-in time property.

Hey tell u wat.i scoured a lot for the ‘heard of’ time functionality in cg but found none.