升级水插件
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
@@ -9,6 +9,7 @@ namespace WaveHarmonic.Crest
|
||||
/// <summary>
|
||||
/// A persistent simulation that moves around with a displacement LOD.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public abstract partial class PersistentLod : Lod
|
||||
{
|
||||
[Tooltip("Frequency to run the simulation, in updates per second.\n\nLower frequencies are more efficient but may lead to visible jitter or slowness.")]
|
||||
@@ -37,6 +38,8 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
internal int LastUpdateSubstepCount { get; private set; }
|
||||
|
||||
private protected virtual int Kernel => 0;
|
||||
private protected virtual bool SkipFlipBuffers => false;
|
||||
private protected abstract ComputeShader SimulationShader { get; }
|
||||
private protected abstract void GetSubstepData(float timeToSimulate, out int substeps, out float delta);
|
||||
|
||||
@@ -61,9 +64,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
internal override void BuildCommandBuffer(WaterRenderer water, CommandBuffer buffer)
|
||||
{
|
||||
buffer.BeginSample(Name);
|
||||
buffer.BeginSample(ID);
|
||||
|
||||
FlipBuffers();
|
||||
if (!SkipFlipBuffers)
|
||||
{
|
||||
FlipBuffers();
|
||||
}
|
||||
|
||||
var slices = water.LodLevels;
|
||||
|
||||
@@ -91,19 +97,19 @@ namespace WaveHarmonic.Crest
|
||||
// artifacts if not and there is a renderer input. Happens for foam and dynamic
|
||||
// waves. Confusing/concerning.
|
||||
buffer.GetTemporaryRT(ShaderIDs.s_TemporaryPersistentTarget, DataTexture.descriptor);
|
||||
buffer.SetRenderTarget(ShaderIDs.s_TemporaryPersistentTarget, 0, CubemapFace.Unknown, -1);
|
||||
buffer.ClearRenderTarget(RTClearFlags.Color, ClearColor, 0, 0);
|
||||
CoreUtils.SetRenderTarget(buffer, ShaderIDs.s_TemporaryPersistentTarget, ClearFlag.Color, ClearColor);
|
||||
}
|
||||
|
||||
var target = new RenderTargetIdentifier(DataTexture);
|
||||
var source = new RenderTargetIdentifier(ShaderIDs.s_TemporaryPersistentTarget);
|
||||
var current = target;
|
||||
|
||||
var wrapper = new PropertyWrapperCompute(buffer, SimulationShader, Kernel);
|
||||
|
||||
for (var substep = 0; substep < substeps; substep++)
|
||||
{
|
||||
var isFirstStep = substep == 0;
|
||||
var frame = isFirstStep ? 1 : 0;
|
||||
var wrapper = new PropertyWrapperCompute(buffer, SimulationShader, 0);
|
||||
|
||||
// Record how much we caught up
|
||||
_TimeToSimulate -= delta;
|
||||
@@ -168,14 +174,15 @@ namespace WaveHarmonic.Crest
|
||||
// Set the target texture as to make sure we catch the 'pong' each frame.
|
||||
Shader.SetGlobalTexture(_TextureShaderID, DataTexture);
|
||||
|
||||
buffer.EndSample(Name);
|
||||
buffer.EndSample(ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set any simulation specific shader parameters.
|
||||
/// </summary>
|
||||
private protected virtual void SetAdditionalSimulationParameters<T>(T properties) where T : IPropertyWrapper
|
||||
private protected virtual void SetAdditionalSimulationParameters(PropertyWrapperCompute properties)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user