You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/AllIn1SpriteShader/Resources/WaterWaves.shader

68 lines
2.2 KiB
Plaintext

Shader "Custom/WaterWave"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {} // Main texture property
_WaveHeight ("Wave Height", Range(0, 0.2)) = 0.05 // Height of the wave effect
_Speed ("Wave Speed", Range(0, 5.0)) = 2.0 // Speed of the wave movement
_Frequency ("Wave Frequency", Range(0, 20.0)) = 5.0 // Frequency of the waves
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Overlay" }
LOD 200
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION; // Vertex position
float2 uv : TEXCOORD0; // UV coordinates
};
struct v2f
{
float2 uv : TEXCOORD0; // UV coordinates
float4 vertex : SV_POSITION; // Vertex position for rendering
};
sampler2D _MainTex; // The main texture
float _WaveHeight; // Wave height (amplitude)
float _Speed; // Speed of the wave
float _Frequency; // Frequency of the wave
// Vertex function to create wave distortion on top vertices
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex); // Convert vertex position to clip space
o.uv = v.uv;
// Create a wave effect at the top of the image (for uv.y > 0.5)
if (v.uv.y > 0.5)
{
// Calculate wave displacement using the built-in _Time variable
float wave = sin(_Frequency * v.uv.x + _Speed * _Time.y) * _WaveHeight;
o.vertex.y += wave; // Offset the y position to create the wave effect
}
return o;
}
// Fragment shader to render the texture
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv); // Sample the texture
return col; // Return the final color
}
ENDCG
}
}
FallBack "Transparent"
}