just did one more test on the perlin noise - a poor man version of ocean shader. well, not realities at all but it is cheap only using 1 drawing call and everything running inside the shader ![]()
[ webplayer ]
http://homepage.mac.com/antonioh/unity3d/build/Perlin_Ocean.html
[ sample video ]
Basically, it is a very simple shader. Its use 2 channel of 2D Perlin noise to generate the normal.
float4 fragment_shader( v2f IN, out float4 finalcolor): COLOR
{
float2 ph = float2(shift_x, shift_y); // Phase Shift
float2 time = float2(_SinTime.w, _CosTime.w);
ph += time /3.0;
freq_0.xy += time /5.0;
float n0 = noise(IN.texcoord*freq_0.xy )*freq_0.w;
float n1 = noise(IN.texcoord*freq_0.xy +ph)*freq_0.w;
float nx = n0-n1;
float ny = n0-n1;
float nz = sqrt(max(0, 1-(nx*nx+ny*ny*freq_0.z)));
float3 normal = normalize(float3(nx, ny, nz ));
float4 c = tex2D(color_map,IN.texcoord*8.0 +ph*0.1)*nz;
float3 L = normalize(IN.light);
float3 V = normalize(IN.eye);
float diff = saturate(dot(L,normal));
float spec = saturate(dot(normalize(L-V),normal));
float att = 1.0 - max(0,L.z);
att = 1.0 - att*att;
return c*ambient_color + att*(c*diffuse_color*diff+specular_color*pow(spec,shine));
}
I also, put in some code to animate the vertex too ![]()
float4 pos = float4(IN.vertex.xyz, 1.0);
float3 d = 0.25- min(0.25, distance(_ObjectSpaceCameraPos, pos.xyz) *0.025);
pos.y = cos(pos.x *_SinTime.x + pos.z *_CosTime.x) *d;
Enjoy !