升级水插件

This commit is contained in:
2026-01-08 22:30:55 +08:00
parent febff82d24
commit ca68084264
415 changed files with 18138 additions and 7134 deletions

View File

@@ -14,6 +14,21 @@ namespace WaveHarmonic.Crest
}
#endif
/// <summary>
/// The render pass injection point.
/// </summary>
[@GenerateDoc]
public enum WaterInjectionPoint
{
/// <inheritdoc cref="Generated.WaterInjectionPoint.Default" />
[Tooltip("Renders in the default pass.\n\nFor the water surface, this will be determined by the material (opaque or transparent). This pass is controlled by Unity, and is not compatible with certain features like soft particles.\n\nFor the water volume, this will be after transparency.")]
Default,
/// <inheritdoc cref="Generated.WaterInjectionPoint.BeforeTransparent" />
[Tooltip("Renders before the transparent pass.\n\nThis has advantages like being compatible with soft particles, refractive shaders, and possibly third-party fog.")]
BeforeTransparent,
}
partial class WaterRenderer
{
internal const float k_MaximumWindSpeedKPH = 150f;
@@ -25,37 +40,64 @@ namespace WaveHarmonic.Crest
[Tooltip("The camera which drives the water data.\n\nSetting this is optional. Defaults to the main camera.")]
[@GenerateAPI(Getter.Custom, name: "Viewer")]
[@DecoratedField, SerializeField]
Camera _Camera;
internal Camera _Camera;
[Tooltip("Optional provider for time.\n\nCan be used to hard-code time for automation, or provide server time. Defaults to local Unity time.")]
[@DecoratedField, SerializeField]
internal TimeProvider _TimeProvider;
[Tooltip("Whether to override the automatic detection of framebuffer HDR rendering (BIRP only).\n\nRendering using HDR formats is optional, but there is no way for us to determine if HDR rendering is enabled in the Graphics Settings. We make an educated based on which platform is the target. If you see rendering issues, try disabling this.\n\n This has nothing to do with having an HDR monitor.")]
[@Predicated(RenderPipeline.Legacy, hide: true)]
[@GenerateAPI]
[@DecoratedField, SerializeField]
bool _OverrideRenderHDR;
[Tooltip("Force HDR format usage (BIRP only).\n\nIf enabled, we assume the framebuffer is an HDR format, otherwise an LDR format.")]
[@Predicated(RenderPipeline.Legacy, hide: true)]
[@Predicated(nameof(_OverrideRenderHDR))]
[@GenerateAPI]
[@DecoratedField, SerializeField]
bool _RenderHDR = true;
[@Group("Environment", Group.Style.Accordian)]
[Tooltip("Base wind speed in km/h.\n\nControls wave conditions. Can be overridden on Shape* components.")]
[@Range(0, k_MaximumWindSpeedKPH, scale: 2f)]
[Tooltip("Uses a provided WindZone as the source of global wind.\n\nIt must be directional. Wind speed units are presumed to be in m/s.")]
[@GenerateAPI]
[@DecoratedField, SerializeField]
WindZone _WindZone;
[Tooltip("Whether to override the given wind zone's wind speed.")]
[@Predicated(nameof(_WindZone), hide: true)]
[@InlineToggle, SerializeField]
bool _OverrideWindZoneWindSpeed;
[Tooltip("Base wind speed in km/h.\n\nControls wave conditions. Can be overridden on Shape* components.")]
[@Predicated(typeof(WaterRenderer), nameof(WindSpeedOverriden), inverted: true, hide: true)]
[@ShowComputedProperty(nameof(WindSpeed))]
[@Range(0, k_MaximumWindSpeedKPH, scale: 2f)]
[@GenerateAPI(Getter.Custom)]
[SerializeField]
internal float _WindSpeed = 10f;
[Tooltip("Whether to override the given wind zone's wind direction.")]
[@Predicated(nameof(_WindZone), hide: true)]
[@InlineToggle, SerializeField]
bool _OverrideWindZoneWindDirection;
[Tooltip("Base wind direction in degrees.\n\nControls wave conditions. Can be overridden on Shape* components.")]
[@Predicated(typeof(WaterRenderer), nameof(WindDirectionOverriden), inverted: true, hide: true)]
[@ShowComputedProperty(nameof(WindDirection))]
[@Range(-180, 180)]
[@GenerateAPI(Getter.Custom)]
[SerializeField]
internal float _WindDirection;
[Tooltip("Whether to override the given wind zone's wind turbulence.")]
[@Predicated(nameof(_WindZone), hide: true)]
[@InlineToggle, SerializeField]
bool _OverrideWindZoneWindTurbulence;
[Tooltip("Base wind turbulence.\n\nControls wave conditions. Can be overridden on ShapeFFT components.")]
[@Predicated(typeof(WaterRenderer), nameof(WindTurbulenceOverriden), inverted: true, hide: true)]
[@ShowComputedProperty(nameof(WindTurbulence))]
[@Range(0, 1)]
[@GenerateAPI(Getter.Custom)]
[SerializeField]
internal float _WindTurbulence = 0.145f;
[@Space(10)]
[Tooltip("Provide your own gravity value instead of Physics.gravity.")]
[@GenerateAPI]
[@DecoratedField, SerializeField]
[@InlineToggle, SerializeField]
bool _OverrideGravity;
[@Label("Gravity")]
@@ -71,50 +113,47 @@ namespace WaveHarmonic.Crest
[SerializeField]
float _GravityMultiplier = 1f;
[@Space(10)]
[Tooltip("The primary light that affects the water.\n\nSetting this is optional. This should be a directional light. Defaults to RenderSettings.sun.")]
[@GenerateAPI(Getter.Custom)]
[@DecoratedField, SerializeField]
Light _PrimaryLight;
[@Group("Surface Renderer", Group.Style.Accordian)]
#if !d_Crest_LegacyUnderwater
[@Group("Rendering", Group.Style.Accordian)]
#else
[HideInInspector]
#endif
[Tooltip("The water chunk renderers will have this layer.")]
[@Layer]
[Tooltip("When in the render pipeline the water is rendered.\n\nDefault is the old behaviour which is controlled by Unity.\n\nBefore Transparency has advantages like being compatible with soft particles, refractive shaders, and possibly third-party atmospheric fog.")]
[@GenerateAPI]
[SerializeField]
int _Layer = 4; // Water
[Tooltip("Material to use for the water surface.")]
[@AttachMaterialEditor]
[@MaterialField("Crest/Water", name: "Water", title: "Create Water Material")]
[@GenerateAPI]
[SerializeField]
internal Material _Material = null;
[Tooltip("Underwater will copy from this material if set.\n\nUseful for overriding properties for the underwater effect. To see what properties can be overriden, see the disabled properties on the underwater material. This does not affect the surface.")]
[@AttachMaterialEditor]
[@MaterialField("Crest/Water", name: "Water (Below)", title: "Create Water Material", parent: "_Material")]
[@GenerateAPI]
[SerializeField]
internal Material _VolumeMaterial = null;
[Tooltip("Template for water chunks as a prefab.\n\nThe only requirements are that the prefab must contain a MeshRenderer at the root and not a MeshFilter or WaterChunkRenderer. MR values will be overwritten where necessary and the prefabs are linked in edit mode.")]
[@PrefabField(title: "Create Chunk Prefab", name: "Water Chunk")]
[SerializeField]
internal GameObject _ChunkTemplate;
[@DecoratedField, SerializeField]
WaterInjectionPoint _InjectionPoint;
#if !d_Crest_LegacyUnderwater
[@Space(10)]
#else
[@Group("Rendering", Group.Style.Accordian)]
#endif
[Tooltip("Have the water surface cast shadows for albedo (both foam and custom).")]
[@Predicated(RenderPipeline.Legacy, inverted: true, hide: true)]
[@Label("Color Texture")]
[Tooltip("Whether to write the water surface color to the color/opaque texture.\n\nThis is likely only beneficial if the water injection point is before transparency, and there are shaders which need it (like refraction).")]
[@Predicated(nameof(_InjectionPoint), inverted: false, nameof(WaterInjectionPoint.Default))]
[@GenerateAPI(Getter.Custom)]
[@DecoratedField, SerializeField]
internal bool _CastShadows;
internal bool _WriteToColorTexture = true;
[@Label("Depth Texture")]
[Tooltip("Whether to write the water surface depth to the depth texture.\n\nThe water surface writes to the depth buffer, but Unity does not copy it to the depth texture for post-processing effects like Depth of Field (or refraction). This will copy the depth buffer to the depth texture.\n\nIf the water injection point is in the transparent pass, be wary that it will include all transparent objects that write to depth. Furthermore, other third parties may already be doing this, and we do not check whether it is necessary to copy or not.\n\nThis feature has a considerable overhead if using the built-in render pipeline, as it requires rendering the surface depth another time.")]
[@Predicated(nameof(_Surface) + "." + nameof(SurfaceRenderer._Enabled))]
[@GenerateAPI(Getter.Custom)]
[@DecoratedField, SerializeField]
internal bool _WriteToDepthTexture = true;
[@Label("Motion Vectors")]
[Tooltip("Whether to enable motion vector support.")]
[@Predicated(RenderPipeline.Legacy, inverted: true, hide: true)]
#if !UNITY_6000_0_OR_NEWER
[@Predicated(RenderPipeline.Universal, inverted: true, hide: true)]
#endif
@@ -122,36 +161,28 @@ namespace WaveHarmonic.Crest
[@DecoratedField, SerializeField]
internal bool _WriteMotionVectors = true;
[Tooltip("Whether to write the water surface depth to the depth texture (URP only).\n\nThe water surface writes to the depth buffer, but Unity does not copy it to the depth texture for post-processing effects like Depth of Field. This will copy the depth buffer to the depth texture.\n\nBe wary that it will include all transparent objects that write to depth. Furthermore, other third parties may already be doing this, and we do not check whether it is necessary to copy or not.")]
[@Predicated(RenderPipeline.Universal, hide: true)]
[@Space(10)]
[Tooltip("Whether to override the automatic detection of framebuffer HDR rendering (BIRP only).\n\nRendering using HDR formats is optional, but there is no way for us to determine if HDR rendering is enabled in the Graphics Settings. We make an educated based on which platform is the target. If you see rendering issues, try disabling this.\n\n This has nothing to do with having an HDR monitor.")]
[@Predicated(RenderPipeline.Legacy, hide: true)]
[@GenerateAPI]
[@InlineToggle, SerializeField]
bool _OverrideRenderHDR;
[Tooltip("Force HDR format usage (BIRP only).\n\nIf enabled, we assume the framebuffer is an HDR format, otherwise an LDR format.")]
[@Predicated(RenderPipeline.Legacy, hide: true)]
[@Predicated(nameof(_OverrideRenderHDR))]
[@GenerateAPI]
[@DecoratedField, SerializeField]
internal bool _WriteToDepthTexture = true;
bool _RenderHDR = true;
[@Heading("Culling")]
[Tooltip("Whether 'Water Body' components will cull the water tiles.\n\nDisable if you want to use the 'Material Override' feature and still have an ocean.")]
[@GenerateAPI]
[@DecoratedField, SerializeField]
bool _WaterBodyCulling = true;
[@Group(isCustomFoldout: true)]
[Tooltip("How many frames to distribute the chunk bounds calculation.\n\nThe chunk bounds are calculated per frame to ensure culling is correct when using inputs that affect displacement. Some performance can be saved by distributing the load over several frames. The higher the frames, the longer it will take - lowest being instant.")]
[@Range(1, 30, Range.Clamp.Minimum)]
[@GenerateAPI]
[SerializeField]
int _TimeSliceBoundsUpdateFrameCount = 1;
[@Heading("Advanced")]
[Tooltip("How to handle self-intersections of the water surface.\n\nThey can be caused by choppy waves which can cause a flipped underwater effect. When not using the portals/volumes, this fix is only applied when within 2 metres of the water surface. Automatic will disable the fix if portals/volumes are used which is the recommend setting.")]
[@DecoratedField, SerializeField]
SurfaceSelfIntersectionFixMode _SurfaceSelfIntersectionFixMode = SurfaceSelfIntersectionFixMode.Automatic;
[Tooltip("Whether to allow sorting using the render queue.\n\nIf you need to change the minor part of the render queue (eg +100), then enable this option. As a side effect, it will also disable the front-to-back rendering optimization for Crest. This option does not affect changing the major part of the render queue (eg AlphaTest, Transparent), as that is always allowed.\n\nRender queue sorting is required for some third-party integrations.")]
[@Predicated(RenderPipeline.HighDefinition, inverted: true, hide: true)]
[@GenerateAPI]
[@DecoratedField, SerializeField]
bool _AllowRenderQueueSorting;
[Tooltip("The water surface renderer.")]
[@GenerateAPI(Setter.None)]
[@DecoratedField(isCustomFoldout: true), SerializeReference]
SurfaceRenderer _Surface = new();
[@Group("Level of Detail", Group.Style.Accordian)]
@@ -174,7 +205,7 @@ namespace WaveHarmonic.Crest
[@Range(2, Lod.k_MaximumSlices)]
[@GenerateAPI(name: "LodLevels")]
[SerializeField]
int _Slices = 7;
int _Slices = 9;
[@Label("Resolution")]
[Tooltip("The resolution of the various water LOD data.\n\nThis includes mesh density, displacement textures, foam data, dynamic wave simulation, etc. Sets the 'detail' present in the water - larger values give more detail at increased run-time expense. This value can be overriden per LOD in their respective settings except for Animated Waves which is tied to this value.")]
@@ -204,6 +235,12 @@ namespace WaveHarmonic.Crest
[@DecoratedField, SerializeField]
Transform _Viewpoint;
[@Label("Displacement Correction")]
[Tooltip("Keep the center of detail from drifting from the viewpoint.\n\nLarge horizontal displacement can displace the center of detail. This uses queries to keep the center of detail aligned.")]
[@GenerateAPI]
[@DecoratedField, SerializeField]
bool _CenterOfDetailDisplacementCorrection = true;
[Tooltip("Also checks terrain height when determining the scale.\n\nThe scale is changed based on the viewer's height above the water surface. This can be a problem with varied water level, as the viewer may not be directly over the higher water level leading to a height difference, and thus incorrect scale.")]
[Predicated(nameof(_Viewpoint), inverted: true)]
[@GenerateAPI]
@@ -307,6 +344,14 @@ namespace WaveHarmonic.Crest
internal UnderwaterRenderer _Underwater = new();
[@Group(isCustomFoldout: true)]
[Tooltip("The meniscus module.")]
[@GenerateAPI(Setter.None)]
[@DecoratedField(isCustomFoldout: true), SerializeReference]
internal Meniscus _Meniscus = new();
#if !d_CrestPortals
// Hide if package is not present. Fallback to dummy script.
[HideInInspector]
@@ -372,18 +417,6 @@ namespace WaveHarmonic.Crest
public bool _DestroyResourcesInOnDisable;
#if CREST_DEBUG
[Tooltip("Whether to disable chunk generation.")]
[@DecoratedField, SerializeField]
public bool _DisableChunks;
[Tooltip("Whether to generate water geometry tiles uniformly (with overlaps).")]
[@DecoratedField, SerializeField]
public bool _UniformTiles;
[Tooltip("Disable generating a wide strip of triangles at the outer edge to extend water to edge of view frustum.")]
[@DecoratedField, SerializeField]
public bool _DisableSkirt;
[@DecoratedField, SerializeField]
public bool _DrawLodOutline;
@@ -416,10 +449,6 @@ namespace WaveHarmonic.Crest
[@Heading("Server")]
[Tooltip("Emulate batch mode which models running without a display (but with a GPU available). Equivalent to running standalone build with -batchmode argument.")]
[@DecoratedField, SerializeField]
public bool _ForceBatchMode;
[Tooltip("Emulate running on a client without a GPU. Equivalent to running standalone with -nographics argument.")]
[@DecoratedField, SerializeField]
public bool _ForceNoGraphics;