You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
The first series of changes relate to modifying the way that SGraphNode* inheritants are created. Previously, NodeFactory was responsible of creating the SGraphNode* inheritants based on some runtime type checking (which basically means a series of if statements checking if the passed in pointer is of a certain child class type). Now, the UMaterialGraph* inheritants (the controller classes in the MVC paradigm of the material graph) are responsible for creating their own UI components (SGraphNode* inheritants). This just means that we now polymorphically create the proper SGraphNode* for the given UMaterialGraph* inheritant. This refactor allows us to more flexibly create a variety of nodes types instead of relying on SGraphNodeMaterialBase as a one size fits all solution, leading to the new HLSL custom node. Previously, this node didn't support showing the syntax-highlighted code inline in the node itself. Because we now use polymorphism to create the nodes, it was very easy to create new UMaterialGraph* and SGraphNode* inheritants to support this new change. Other changes which relate to propagating changes (to affect previews) in MaterialGraphNode.cpp are needed because there previously wasn't the mechanism to do so (which may have been a bug). For instance, suppose you had a constant vector3 feeding into a custom HLSL node which just outputs the color coming from that constant vector3 node. It would be obvious that changing the vector3, requires a preview update of the HLSL node. However, that wouldn't happen - the preview on the HLSL node just stayed the same. These changes addresses that issue. There is one last series of changes which relates to collapsing the HLSL code in the node. We want to make sure that this change doesn't mess up the layouts of artists' already made material graphs which use the custom HLSL node. In order to address this, we added the ability to collapse the code in order to hide it. Furthermore, we had to make sure that projects which previously used a custom HLSL node, have the code collapsed by default (because it wasn't there before). However, creating a new HLSL node once this change comes in, would yield an uncollapsed node. The collapsing of nodes uses the "Advanced Pins" chevron/collapser which doesn't save its state after saving and exiting the material. It was crucial, in order to preserve the layout of the material graph, that the saving happens. However, previously, the only way to save state, was to go through a recompile/regeneration of the previews. Therefore, it was necessary to add a special function in the material editor utilities which would just mark the material as dirty such that states like whether the code was collapsed save throughout sessions. #jira UE-146779 #rb jason.nadro [CL 26677757 by luc rosenzweig in ue5-main branch]
146 lines
4.8 KiB
C++
146 lines
4.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Internationalization/Text.h"
|
|
#include "Layout/Visibility.h"
|
|
#include "Math/UnrealMathSSE.h"
|
|
#include "Math/Vector2D.h"
|
|
#include "Rendering/RenderingCommon.h"
|
|
#include "SGraphNode.h"
|
|
#include "SNodePanel.h"
|
|
#include "Styling/SlateTypes.h"
|
|
#include "Templates/SharedPointer.h"
|
|
#include "Textures/SlateShaderResource.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
|
|
class FMaterialRenderProxy;
|
|
class FRHICommandListImmediate;
|
|
class FSlateRect;
|
|
class FWidgetStyle;
|
|
class SGraphPin;
|
|
class SOverlay;
|
|
class SVerticalBox;
|
|
class SWidget;
|
|
class UMaterialGraphNode;
|
|
struct FGeometry;
|
|
struct FSlateBrush;
|
|
|
|
typedef TSharedPtr<class FPreviewElement, ESPMode::ThreadSafe> FThreadSafePreviewPtr;
|
|
|
|
class FPreviewViewport : public ISlateViewport
|
|
{
|
|
public:
|
|
FPreviewViewport(class UMaterialGraphNode* InNode);
|
|
~FPreviewViewport();
|
|
|
|
// ISlateViewport interface
|
|
virtual void OnDrawViewport( const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, class FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) override;
|
|
virtual FIntPoint GetSize() const override;
|
|
virtual class FSlateShaderResource* GetViewportRenderTargetTexture() const override {return NULL;}
|
|
virtual bool RequiresVsync() const override {return false;}
|
|
|
|
/** Material node to get expression preview from */
|
|
UMaterialGraphNode* MaterialNode;
|
|
/** Custom Slate Element to display the preview */
|
|
FThreadSafePreviewPtr PreviewElement;
|
|
private:
|
|
/**
|
|
* Updates the expression preview render proxy from a graph node
|
|
*/
|
|
void UpdatePreviewNodeRenderProxy();
|
|
};
|
|
|
|
class FPreviewElement : public ICustomSlateElement
|
|
{
|
|
public:
|
|
FPreviewElement();
|
|
~FPreviewElement();
|
|
|
|
/**
|
|
* Sets up the canvas for rendering
|
|
*
|
|
* @param InCanvasRect Size of the canvas tile
|
|
* @param InClippingRect How to clip the canvas tile
|
|
* @param InGraphNode The graph node for the material preview
|
|
* @param bInIsRealtime Whether preview is using realtime values
|
|
*
|
|
* @return Whether there is anything to render
|
|
*/
|
|
bool BeginRenderingCanvas( const FIntRect& InCanvasRect, const FIntRect& InClippingRect, UMaterialGraphNode* InGraphNode, bool bInIsRealtime );
|
|
|
|
/**
|
|
* Updates the expression preview render proxy from a graph node on the render thread
|
|
*/
|
|
void UpdateExpressionPreview(UMaterialGraphNode* PreviewNode);
|
|
private:
|
|
/**
|
|
* ICustomSlateElement interface
|
|
*/
|
|
virtual void DrawRenderThread(FRHICommandListImmediate& RHICmdList, const void* InWindowBackBuffer) override;
|
|
|
|
private:
|
|
/** Render target that the canvas renders to */
|
|
class FSlateMaterialPreviewRenderTarget* RenderTarget;
|
|
/** Render proxy for the expression preview */
|
|
FMaterialRenderProxy* ExpressionPreview;
|
|
/** Whether preview is using realtime values */
|
|
bool bIsRealtime;
|
|
};
|
|
|
|
class GRAPHEDITOR_API SGraphNodeMaterialBase : public SGraphNode
|
|
{
|
|
public:
|
|
SLATE_BEGIN_ARGS(SGraphNodeMaterialBase){}
|
|
SLATE_END_ARGS()
|
|
|
|
void Construct(const FArguments& InArgs, class UMaterialGraphNode* InNode);
|
|
|
|
// SGraphNode interface
|
|
virtual void CreatePinWidgets() override;
|
|
// End of SGraphNode interface
|
|
|
|
// SNodePanel::SNode interface
|
|
virtual void MoveTo(const FVector2D& NewPosition, FNodeSet& NodeFilter, bool bMarkDirty = true) override;
|
|
// End of SNodePanel::SNode interface
|
|
|
|
UMaterialGraphNode* GetMaterialGraphNode() const {return MaterialNode;}
|
|
|
|
/* Populate a meta data tag with information about this graph node */
|
|
virtual void PopulateMetaTag(class FGraphNodeMetaData* TagMeta) const override;
|
|
|
|
protected:
|
|
// SGraphNode interface
|
|
virtual void AddPin( const TSharedRef<SGraphPin>& PinToAdd ) override;
|
|
virtual void CreateBelowPinControls(TSharedPtr<SVerticalBox> MainBox) override;
|
|
virtual void SetDefaultTitleAreaWidget(TSharedRef<SOverlay> DefaultTitleAreaWidget) override;
|
|
virtual TSharedRef<SWidget> CreateNodeContentArea() override;
|
|
virtual void OnAdvancedViewChanged(const ECheckBoxState NewCheckedState) override;
|
|
// End of SGraphNode interface
|
|
|
|
/** Creates a preview viewport if necessary */
|
|
TSharedRef<SWidget> CreatePreviewWidget();
|
|
|
|
/** Returns visibility of Expression Preview viewport */
|
|
EVisibility ExpressionPreviewVisibility() const;
|
|
|
|
/** Returns text to over lay over the expression preview viewport */
|
|
FText ExpressionPreviewOverlayText() const;
|
|
|
|
/** Show/hide Expression Preview */
|
|
void OnExpressionPreviewChanged( const ECheckBoxState NewCheckedState );
|
|
|
|
/** hidden == unchecked, shown == checked */
|
|
ECheckBoxState IsExpressionPreviewChecked() const;
|
|
|
|
/** Up when shown, down when hidden */
|
|
const FSlateBrush* GetExpressionPreviewArrow() const;
|
|
|
|
protected:
|
|
/** Slate viewport for rendering preview via custom slate element */
|
|
TSharedPtr<FPreviewViewport> PreviewViewport;
|
|
|
|
/** Cached material graph node pointer to avoid casting */
|
|
UMaterialGraphNode* MaterialNode;
|
|
};
|