升级6.4.升级水,升级天气
This commit is contained in:
@@ -22,6 +22,7 @@ namespace WaveHarmonic.Crest
|
||||
public static int s_WaterLineSnappedPosition = Shader.PropertyToID("_Crest_WaterLineSnappedPosition");
|
||||
public static int s_WaterLineResolution = Shader.PropertyToID("_Crest_WaterLineResolution");
|
||||
public static int s_WaterLineTexel = Shader.PropertyToID("_Crest_WaterLineTexel");
|
||||
public static int s_WaterLineFlatWater = Shader.PropertyToID("_Crest_WaterLineFlatWater");
|
||||
}
|
||||
|
||||
RenderTexture _HeightRT;
|
||||
@@ -50,6 +51,13 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
internal void UpdateDisplacedSurfaceData(Camera camera)
|
||||
{
|
||||
Helpers.SetGlobalBoolean(ShaderIDs.s_WaterLineFlatWater, IsQuadMesh);
|
||||
|
||||
if (IsQuadMesh)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// World size of the texture. Formula should effectively cover the camera.
|
||||
var size = 1f + (camera.nearClipPlane * 2f);
|
||||
|
||||
@@ -76,6 +84,7 @@ namespace WaveHarmonic.Crest
|
||||
"_Crest_WaterLine",
|
||||
ref _HeightRT,
|
||||
texel: 0.0125f,
|
||||
maximumResolution: 2048,
|
||||
out _SurfaceDataParameters
|
||||
);
|
||||
|
||||
@@ -84,9 +93,11 @@ namespace WaveHarmonic.Crest
|
||||
BindDisplacedSurfaceData(wrapper);
|
||||
|
||||
var lod = (int)Builder.PatchType.Interior;
|
||||
var mpb = _PerCascadeMPB.Current[lod];
|
||||
var mpb = PerCascadeMPB[lod];
|
||||
|
||||
if (_Water.Viewpoint != camera.transform && Vector3.Distance(_Water.Viewpoint.position, camera.transform.position) > 0.01f)
|
||||
var viewpoint = _Water.Viewpoint;
|
||||
|
||||
if (viewpoint == null || (viewpoint != camera.transform && Vector3.Distance(viewpoint.position, camera.transform.position) > 0.01f))
|
||||
{
|
||||
foreach (var chunk in _Water.Surface.Chunks)
|
||||
{
|
||||
@@ -125,22 +136,32 @@ namespace WaveHarmonic.Crest
|
||||
Graphics.ExecuteCommandBuffer(commands);
|
||||
}
|
||||
|
||||
internal void UpdateDisplacedSurfaceData(CommandBuffer commands, Bounds bounds, string name, ref RenderTexture target, float texel, out SurfaceDataParameters parameters)
|
||||
internal void UpdateDisplacedSurfaceData(CommandBuffer commands, Bounds bounds, string name, ref RenderTexture target, float texel, int maximumResolution, out SurfaceDataParameters parameters)
|
||||
{
|
||||
var size = bounds.size.XZ();
|
||||
var position = bounds.center.XZ();
|
||||
|
||||
var scale = size;
|
||||
|
||||
// TODO: texel needs to be calculates is clamped
|
||||
// TODO: aspect ratio
|
||||
var resolution = new Vector2Int
|
||||
(
|
||||
// TODO: Floor, Ceil or Round?
|
||||
Mathf.CeilToInt(size.x / texel),
|
||||
Mathf.CeilToInt(size.y / texel)
|
||||
);
|
||||
|
||||
var largest = Mathf.Max(resolution.x, resolution.y);
|
||||
|
||||
if (largest > maximumResolution)
|
||||
{
|
||||
texel = Mathf.Max(size.x, size.y) / maximumResolution;
|
||||
|
||||
resolution = new Vector2Int
|
||||
(
|
||||
Mathf.CeilToInt(size.x / texel),
|
||||
Mathf.CeilToInt(size.y / texel)
|
||||
);
|
||||
}
|
||||
|
||||
// Snapping for spatial stability. Different results, but could not tell which is
|
||||
// more accurate. At higher resolution, appears negligable anyway.
|
||||
var snapped = position - new Vector2(Mathf.Repeat(position.x, texel), Mathf.Repeat(position.y, texel));
|
||||
@@ -153,11 +174,6 @@ namespace WaveHarmonic.Crest
|
||||
_Texel = texel,
|
||||
};
|
||||
|
||||
if (resolution.x > 2048 || resolution.y > 2048)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: LOD scale less than two has cut off and fall off at edges.
|
||||
var view = WaterRenderer.CalculateViewMatrixFromSnappedPositionRHS(snapped.XNZ());
|
||||
var projection = Matrix4x4.Ortho(size.x * -0.5f, size.x * 0.5f, size.y * -0.5f, size.y * 0.5f, 1f, 10000f + 10000f);
|
||||
|
||||
Reference in New Issue
Block a user