Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge direction visualization via shader #802

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions Assets/SEE/Game/Operator/EdgeOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public partial class EdgeOperator : GraphElementOperator<(Color start, Color end
/// </summary>
private SEESpline spline;

/// Shader property that enables or disables the edge direction (data flow) animation.
tinxx marked this conversation as resolved.
Show resolved Hide resolved
private static readonly int EdgeFlowEnabledProperty = Shader.PropertyToID("_EdgeFlowEnabled");

#region Public API

/// <summary>
Expand Down Expand Up @@ -149,13 +152,9 @@ public IOperationCallback<Action> ShowOrHide(bool show, EdgeAnimationKind animat
/// <param name="enable">Enable or disable animation.</param>
public void AnimateDataFlow(bool enable = true)
{
if (gameObject.TryGetComponent<MeshRenderer>(out MeshRenderer meshRenderer))
{
meshRenderer.material.SetFloat("_EdgeFlowEnabled", enable ? 1.0f : 0.0f);
}
else
if (gameObject.TryGetComponentOrLog(out MeshRenderer meshRenderer))
{
Debug.LogWarning($"No MeshRenderer found to enable data flow animation on: {gameObject.FullName()}");
meshRenderer.material.SetFloat(EdgeFlowEnabledProperty, enable ? 1.0f : 0.0f);
}
}

Expand Down
15 changes: 12 additions & 3 deletions Assets/SEE/GameObjects/SEESpline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ public Material MeshMaterial
}
}

/// Shader property that defines the (start) color.
private static readonly int ColorProperty = Shader.PropertyToID("_Color");

/// Shader property that defines the end color of the color gradient.
private static readonly int EndColorProperty = Shader.PropertyToID("_EndColor");

/// Shader property that enables or disables the color gradient.
private static readonly int ColorGradientEnabledProperty = Shader.PropertyToID("_ColorGradientEnabled");
tinxx marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Called by Unity when an instance of this class is being loaded.
/// </summary>
Expand Down Expand Up @@ -584,9 +593,9 @@ protected virtual void UpdateMaterial()
return;
}

meshRenderer.material.SetColor("_Color", gradientColors.start);
meshRenderer.material.SetColor("_EndColor", gradientColors.end);
meshRenderer.material.SetFloat("_ColorGradientEnabled", 1.0f);
meshRenderer.material.SetColor(ColorProperty, gradientColors.start);
meshRenderer.material.SetColor(EndColorProperty, gradientColors.end);
meshRenderer.material.SetFloat(ColorGradientEnabledProperty, 1.0f);
}

/// <summary>
Expand Down
Loading