hey, so I wrote a shader that makes my characters cloths wet when he goes into the water.
I calculate how deep he was submerged and then add that to his transform y position.
now my problem is that when he starts walk/running the vertices start moving up and down so it looks like the waterline moves across his cloths. I tried so many things to fix it i can’t even remember all of them.
my last hope is to try and set the waterline in the uv’s instead of vertex based. but i can’t seem to figure out how.
here’s the part of the shader that does the “making wet”
float dieDiff = cos(IN.worldPos.y) + (_WaterLevel - IN.worldPos.y) / _GradientScale;
if (dieDiff < 0)
{
dieDiff = 0;
}
else if (dieDiff > 1)
{
dieDiff = 1;
}
float dieFrac = _WaterColor.rgb * dieDiff + sg.a * (1-dieDiff);
o.Metallic = sg.rgb + (dieFrac* _Metallic) + IN.rainMask.a * _RainMultiplier;// - sm.rgb * _SkinTint;
o.Smoothness = sg.a + (dieFrac* _Glossiness) +IN.rainMask.a * _RainMultiplier;// - sm.rgb * _SkinTint;
_WaterLevel gets set by this piece of code
public void MakePlayerWet()
{
if (WaterBroker.IsInWater(m_Player.position))
{
m_IsWet = true;
m_UnderWaterDeepest = m_UnderWaterLevel;
if (WaterBroker.PreciseUnderWaterDepth(m_Player.position) > m_UnderWaterLevel)
{
m_UnderWaterDeepest = WaterBroker.PreciseUnderWaterDepth(m_Player.position);
m_UnderWaterLevel = m_UnderWaterDeepest;
}
m_Lerp = 0.0f;
}
if (m_IsWet)
{
m_WaterLevel = (m_Player.position.y + m_UnderWaterDeepest);
if (!WaterBroker.IsInWater(m_Player.position))
StartDrying();
if (m_currentMaterials.Count == 0)
GetMaterials();
foreach (Material m in m_currentMaterials)
m.SetFloat("_WaterLevel", m_Player.position.y + m_UnderWaterDeepest);
}
}
private void StartDrying()
{
m_Lerp = Mathf.Clamp01(m_Lerp + Time.deltaTime*m_DrySpeed);
m_WaterLevel = Mathf.Lerp(m_WaterLevel, m_Player.position.y, m_Lerp);
m_UnderWaterLevel = m_WaterLevel- m_Player.position.y;
if (m_Lerp >= 1.0f)
{
m_IsWet = false;
m_Lerp = 0.0f;
m_UnderWaterLevel = 0.0f;
}
}
and here is a small vid showing my problem: