From e2867399dbb341ac57ae49d7cf922035a8e9da20 Mon Sep 17 00:00:00 2001 From: Huw Bowles Date: Wed, 21 Aug 2019 21:01:41 +0100 Subject: [PATCH] Add dyn waves from texture --- .../BoatDev/Scenes/threeboats.unity | 10 ++- .../Scripts/LodData/LodDataMgrPersistent.cs | 2 +- .../Scripts/LodData/RegisterLodDataInput.cs | 1 + .../OceanInputs/DynWavesAddBump.shader | 2 +- .../OceanInputs/DynWavesAddFromTex.shader | 62 +++++++++++++++++++ .../DynWavesAddFromTex.shader.meta | 9 +++ 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader create mode 100644 crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader.meta diff --git a/crest/Assets/Crest/Crest-Examples/BoatDev/Scenes/threeboats.unity b/crest/Assets/Crest/Crest-Examples/BoatDev/Scenes/threeboats.unity index bc064591c..96c4c8a22 100644 --- a/crest/Assets/Crest/Crest-Examples/BoatDev/Scenes/threeboats.unity +++ b/crest/Assets/Crest/Crest-Examples/BoatDev/Scenes/threeboats.unity @@ -642,11 +642,11 @@ MonoBehaviour: _timeProvider: {fileID: 0} _material: {fileID: 2100000, guid: 9def92ac79181fe41b238e91663f0fad, type: 2} _layerName: Water - _windDirectionAngle: 0 _gravityMultiplier: 1 _minTexelsPerWave: 3 _minScale: 8 _maxScale: 256 + _dropDetailHeightBasedOnWaves: 0.2 _lodDataResolution: 256 _geometryDownSampleFactor: 2 _lodCount: 8 @@ -861,7 +861,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1680820176 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1029,9 +1029,15 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _spectrum: {fileID: 11400000, guid: 691aad324f2d2be4abf8123c36963da5, type: 2} + _windDirectionAngle: 0 _componentsPerOctave: 8 _weight: 1 _randomSeed: 0 + _evaluateSpectrumAtRuntime: 1 + _wavelengths: [] + _amplitudes: [] + _angleDegs: [] + _phases: [] _directTowardsPoint: 0 _pointPositionXZ: {x: 0, y: 0} _pointRadii: {x: 100, y: 200} diff --git a/crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrPersistent.cs b/crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrPersistent.cs index 469c441e5..9f265ff07 100644 --- a/crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrPersistent.cs +++ b/crest/Assets/Crest/Crest/Scripts/LodData/LodDataMgrPersistent.cs @@ -26,7 +26,7 @@ public abstract class LodDataMgrPersistent : LodDataMgr float _substepDtPrevious = 1f / 60f; - static int sp_SimDeltaTime = Shader.PropertyToID("_SimDeltaTime"); + public static int sp_SimDeltaTime = Shader.PropertyToID("_SimDeltaTime"); static int sp_SimDeltaTimePrev = Shader.PropertyToID("_SimDeltaTimePrev"); protected override void Start() diff --git a/crest/Assets/Crest/Crest/Scripts/LodData/RegisterLodDataInput.cs b/crest/Assets/Crest/Crest/Scripts/LodData/RegisterLodDataInput.cs index d564482a5..c0bbfc99e 100644 --- a/crest/Assets/Crest/Crest/Scripts/LodData/RegisterLodDataInput.cs +++ b/crest/Assets/Crest/Crest/Scripts/LodData/RegisterLodDataInput.cs @@ -58,6 +58,7 @@ public void Draw(CommandBuffer buf, float weight, int isTransition) if (_renderer && weight > 0f) { _materials[isTransition].SetFloat(sp_Weight, weight); + _materials[isTransition].SetFloat(LodDataMgrPersistent.sp_SimDeltaTime, OceanRenderer.Instance.DeltaTimeDynamics); buf.DrawRenderer(_renderer, _materials[isTransition]); } diff --git a/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddBump.shader b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddBump.shader index 37bcc41ea..f9df12918 100644 --- a/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddBump.shader +++ b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddBump.shader @@ -7,7 +7,7 @@ Shader "Crest/Inputs/Dynamic Waves/Add Bump" Properties { _Amplitude( "Amplitude", float ) = 1 - _Radius( "Radius", float) = 3 + _Radius("Radius", float) = 3 } SubShader diff --git a/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader new file mode 100644 index 000000000..a8b5c2bec --- /dev/null +++ b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader @@ -0,0 +1,62 @@ +// Crest Ocean System + +// This file is subject to the MIT License as seen in the root of this folder structure (LICENSE) + +Shader "Crest/Inputs/Dynamic Waves/Add From Texture" +{ + Properties + { + _MainTex("Texture", 2D) = "white" {} + _Strength( "Strength", float ) = 1 + } + + SubShader + { + // base simulation runs on the Geometry queue, before this shader. + // this shader adds interaction forces on top of the simulation result. + Blend One One + + Pass + { + CGPROGRAM + #pragma vertex Vert + #pragma fragment Frag + + #include "UnityCG.cginc" + + sampler2D _MainTex; + + float4 _MainTex_ST; + float _Strength; + float _SimDeltaTime; + + struct Attributes + { + float3 positionOS : POSITION; + float2 uv : TEXCOORD0; + }; + + struct Varyings + { + float4 positionCS : SV_POSITION; + float2 uv : TEXCOORD0; + }; + + Varyings Vert(Attributes input) + { + Varyings o; + o.positionCS = UnityObjectToClipPos(input.positionOS); + o.uv = TRANSFORM_TEX(input.uv, _MainTex); + return o; + } + + float4 Frag(Varyings input) : SV_Target + { + // Integrate acceleration onto velocity + return float4(0.0, _SimDeltaTime*_Strength*tex2D(_MainTex, input.uv).x, 0.0, 0.0); + } + + ENDCG + } + } +} diff --git a/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader.meta b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader.meta new file mode 100644 index 000000000..f46ad7b78 --- /dev/null +++ b/crest/Assets/Crest/Crest/Shaders/OceanInputs/DynWavesAddFromTex.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c2a26b18708ad5944b30fc3e73a3ec34 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: