Minor - Add Assets And Support Dual Screen
This commit is contained in:
9
Assets/MobileDepthWater/Shaders/WaterOpaque.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterOpaque.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 632cd2f10f155c24185d24edb6f980bc
|
||||
folderAsset: yes
|
||||
timeCreated: 1493144633
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/MobileDepthWater/Shaders/WaterOpaque/Depth.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterOpaque/Depth.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cc8fd61d919e074992c0f77c28c8fc8
|
||||
folderAsset: yes
|
||||
timeCreated: 1493418164
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,186 @@
|
||||
Shader "Custom/Water/Depth/DiffuseColorWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility ("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterDepth ("Water depth param", Range(0, 0.1)) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
fixed4 worldPos : TEXCOORD0;
|
||||
fixed camHeightOverWater : TEXCOORD1;
|
||||
fixed waterDepth : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterDepth;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
fixed3 rayToWaterPlane = o.camHeightOverWater / (-camToWorldRay.y) * camToWorldRay;
|
||||
fixed depth = length(camToWorldRay - rayToWaterPlane);
|
||||
o.waterDepth = depth * _WaterDepth * saturate(rayToWaterPlane.y - camToWorldRay.y);
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos + rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha + i.waterDepth);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(i.waterDepth, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb270c1e5be780e46b05d4a023cd7e73
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterOpaque/Depth/DiffuseColorDepthWater.shader
|
||||
uploadId: 179707
|
||||
@@ -0,0 +1,192 @@
|
||||
Shader "Custom/Water/Depth/DiffuseWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility ("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterDepth ("Water depth param", Range(0, 0.1)) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
fixed waterDepth : TEXCOORD3;
|
||||
UNITY_FOG_COORDS(4)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD5;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD5;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterDepth;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = tex2D(_MainTex, i.uv) * _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
fixed3 rayToWaterPlane = o.camHeightOverWater / (-camToWorldRay.y) * camToWorldRay;
|
||||
fixed depth = length(camToWorldRay - rayToWaterPlane);
|
||||
o.waterDepth = depth * _WaterDepth * saturate(rayToWaterPlane.y - camToWorldRay.y);;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos + rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha + i.waterDepth);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7e85ac45d06bba48b3f9c38ef023f7b
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterOpaque/Depth/DiffuseDepthWater.shader
|
||||
uploadId: 179707
|
||||
@@ -0,0 +1,112 @@
|
||||
Shader "Custom/Water/DiffuseWaterOpaque"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex ("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos: TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (o.camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos - rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, waterCol);
|
||||
|
||||
return waterCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12a8cc6f8fa05ab49a845b58de64c0ee
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterOpaque/DiffuseWaterOpaque.shader
|
||||
uploadId: 179707
|
||||
9
Assets/MobileDepthWater/Shaders/WaterOpaque/Height.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterOpaque/Height.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e062190da4e75949b852630e2f9d775
|
||||
folderAsset: yes
|
||||
timeCreated: 1493418171
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,184 @@
|
||||
Shader "Custom/Water/Height/DiffuseColorWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
float4 _WaterTex_ST;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _WaterTex);
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (o.camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos - rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db40be83fcff3ea48b6d4ddba9b8a9db
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterOpaque/Height/DiffuseColorHeightWater.shader
|
||||
uploadId: 179707
|
||||
@@ -0,0 +1,186 @@
|
||||
Shader "Custom/Water/Height/DiffuseWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = tex2D(_MainTex, i.uv) * _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (o.camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos - rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c457a2dd112aafe4f9008b8dd0c15a31
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterOpaque/Height/DiffuseHeightWater.shader
|
||||
uploadId: 179707
|
||||
9
Assets/MobileDepthWater/Shaders/WaterTwoSide.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterTwoSide.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0250523c753206d488cedbd62550b59a
|
||||
folderAsset: yes
|
||||
timeCreated: 1493144633
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/MobileDepthWater/Shaders/WaterTwoSide/Depth.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterTwoSide/Depth.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dac9c720acd24f44398957e83cc3b87c
|
||||
folderAsset: yes
|
||||
timeCreated: 1493418164
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,187 @@
|
||||
Shader "Custom/Water/TwoSide/Depth/DiffuseColorWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility ("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterDepth ("Water depth param", Range(0, 0.1)) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
fixed4 worldPos : TEXCOORD0;
|
||||
fixed camHeightOverWater : TEXCOORD1;
|
||||
fixed waterDepth : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterDepth;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
fixed3 rayToWaterPlane = o.camHeightOverWater / (-camToWorldRay.y) * camToWorldRay;
|
||||
fixed depth = length(camToWorldRay - rayToWaterPlane);
|
||||
o.waterDepth = depth * _WaterDepth * saturate(rayToWaterPlane.y - camToWorldRay.y);
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos + rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha + i.waterDepth);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(i.waterDepth, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2065017c9f60034a921e136ee175344
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterTwoSide/Depth/DiffuseColorDepthWaterTwoSide.shader
|
||||
uploadId: 179707
|
||||
@@ -0,0 +1,194 @@
|
||||
Shader "Custom/Water/TwoSide/Depth/DiffuseWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility ("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterDepth ("Water depth param", Range(0, 0.1)) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
fixed waterDepth : TEXCOORD3;
|
||||
UNITY_FOG_COORDS(4)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD5;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD5;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterDepth;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = tex2D(_MainTex, i.uv) * _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
fixed3 rayToWaterPlane = o.camHeightOverWater / (-camToWorldRay.y) * camToWorldRay;
|
||||
fixed depth = length(camToWorldRay - rayToWaterPlane);
|
||||
o.waterDepth = depth * _WaterDepth * saturate(rayToWaterPlane.y - camToWorldRay.y);;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos + rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha + i.waterDepth);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43be516172fe7624da4ca48a036caaf5
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterTwoSide/Depth/DiffuseDepthWaterTwoSide.shader
|
||||
uploadId: 179707
|
||||
9
Assets/MobileDepthWater/Shaders/WaterTwoSide/Height.meta
Normal file
9
Assets/MobileDepthWater/Shaders/WaterTwoSide/Height.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f35b01f87496ec42b68244883e69638
|
||||
folderAsset: yes
|
||||
timeCreated: 1493418171
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,185 @@
|
||||
Shader "Custom/Water/TwoSide/Height/DiffuseColorWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
float4 _WaterTex_ST;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _WaterTex);
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (o.camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos - rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 028ad784f85aa8642a6cf82631f7fd50
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterTwoSide/Height/DiffuseColorHeightWaterTwoSide.shader
|
||||
uploadId: 179707
|
||||
@@ -0,0 +1,187 @@
|
||||
Shader "Custom/Water/TwoSide/Height/DiffuseWater"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
|
||||
[Space(20)]
|
||||
_WaterColor ("Water color", Color) = (1, 1, 1, 1)
|
||||
_WaterTex("Water texture", 2D) = "white" {}
|
||||
_Tiling ("Water tiling", Vector) = (1, 1, 1, 1)
|
||||
_TextureVisibility("Texture visibility", Range(0, 1)) = 1
|
||||
|
||||
[Space(20)]
|
||||
_DistTex ("Distortion", 2D) = "white" {}
|
||||
_DistTiling ("Distortion tiling", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[Space(20)]
|
||||
//_DeepColor ("Water deep color", Color) = (1, 1, 1, 1)
|
||||
_WaterHeight ("Water height", Float) = 0
|
||||
_WaterDeep ("Water deep", Float) = 0
|
||||
_WaterMinAlpha ("Water min alpha", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_BorderColor ("Border color", Color) = (1, 1, 1, 1)
|
||||
_BorderWidth ("Border width", Range(0, 1)) = 0
|
||||
|
||||
[Space(20)]
|
||||
_MoveDirection ("Direction", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "BW" = "TrueProbes" "LightMode" = "ForwardBase" }
|
||||
LOD 100
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityLightingCommon.cginc"
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
#if LIGHTMAP_ON
|
||||
float2 lightmap_uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
fixed4 worldPos : TEXCOORD1;
|
||||
fixed camHeightOverWater : TEXCOORD2;
|
||||
UNITY_FOG_COORDS(3)
|
||||
#if LIGHTMAP_ON
|
||||
fixed2 lightmap_uv : TEXCOORD4;
|
||||
#else
|
||||
fixed4 diffuseLight : TEXCOORD4;
|
||||
#endif
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
sampler2D _WaterTex;
|
||||
fixed2 _Tiling;
|
||||
fixed4 _WaterColor;
|
||||
|
||||
sampler2D _DistTex;
|
||||
fixed2 _DistTiling;
|
||||
|
||||
fixed4 _DeepColor;
|
||||
fixed _WaterHeight;
|
||||
fixed _TextureVisibility;
|
||||
fixed _WaterDeep;
|
||||
fixed _WaterMinAlpha;
|
||||
|
||||
fixed4 _BorderColor;
|
||||
fixed _BorderWidth;
|
||||
fixed _BorderVisibility;
|
||||
|
||||
fixed3 _MoveDirection;
|
||||
|
||||
fixed4 DiffuseLight(fixed3 worldNormal)
|
||||
{
|
||||
half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
|
||||
|
||||
fixed4 diff = nl * _LightColor0;
|
||||
diff.rgb += ShadeSH9(half4(worldNormal, 1));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
fixed2 WaterPlaneUV(fixed3 worldPos, fixed camHeightOverWater)
|
||||
{
|
||||
fixed3 camToWorldRay = worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
return rayToWaterPlane.xz - _WorldSpaceCameraPos.xz;
|
||||
}
|
||||
|
||||
fixed3 LightmapColor(fixed2 lightmap_uv)
|
||||
{
|
||||
fixed4 lightmapCol = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmap_uv);
|
||||
return DecodeLightmap(lightmapCol);
|
||||
}
|
||||
|
||||
fixed4 MainColor(v2f i)
|
||||
{
|
||||
fixed4 mainCol = tex2D(_MainTex, i.uv) * _Color;
|
||||
#if LIGHTMAP_ON
|
||||
mainCol.rgb *= LightmapColor(i.lightmap_uv);
|
||||
#else
|
||||
mainCol.rgb *= i.diffuseLight;
|
||||
#endif
|
||||
|
||||
return mainCol;
|
||||
}
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul(UNITY_MATRIX_M, v.vertex);
|
||||
o.vertex = mul(UNITY_MATRIX_VP, o.worldPos);
|
||||
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.camHeightOverWater = _WorldSpaceCameraPos.y - _WaterHeight;
|
||||
|
||||
#if LIGHTMAP_ON
|
||||
o.lightmap_uv = v.lightmap_uv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#else
|
||||
fixed4 worldNormal = normalize(mul(UNITY_MATRIX_M, float4(v.normal.xyz, 0)));
|
||||
o.diffuseLight = DiffuseLight(worldNormal.xyz);
|
||||
#endif
|
||||
|
||||
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
|
||||
fixed3 camToWorldRay = o.worldPos - _WorldSpaceCameraPos;
|
||||
fixed3 rayToWaterPlane = (o.camHeightOverWater / camToWorldRay.y * camToWorldRay);
|
||||
|
||||
fixed3 worldPosOnPlane = _WorldSpaceCameraPos - rayToWaterPlane;
|
||||
fixed3 positionForFog = lerp(worldPosOnPlane, o.worldPos.xyz, o.worldPos.y > _WaterHeight);
|
||||
fixed4 waterVertex = mul(UNITY_MATRIX_VP, fixed4(positionForFog, 1));
|
||||
UNITY_TRANSFER_FOG(o, waterVertex);
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed lengthUnderWater = max(0, _WaterHeight - i.worldPos.y);
|
||||
fixed underWater = lerp(0, 1, lengthUnderWater > 0);
|
||||
fixed borderAlpha = lerp(underWater * _BorderColor.a, 0, saturate(lengthUnderWater / _BorderWidth));
|
||||
fixed waterAlpha = saturate(lengthUnderWater / _WaterDeep + _WaterMinAlpha);
|
||||
|
||||
fixed4 mainCol = MainColor(i);
|
||||
|
||||
fixed2 water_uv = WaterPlaneUV(i.worldPos, i.camHeightOverWater);
|
||||
fixed4 distortion = tex2D(_DistTex, water_uv * _DistTiling) * 2 - 1;
|
||||
fixed2 distorted_uv = ((water_uv + distortion.rg) - _Time.y * _MoveDirection.xz) * _Tiling;
|
||||
|
||||
fixed4 waterCol = tex2D(_WaterTex, distorted_uv);
|
||||
waterCol = lerp(_WaterColor, fixed4(1, 1, 1, 1), waterCol.r * _TextureVisibility);
|
||||
|
||||
fixed4 finalCol = lerp(mainCol, waterCol, _WaterColor.a * waterAlpha * underWater);
|
||||
finalCol.rgb = lerp(finalCol.rgb, _BorderColor.rgb, borderAlpha);
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, finalCol);
|
||||
|
||||
//return fixed4(reflection, 0, 0, 1);
|
||||
return finalCol;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f60c2d25440af4243bba933dc9bb262e
|
||||
timeCreated: 1493134247
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 89541
|
||||
packageName: Mobile depth water shader
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/MobileDepthWater/Shaders/WaterTwoSide/Height/DiffuseHeightWaterTwoSide.shader
|
||||
uploadId: 179707
|
||||
Reference in New Issue
Block a user