Feb
20
2014

Beach Sand Water (shader)

sea_beach_sand_water_shader_unity

Quick test for beach shader..

Inspiration from this topic: http://forum.unity3d.com/threads/229473-Wet-beach-texture

Info:
– Nothing much happening there, beach has moving mask to change color
– Water plane has moving vertices and quite basic normal mapped transparent shader
– Transparency glitches here & there.. (goes out of sync from moving?)
– Made sand normal map with this : ) normalmapmaker

Webplayer:
http://unitycoder.com/upload/demos/BeachSandWaterShader1/ (~3.7mb)

Sand texture:
http://hhh316.deviantart.com/art/Seamless-desert-sand-texture-183159331

Water shader (quite broken)

Shader "UnityCoder/SeaBeachTest1" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
	_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
	_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
//	_Perturb ("Perturb", 2D) = "black" {}
	_Mask ("Mask", 2D) = "black" {}
	_BumpMap ("Normal map", 2D) = "bump" {}
	_BumpMap2 ("Normal map2", 2D) = "bump" {}
	
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 300

CGPROGRAM
#pragma surface surf BlinnPhong alpha vertex:vert


sampler2D _MainTex;
sampler2D _Mask;
//sampler2D _Perturb;
sampler2D _BumpMap;
sampler2D _BumpMap2;
fixed4 _Color;
half _Shininess;

struct Input {
	float2 uv_MainTex;
	float2 uv_Mask;
	//float3 worldPos;
};

 void vert (inout appdata_full v) 
 {
 	v.vertex.z += (_SinTime.y*0.5f-0.5f)*10;
 }

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
	
	float2 pan = float2(0,(_SinTime.y*0.5f-0.5f));
	
	fixed4 norm1 = tex2D(_BumpMap, IN.uv_MainTex+pan*0.2f);
	fixed4 norm2 = tex2D(_BumpMap2, IN.uv_MainTex+pan*0.22f);
	
	
	
	fixed water = tex2D(_Mask, IN.uv_Mask).a;
	
	o.Albedo = tex.rgb * _Color.rgb;
	o.Gloss = tex.a;
	o.Alpha = ((1-_SinTime.y)*(tex.a*2 * _Color.a))-(1-water);
	o.Specular = tex.r*_Shininess;
	o.Normal = UnpackNormal(lerp(norm1,norm2,tex.r));
}
ENDCG
}

Fallback "Transparent/VertexLit"
}

Beach shader (quite broken)


Shader "UnityCoder/BeachSandTest1" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _CutOff ("CutOff", Range (0.0, 1)) = 0.5
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _BumpMap ("Normal map", 2D) = "bump" {}
    _SpecMap ("Specular map", 2D) = "black" {}
    _Mask ("Mask", 2D) = "black" {}
}
SubShader { 
    Tags { "RenderType"="Opaque" }
    LOD 400
    
CGPROGRAM
#pragma surface surf BlinnPhong
#pragma exclude_renderers flash
#pragma target 3.0

sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _SpecMap;
sampler2D _Mask;
fixed4 _Color;
fixed _CutOff;
half _Shininess;

struct Input {
    float2 uv_MainTex;
    float2 uv_Mask;
};

void surf (Input IN, inout SurfaceOutput o) {
    
    float2 pan = float2(0,_SinTime.y*0.5f-0.5f);
    
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    
//    fixed wet = clamp(tex2D(_Mask, IN.uv_Mask+pan).r,0,0.5f); //,0,_CutOff)*2;
    fixed wet = tex2D(_Mask, IN.uv_Mask+pan).r;
    //fixed wet = tex2D(_Mask, IN.uv_Mask).r;
//    fixed4 specTex = tex2D(_SpecMap, IN.uv_MainTex+pan);
    fixed4 specTex = tex2D(_SpecMap, IN.uv_MainTex);
    fixed4 specTex2 = tex2D(_SpecMap, IN.uv_MainTex+pan*0.2f);
    
    float4 norm1 = tex2D(_BumpMap, IN.uv_MainTex);
    float4 norm2 = tex2D(_BumpMap, IN.uv_MainTex+pan*2);
    
    fixed4 tex2 = tex2D(_MainTex, IN.uv_MainTex+pan);
    
    //fixed3 c = tex.rgb;
    fixed3 cc = lerp(tex.rgb,tex2.rgb*0.2f,wet*_CutOff);
    
    float g = clamp(lerp(specTex2.r,0,cc.r),0,1);
    float g2 = clamp(lerp(specTex.r,specTex2.r,wet),0,1);
    
    o.Albedo = cc;
    o.Gloss = g;
    //o.Emission = g*10;
    o.Alpha = 1; //tex.a * _Color.a;
    o.Specular = g2;//*_Shininess;// * specTex.g * wet;
    o.Normal = UnpackNormal(lerp(norm1,norm2,g));
}
ENDCG
}

FallBack "Specular"
}



 

 


2 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.