|
|
?????????????????
1.?????????
2.??????? ???????3D??2D ??????
3.???????????????????Y???
???Unity Connect??????????????????Unity??????????
?????
?????????????? z(i,j,k+1) ? ????+?????+????
???? *= (4-8*c^2*t^2/d^2/d^2)/(u*t)
????? *= (ut-2) / (ut + 2)
???? *= (2c^2t^2/d^2) / (ut + 2)
???????? c ??? u ??, d ??????, t ?????
???????????
????????????Unity Wiki?????????????wiki???????????
https://wiki.unity3d.com/index.php/CreatePlane
???????????10???10????100??????????????????????????????????3???????????????????
- m_waterWaveMarkTexture = new RenderTexture(WaveTextureResolution, WaveTextureResolution, 0, RenderTextureFormat.Default);
- m_waterWaveMarkTexture.name = "m_waterWaveMarkTexture";
- m_waveTransmitTexture = new RenderTexture(WaveTextureResolution, WaveTextureResolution, 0, RenderTextureFormat.Default);
- m_waveTransmitTexture.name = "m_waveTransmitTexture";
- m_prevWaveMarkTexture = new RenderTexture(WaveTextureResolution, WaveTextureResolution, 0, RenderTextureFormat.Default);
- m_prevWaveMarkTexture.name = "m_prevWaveMarkTexture";
复制代码
????????
- void WaterPlaneCollider()
- {
- hasHit = false;
- if (Input.GetMouseButton(0))
- {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hitInfo = new RaycastHit();
- bool ret = Physics.Raycast(ray.origin, ray.direction, out hitInfo);
- if (ret)
- {
- Vector3 waterPlaneSpacePos = WaterPlane.transform.worldToLocalMatrix * new Vector4(hitInfo.point.x, hitInfo.point.y, hitInfo.point.z, 1);
- float dx = (waterPlaneSpacePos.x / WaterPlaneWidth) + 0.5f;
- float dy = (waterPlaneSpacePos.z / WaterPlaneLength) + 0.5f;
- hitPos.Set(dx, dy);
- m_waveMarkParams.Set(dx, dy, WaveRadius * WaveRadius, WaveHeight);
- hasHit = true;
- }
- }
- }
复制代码
??????Raycast ??????????????????????? [0-1] ??????????uv?????? m_waterWaveMarkTexture ????? ???????? world2Local ???????? ???CreatePlane?????Pivot ?????????????1????????[-0.5,0.5]????????? + 0.5???
??????Shader
- float dx = i.uv.x - _WaveMarkParams.x;
- float dy = i.uv.y - _WaveMarkParams.y;
- float disSqr = dx * dx + dy * dy;
- int hasCol = step(0, _WaveMarkParams.z - disSqr);
- float waveValue = DecodeHeight(tex2D(_MainTex, i.uv));
- if (hasCol == 1) {
- waveValue = _WaveMarkParams.w;
- }
复制代码
?????_WaveMarkParams.xy ???uv ?????????????????????
????Shader
- static const float2 WAVE_DIR[4] = { float2(1, 0), float2(0, 1), float2(-1, 0), float2(0, -1) };
- float dx = _WaveTransmitParams.w;
- float avgWaveHeight = 0;
- for (int s = 0; s < 4; s++)
- {
- avgWaveHeight += DecodeHeight(tex2D(_MainTex, i.uv + WAVE_DIR[s] * dx));
- }
- //(2 * c^2 * t^2 / d ^2) / (u * t + 2)*(z(x + dx, y, t) + z(x - dx, y, t) + z(x, y + dy, t) + z(x, y - dy, t);
- float agWave = _WaveTransmitParams.z * avgWaveHeight;
- // (4 - 8 * c^2 * t^2 / d^2) / (u * t + 2)
- float curWave = _WaveTransmitParams.x * DecodeHeight(tex2D(_MainTex, i.uv));
- // (u * t - 2) / (u * t + 2) * z(x,y,z, t - dt) ?????? t - dt
- float prevWave = _WaveTransmitParams.y * DecodeHeight(tex2D(_PrevWaveMarkTex, i.uv));
- //???
- float waveValue = (curWave + prevWave + agWave) * _WaveAtten;
复制代码
????????????????????????????ES3.0 ???
- v2f vert (appdata v)
- {
- v2f o;
- float4 localPos = v.vertex;
- float4 waveTransmit = tex2Dlod(_WaveResult, float4(v.uv, 0, 0));
- float waveHeight = DecodeFloatRGBA(waveTransmit);
- localPos.y += waveHeight * _WaveScale;
- float3 worldPos = mul(unity_ObjectToWorld, localPos);
- float3 worldSpaceNormal = mul(unity_ObjectToWorld, v.normal);
- float3 worldSpaceViewDir = UnityWorldSpaceViewDir(worldPos);
- o.vertex = mul(UNITY_MATRIX_VP, float4(worldPos, 1));
- o.uv = v.uv;
- o.worldSpaceReflect = reflect(-worldSpaceViewDir, worldSpaceNormal);
- return o;
复制代码
* ????????????
https://en.wikipedia.org/wiki/Wave_equation
https://www.amazon.com/Mathematics-Programming-Computer-Graphics-Third/dp/1435458869 ?? ??
???dreamfairy
???Unity????
????https://mp.weixin.qq.com/s/-sL54xgyX6mVMnVOMHnpVg
|
|