Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,609 changes: 2,602 additions & 7 deletions crest/Assets/Crest/Crest-Examples/Main/Scenes/main.unity

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: HeightTest 1
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 0, g: 1, b: 0.19270587, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: HeightTest
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 1, g: 0, b: 0, a: 0.8}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
/// </summary>
public class OceanSampleHeightDemo : MonoBehaviour
{
[Tooltip("Some query systems return results with latency. This applies a correction to compensate.")]
public bool _compensateLatency = true;

SampleHeightHelper _sampleHeightHelper = new SampleHeightHelper();

void Update()
Expand All @@ -18,7 +21,10 @@ void Update()
var r = transform.lossyScale.magnitude;
_sampleHeightHelper.Init(transform.position, 2f * r);

if (_sampleHeightHelper.Sample(out var height))
float height;
bool result = _compensateLatency ? _sampleHeightHelper.SampleWithLantencyCompensation(out height) : _sampleHeightHelper.Sample(out height);

if (result)
{
var pos = transform.position;
pos.y = height;
Expand Down
5 changes: 5 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/Collision/CollProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public interface ICollProvider
/// </summary>
void UpdateQueries();

/// <summary>
/// For query providers where there is one or more frames latency, this will adjust the height to compensate
/// </summary>
float CompensateLatency(float i_height, float i_velocity, float i_frameTime);

/// <summary>
/// On destroy, to cleanup resources
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public void CleanUp()
{
}

public float CompensateLatency(float i_height, float i_velocity, float i_frameTime)
{
return i_height;
}

public readonly static CollProviderNull Instance = new CollProviderNull();
}
}
6 changes: 6 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/Collision/QueryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ public bool RetrieveSucceeded(int queryStatus)
return (queryStatus & (int)QueryStatus.RetrieveFailed) == 0;
}

public float CompensateLatency(float i_height, float i_velocity, float i_frameTime)
{
// +1 to account for current frame which has not been sent as a request yet
return i_height + (RequestCount + 1f) * i_velocity * i_frameTime;
}

public int ResultGuidCount => _resultSegments != null ? _resultSegments.Count : 0;

public int RequestCount => _requests != null ? _requests.Count : 0;
Expand Down
27 changes: 27 additions & 0 deletions crest/Assets/Crest/Crest/Scripts/Collision/SamplingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ public bool Sample(out float o_height)
return true;
}

/// <summary>
/// Call this to do the query. Can be called only once after Init(). This variant compensates for
/// latency in the query system if present.
/// </summary>
public bool SampleWithLantencyCompensation(out float o_height)
{
var collProvider = OceanRenderer.Instance?.CollisionProvider;
if (collProvider == null)
{
o_height = 0f;
return false;
}

var status = collProvider.Query(GetHashCode(), _minLength, _queryPos, _queryResult, null, _queryResultVel);

if (!collProvider.RetrieveSucceeded(status))
{
o_height = OceanRenderer.Instance.SeaLevel;
return false;
}

o_height = _queryResult[0].y + OceanRenderer.Instance.SeaLevel;
o_height = collProvider.CompensateLatency(o_height, _queryResultVel[0].y, Time.deltaTime);

return true;
}

public bool Sample(out float o_height, out Vector3 o_normal)
{
var collProvider = OceanRenderer.Instance?.CollisionProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,11 @@ public void UpdateQueries()
public void CleanUp()
{
}

public float CompensateLatency(float i_height, float i_velocity, float i_frameTime)
{
return i_height;
}
}

#if UNITY_EDITOR
Expand Down