Skip to content
Merged
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
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added toggle "Disable Global Mip Bias" in Sample Texture 2D and Sample Texture 2D array node. This checkbox disables the runtimes automatic Mip Bias, which for instance can be activated during dynamic resolution scaling.
- Added `Sprite` option to Main Preview, which is similar to `Quad` but does not allow rotation. `Sprite` is used as the default preview for URP Sprite shaders.
- Added visible errors for invalid stage capability connections to shader graph.
- Added a ShaderGraph animated preview framerate throttle.

### Changed
- Properties and Keywords are no longer separated by type on the blackboard. Categories allow for any combination of properties and keywords to be grouped together as the user defines.
Expand Down
37 changes: 34 additions & 3 deletions com.unity.shadergraph/Editor/Drawing/PreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class PreviewManager : IDisposable
HashSet<PreviewRenderData> m_PreviewsToDraw = new HashSet<PreviewRenderData>(); // previews to re-render the texture (either because shader compile changed or property changed)
HashSet<PreviewRenderData> m_TimedPreviews = new HashSet<PreviewRenderData>(); // previews that are dependent on a time node -- i.e. animated / need to redraw every frame

double m_LastTimedUpdateTime = 0.0f;

bool m_TopologyDirty; // indicates topology changed, used to rebuild timed node list and preview type (2D/3D) inheritance.

HashSet<BlockNode> m_MasterNodeTempBlocks = new HashSet<BlockNode>(); // temp blocks used by the most recent master node preview generation.
Expand Down Expand Up @@ -451,8 +453,36 @@ void AssignPerMaterialPreviewProperties(Material mat, List<PreviewProperty> perM
}
}

bool TimedNodesShouldUpdate(EditorWindow editorWindow)
{
// get current screen FPS, clamp to what we consider a valid range
// this is probably not accurate for multi-monitor.. but should be relevant to at least one of the monitors
double monitorFPS = Screen.currentResolution.refreshRate + 1.0; // +1 to round up, since it is an integer and rounded down
if (Double.IsInfinity(monitorFPS) || Double.IsNaN(monitorFPS))
monitorFPS = 60.0f;
monitorFPS = Math.Min(monitorFPS, 144.0);
monitorFPS = Math.Max(monitorFPS, 30.0);

var curTime = EditorApplication.timeSinceStartup;
var deltaTime = curTime - m_LastTimedUpdateTime;
bool isFocusedWindow = (EditorWindow.focusedWindow == editorWindow);

// we throttle the update rate, based on whether the window is focused and if unity is active
const double k_AnimatedFPS_WhenNotFocused = 10.0;
const double k_AnimatedFPS_WhenInactive = 2.0;
double maxAnimatedFPS =
(UnityEditorInternal.InternalEditorUtility.isApplicationActive ?
(isFocusedWindow ? monitorFPS : k_AnimatedFPS_WhenNotFocused) :
k_AnimatedFPS_WhenInactive);

bool update = (deltaTime > (1.0 / maxAnimatedFPS));
if (update)
m_LastTimedUpdateTime = curTime;
return update;
}

private static readonly ProfilerMarker RenderPreviewsMarker = new ProfilerMarker("RenderPreviews");
public void RenderPreviews(bool requestShaders = true)
public void RenderPreviews(EditorWindow editorWindow, bool requestShaders = true)
{
using (RenderPreviewsMarker.Auto())
using (var renderList2D = PooledList<PreviewRenderData>.Get())
Expand Down Expand Up @@ -486,10 +516,11 @@ public void RenderPreviews(bool requestShaders = true)
CollectPreviewProperties(m_NodesPropertyChanged, perMaterialPreviewProperties);
m_NodesPropertyChanged.Clear();

// timed nodes change every frame, so must be drawn
// timed nodes are animated, so they should be updated regularly (but not necessarily on every update)
// (m_TimedPreviews has been pre-propagated downstream)
// HOWEVER they do not need to collect properties. (the only property changing is time..)
m_PreviewsToDraw.UnionWith(m_TimedPreviews);
if (TimedNodesShouldUpdate(editorWindow))
m_PreviewsToDraw.UnionWith(m_TimedPreviews);

ForEachNodesPreview(nodesToDraw, p => m_PreviewsToDraw.Add(p));

Expand Down
9 changes: 0 additions & 9 deletions com.unity.shadergraph/Editor/Drawing/PreviewRate.cs

This file was deleted.

3 changes: 0 additions & 3 deletions com.unity.shadergraph/Editor/Drawing/PreviewRate.cs.meta

This file was deleted.

4 changes: 2 additions & 2 deletions com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage
m_AssetName = graphName;
m_MessageManager = messageManager;
previewManager = new PreviewManager(graph, messageManager);
previewManager.RenderPreviews(false);
previewManager.RenderPreviews(m_EditorWindow, false);

styleSheets.Add(Resources.Load<StyleSheet>("Styles/GraphEditorView"));
var serializedSettings = EditorUserSettings.GetConfigValue(k_UserViewSettings);
Expand Down Expand Up @@ -669,7 +669,7 @@ public void HandleGraphChanges(bool wasUndoRedoPerformed)
m_ColorManager.UpdateNodeViews(nodeList);
}

previewManager.RenderPreviews();
previewManager.RenderPreviews(m_EditorWindow);

if (wasUndoRedoPerformed || m_InspectorView.doesInspectorNeedUpdate)
m_InspectorView.Update();
Expand Down