Add project files.

This commit is contained in:
2023-10-08 18:51:40 +02:00
commit 51cc9df14f
2249 changed files with 636804 additions and 0 deletions

View File

@@ -0,0 +1,692 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
namespace AmplifyShaderEditor
{
public enum eResizeAxis
{
X_AXIS,
Y_AXIS,
ALL
}
[Serializable]
public sealed class CommentaryNode : ParentNode, ISerializationCallbackReceiver
{
private const string InfoText = "Press Alt + Left Mouse Click/Drag to make all Comment node area interactable.\nDouble click on the Comment at the node body to modify it directly from there.";
private const string CommentaryTitle = "Comment";
private const float BORDER_SIZE_X = 50;
private const float BORDER_SIZE_Y = 50;
private const float MIN_SIZE_X = 100;
private const float MIN_SIZE_Y = 100;
private const float COMMENTARY_BOX_HEIGHT = 30;
private readonly Vector2 ResizeButtonPos = new Vector2( 1, 1 );
[SerializeField]
private string m_commentText = "Comment";
[SerializeField]
private string m_titleText = string.Empty;
[SerializeField]
private eResizeAxis m_resizeAxis = eResizeAxis.ALL;
[SerializeField]
private List<ParentNode> m_nodesOnCommentary = new List<ParentNode>();
private Dictionary<int, ParentNode> m_nodesOnCommentaryDict = new Dictionary<int, ParentNode>();
private bool m_reRegisterNodes = false;
[SerializeField]
private Rect m_resizeLeftIconCoords;
[SerializeField]
private Rect m_resizeRightIconCoords;
[SerializeField]
private Rect m_auxHeaderPos;
[SerializeField]
private Rect m_commentArea;
private Texture2D m_resizeIconTex;
private bool m_isResizingRight = false;
private bool m_isResizingLeft = false;
private Vector2 m_resizeStartPoint = Vector2.zero;
private string m_focusName = "CommentaryNode";
private bool m_focusOnTitle = false;
private bool m_graphDepthAnalized = false;
private bool m_checkCommentText = true;
private bool m_checkTitleText = true;
public Color m_frameColor = Color.white;
private List<int> m_nodesIds = new List<int>();
private bool m_checkContents = false;
private bool m_isEditing;
private bool m_stopEditing;
private bool m_startEditing;
private double m_clickTime;
private double m_doubleClickTime = 0.3;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
m_reorderLocked = true;
m_rmbIgnore = true;
m_defaultInteractionMode = InteractionMode.Both;
m_headerColor = UIUtils.GetColorFromCategory( "Commentary" );
m_connStatus = NodeConnectionStatus.Island;
m_textLabelWidth = 90;
}
protected override void OnUniqueIDAssigned()
{
base.OnUniqueIDAssigned();
m_focusName = CommentaryTitle + OutputId;
}
public void CreateFromSelectedNodes( Vector2 mousePosOnCanvasCoords, ParentNode[] selectedNodes )
{
if ( selectedNodes.Length == 0 )
{
m_position = new Rect( mousePosOnCanvasCoords, new Vector2( 100, 100 ) );
return;
}
Vector2 minPos = new Vector2( float.MaxValue, float.MaxValue );
Vector2 maxPos = new Vector2( float.MinValue, float.MinValue );
for ( int i = 0; i < selectedNodes.Length; i++ )
{
//Check min
if ( selectedNodes[ i ].Position.x < minPos.x )
minPos.x = selectedNodes[ i ].Position.x;
if ( selectedNodes[ i ].Position.y < minPos.y )
minPos.y = selectedNodes[ i ].Position.y;
//check max
float nodeXMax = selectedNodes[ i ].Position.x + selectedNodes[ i ].Position.width;
if ( nodeXMax > maxPos.x )
{
maxPos.x = nodeXMax;
}
float nodeYMax = selectedNodes[ i ].Position.y + selectedNodes[ i ].Position.height;
if ( nodeYMax > maxPos.y )
{
maxPos.y = nodeYMax;
}
//_nodesOnCommentary.Add( selectedNodes[ i ] );
//selectedNodes[ i ].OnNodeStoppedMovingEvent += NodeStoppedMoving;
AddNodeToCommentary( selectedNodes[ i ] );
}
Vector2 dims = maxPos - minPos + new Vector2( 2 * BORDER_SIZE_X, 2 * BORDER_SIZE_Y );
m_position = new Rect( minPos.x - BORDER_SIZE_X, minPos.y - BORDER_SIZE_Y, dims.x, dims.y );
}
public override void Move( Vector2 delta, bool snap )
{
if ( m_isResizingRight || m_isResizingLeft )
return;
base.Move( delta, snap );
for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
{
if ( !m_nodesOnCommentary[ i ].Selected )
{
m_nodesOnCommentary[ i ].RecordObject( Constants.UndoMoveNodesId );
m_nodesOnCommentary[ i ].Move( delta, snap );
}
}
}
public void NodeStoppedMoving( ParentNode node, bool testOnlySelected, InteractionMode useTargetInteraction )
{
if ( !m_position.Contains( node.Vec2Position ) && !m_position.Contains( node.Corner ) )
{
RemoveNode( node );
}
}
public void NodeDestroyed( ParentNode node )
{
RemoveNode( node );
}
public void RemoveNode( ParentNode node )
{
if ( m_nodesOnCommentaryDict.ContainsKey( node.UniqueId ) )
{
UIUtils.MarkUndoAction();
RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
node.RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
m_nodesOnCommentary.Remove( node );
m_nodesOnCommentaryDict.Remove( node.UniqueId );
node.OnNodeStoppedMovingEvent -= NodeStoppedMoving;
node.OnNodeDestroyedEvent -= NodeDestroyed;
node.CommentaryParent = -1;
}
}
public void RemoveAllNodes()
{
UIUtils.MarkUndoAction();
for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
{
RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
m_nodesOnCommentary[ i ].RecordObject( Constants.UndoRemoveNodeFromCommentaryId );
m_nodesOnCommentary[ i ].OnNodeStoppedMovingEvent -= NodeStoppedMoving;
m_nodesOnCommentary[ i ].OnNodeDestroyedEvent -= NodeDestroyed;
m_nodesOnCommentary[ i ].CommentaryParent = -1;
}
m_nodesOnCommentary.Clear();
m_nodesOnCommentaryDict.Clear();
}
public override void Destroy()
{
base.Destroy();
RemoveAllNodes();
}
public void AddNodeToCommentary( ParentNode node )
{
if( node.UniqueId == UniqueId )
return;
if ( !m_nodesOnCommentaryDict.ContainsKey( node.UniqueId ) )
{
bool addToNode = false;
if ( node.CommentaryParent < 0 )
{
addToNode = true;
if ( node.Depth <= m_depth )
{
ActivateNodeReordering( node.Depth );
}
}
else
{
CommentaryNode other = UIUtils.GetNode( node.CommentaryParent ) as CommentaryNode;
if ( other != null )
{
if ( other.Depth < Depth )
{
other.RemoveNode( node );
addToNode = true;
}
}
}
if ( addToNode )
{
UIUtils.MarkUndoAction();
RecordObject( Constants.UndoAddNodeToCommentaryId );
node.RecordObject( Constants.UndoAddNodeToCommentaryId );
m_nodesOnCommentary.Add( node );
m_nodesOnCommentaryDict.Add( node.UniqueId, node );
node.OnNodeStoppedMovingEvent += NodeStoppedMoving;
node.OnNodeDestroyedEvent += NodeDestroyed;
node.CommentaryParent = UniqueId;
}
}
}
public override void DrawProperties()
{
base.DrawProperties();
NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr,()=>
{
EditorGUI.BeginChangeCheck();
m_titleText = EditorGUILayoutTextField( "Frame Title", m_titleText );
if ( EditorGUI.EndChangeCheck() )
{
m_checkTitleText = true;
}
EditorGUI.BeginChangeCheck();
m_commentText = EditorGUILayoutTextField( CommentaryTitle, m_commentText );
if ( EditorGUI.EndChangeCheck() )
{
m_checkCommentText = true;
}
m_frameColor = EditorGUILayoutColorField( "Frame Color", m_frameColor );
} );
EditorGUILayout.HelpBox( InfoText, MessageType.Info );
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
if ( m_nodesIds.Count > 0 )
{
for ( int i = 0; i < m_nodesIds.Count; i++ )
{
ParentNode node = ContainerGraph.GetNode( m_nodesIds[ i ] );
if ( node )
{
AddNodeToCommentary( node );
}
}
m_nodesIds.Clear();
}
if ( m_reRegisterNodes )
{
m_reRegisterNodes = false;
m_nodesOnCommentaryDict.Clear();
for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
{
if ( m_nodesOnCommentary[ i ] != null )
{
m_nodesOnCommentary[ i ].OnNodeStoppedMovingEvent += NodeStoppedMoving;
m_nodesOnCommentary[ i ].OnNodeDestroyedEvent += NodeDestroyed;
m_nodesOnCommentaryDict.Add( m_nodesOnCommentary[ i ].UniqueId, m_nodesOnCommentary[ i ] );
}
}
}
//base.OnLayout( drawInfo );
CalculatePositionAndVisibility( drawInfo );
m_headerPosition = m_globalPosition;
m_headerPosition.height = UIUtils.CurrentHeaderHeight;
m_auxHeaderPos = m_position;
m_auxHeaderPos.height = UIUtils.HeaderMaxHeight;
m_commentArea = m_globalPosition;
m_commentArea.height = COMMENTARY_BOX_HEIGHT * drawInfo.InvertedZoom;
m_commentArea.xMin += 10 * drawInfo.InvertedZoom;
m_commentArea.xMax -= 10 * drawInfo.InvertedZoom;
if ( m_resizeIconTex == null )
{
m_resizeIconTex = UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButton ).normal.background;
}
// LEFT RESIZE BUTTON
m_resizeLeftIconCoords = m_globalPosition;
m_resizeLeftIconCoords.x = m_globalPosition.x + 2;
m_resizeLeftIconCoords.y = m_globalPosition.y + m_globalPosition.height - 2 - ( m_resizeIconTex.height + ResizeButtonPos.y ) * drawInfo.InvertedZoom;
m_resizeLeftIconCoords.width = m_resizeIconTex.width * drawInfo.InvertedZoom;
m_resizeLeftIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;
// RIGHT RESIZE BUTTON
m_resizeRightIconCoords = m_globalPosition;
m_resizeRightIconCoords.x = m_globalPosition.x + m_globalPosition.width - 1 - ( m_resizeIconTex.width + ResizeButtonPos.x ) * drawInfo.InvertedZoom;
m_resizeRightIconCoords.y = m_globalPosition.y + m_globalPosition.height - 2 - ( m_resizeIconTex.height + ResizeButtonPos.y ) * drawInfo.InvertedZoom;
m_resizeRightIconCoords.width = m_resizeIconTex.width * drawInfo.InvertedZoom;
m_resizeRightIconCoords.height = m_resizeIconTex.height * drawInfo.InvertedZoom;
}
public override void OnNodeRepaint( DrawInfo drawInfo )
{
if ( !m_isVisible )
return;
m_colorBuffer = GUI.color;
// Background
GUI.color = Constants.NodeBodyColor * m_frameColor;
GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryBackground ) );
// Header
GUI.color = m_headerColor * m_headerColorModifier * m_frameColor;
GUI.Label( m_headerPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeHeader ) );
GUI.color = m_colorBuffer;
// Fixed Title ( only renders when not editing )
if ( !m_isEditing && !m_startEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
{
GUI.Label( m_commentArea, m_commentText, UIUtils.CommentaryTitle );
}
// Buttons
GUI.Label( m_resizeLeftIconCoords, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButtonInv ) );
GUI.Label( m_resizeRightIconCoords, string.Empty, UIUtils.GetCustomStyle( CustomStyle.CommentaryResizeButton ) );
// Selection Box
if ( m_selected )
{
GUI.color = Constants.NodeSelectedColor;
RectOffset cache = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border;
UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border = UIUtils.RectOffsetSix;
GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ) );
UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ).border = cache;
GUI.color = m_colorBuffer;
}
if ( !string.IsNullOrEmpty( m_titleText ) )
{
Rect titleRect = m_globalPosition;
titleRect.y -= 24;
titleRect.height = 24;
GUI.Label( titleRect, m_titleText, UIUtils.GetCustomStyle( CustomStyle.CommentarySuperTitle ) );
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
// Custom Editable Title
if ( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
{
if ( !m_isEditing && ( ( !ContainerGraph.ParentWindow.MouseInteracted && drawInfo.CurrentEventType == EventType.MouseDown && m_commentArea.Contains( drawInfo.MousePosition ) ) ) )
{
if ( ( EditorApplication.timeSinceStartup - m_clickTime ) < m_doubleClickTime )
m_startEditing = true;
else
GUI.FocusControl( null );
m_clickTime = EditorApplication.timeSinceStartup;
}
else if ( m_isEditing && ( ( drawInfo.CurrentEventType == EventType.MouseDown && !m_commentArea.Contains( drawInfo.MousePosition ) ) || !EditorGUIUtility.editingTextField ) )
{
m_stopEditing = true;
}
if ( m_isEditing || m_startEditing )
{
EditorGUI.BeginChangeCheck();
GUI.SetNextControlName( m_focusName );
m_commentText = EditorGUITextField( m_commentArea, string.Empty, m_commentText, UIUtils.CommentaryTitle );
if ( EditorGUI.EndChangeCheck() )
{
m_checkCommentText = true;
}
if ( m_startEditing )
EditorGUI.FocusTextInControl( m_focusName );
}
if ( drawInfo.CurrentEventType == EventType.Repaint )
{
if ( m_startEditing )
{
m_startEditing = false;
m_isEditing = true;
}
if ( m_stopEditing )
{
m_stopEditing = false;
m_isEditing = false;
GUI.FocusControl( null );
}
}
}
if ( drawInfo.CurrentEventType == EventType.MouseDown && drawInfo.LeftMouseButtonPressed )
{
// Left Button
if( m_resizeLeftIconCoords.Contains( drawInfo.MousePosition ) && ContainerGraph.ParentWindow.CurrentEvent.modifiers != EventModifiers.Shift )
{
if ( !m_isResizingLeft )
{
m_isResizingLeft = true;
ContainerGraph.ParentWindow.ForceAutoPanDir = true;
m_resizeStartPoint = drawInfo.TransformedMousePos;
}
}
// Right Button
if ( m_resizeRightIconCoords.Contains( drawInfo.MousePosition ) && ContainerGraph.ParentWindow.CurrentEvent.modifiers != EventModifiers.Shift )
{
if ( !m_isResizingRight )
{
m_isResizingRight = true;
ContainerGraph.ParentWindow.ForceAutoPanDir = true;
m_resizeStartPoint = drawInfo.TransformedMousePos;
}
}
}
if ( drawInfo.CurrentEventType == EventType.Repaint || drawInfo.CurrentEventType == EventType.MouseUp )
{
// Left Button
EditorGUIUtility.AddCursorRect( m_resizeLeftIconCoords, MouseCursor.ResizeUpRight );
if ( m_isResizingLeft )
{
if ( drawInfo.CurrentEventType == EventType.MouseUp )
{
m_isResizingLeft = false;
ContainerGraph.ParentWindow.ForceAutoPanDir = false;
RemoveAllNodes();
FireStoppedMovingEvent( false, InteractionMode.Target );
}
else
{
Vector2 currSize = ( drawInfo.TransformedMousePos - m_resizeStartPoint ) /*/ drawInfo.InvertedZoom*/;
m_resizeStartPoint = drawInfo.TransformedMousePos;
if ( m_resizeAxis != eResizeAxis.Y_AXIS )
{
m_position.x += currSize.x;
m_position.width -= currSize.x;
if ( m_position.width < MIN_SIZE_X )
{
m_position.x -= ( MIN_SIZE_X - m_position.width );
m_position.width = MIN_SIZE_X;
}
}
if ( m_resizeAxis != eResizeAxis.X_AXIS )
{
m_position.height += currSize.y;
if ( m_position.height < MIN_SIZE_Y )
{
m_position.height = MIN_SIZE_Y;
}
}
}
}
// Right Button
EditorGUIUtility.AddCursorRect( m_resizeRightIconCoords, MouseCursor.ResizeUpLeft );
if ( m_isResizingRight )
{
if ( drawInfo.CurrentEventType == EventType.MouseUp )
{
m_isResizingRight = false;
ContainerGraph.ParentWindow.ForceAutoPanDir = false;
RemoveAllNodes();
FireStoppedMovingEvent( false, InteractionMode.Target );
}
else
{
Vector2 currSize = ( drawInfo.TransformedMousePos - m_resizeStartPoint ) /*/ drawInfo.InvertedZoom*/;
m_resizeStartPoint = drawInfo.TransformedMousePos;
if ( m_resizeAxis != eResizeAxis.Y_AXIS )
{
m_position.width += currSize.x;
if ( m_position.width < MIN_SIZE_X )
{
m_position.width = MIN_SIZE_X;
}
}
if ( m_resizeAxis != eResizeAxis.X_AXIS )
{
m_position.height += currSize.y;
if ( m_position.height < MIN_SIZE_Y )
{
m_position.height = MIN_SIZE_Y;
}
}
}
}
}
if ( m_checkCommentText )
{
m_checkCommentText = false;
m_commentText = m_commentText.Replace( IOUtils.FIELD_SEPARATOR, ' ' );
}
if ( m_checkTitleText )
{
m_checkTitleText = false;
m_titleText = m_titleText.Replace( IOUtils.FIELD_SEPARATOR, ' ' );
}
if ( m_focusOnTitle && drawInfo.CurrentEventType == EventType.KeyUp )
{
m_focusOnTitle = false;
m_startEditing = true;
}
}
public void Focus()
{
m_focusOnTitle = true;
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_reRegisterNodes = true;
}
public override bool OnNodeInteraction( ParentNode node )
{
if ( node == null || UniqueId == node.UniqueId )
return false;
for( int i = 0; i < m_nodesOnCommentary.Count; i++ )
{
if( m_nodesOnCommentary[ i ] && m_nodesOnCommentary[ i ] != this && m_nodesOnCommentary[ i ].OnNodeInteraction( node ) )
{
return false;
}
}
if( m_position.Contains( node.Vec2Position ) && m_position.Contains( node.Corner ) )
{
AddNodeToCommentary( node );
return true;
}
return false;
}
public override void OnSelfStoppedMovingEvent()
{
FireStoppedMovingEvent( false, InteractionMode.Both );
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_position.width = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
m_position.height = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
m_commentText = GetCurrentParam( ref nodeParams );
int count = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
for ( int i = 0; i < count; i++ )
{
m_nodesIds.Add( Convert.ToInt32( GetCurrentParam( ref nodeParams ) ) );
}
if ( UIUtils.CurrentShaderVersion() > 5004 )
m_titleText = GetCurrentParam( ref nodeParams );
if ( UIUtils.CurrentShaderVersion() > 12002 )
{
string[] colorChannels = GetCurrentParam( ref nodeParams ).Split( IOUtils.VECTOR_SEPARATOR );
if ( colorChannels.Length == 4 )
{
m_frameColor.r = Convert.ToSingle( colorChannels[ 0 ] );
m_frameColor.g = Convert.ToSingle( colorChannels[ 1 ] );
m_frameColor.b = Convert.ToSingle( colorChannels[ 2 ] );
m_frameColor.a = Convert.ToSingle( colorChannels[ 3 ] );
}
else
{
UIUtils.ShowMessage( UniqueId, "Incorrect number of color values", MessageSeverity.Error );
}
}
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_position.width );
IOUtils.AddFieldValueToString( ref nodeInfo, m_position.height );
IOUtils.AddFieldValueToString( ref nodeInfo, m_commentText );
IOUtils.AddFieldValueToString( ref nodeInfo, m_nodesOnCommentary.Count );
for ( int i = 0; i < m_nodesOnCommentary.Count; i++ )
{
IOUtils.AddFieldValueToString( ref nodeInfo, m_nodesOnCommentary[ i ].UniqueId );
}
IOUtils.AddFieldValueToString( ref nodeInfo, m_titleText );
IOUtils.AddFieldValueToString( ref nodeInfo, m_frameColor.r.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.g.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.b.ToString() + IOUtils.VECTOR_SEPARATOR + m_frameColor.a.ToString() );
}
public override void ResetNodeData()
{
base.ResetNodeData();
m_graphDepthAnalized = false;
}
public override void ReadAdditionalClipboardData( ref string[] nodeParams )
{
base.ReadAdditionalClipboardData( ref nodeParams );
m_nodesIds.Clear();
m_checkContents = true;
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( m_checkContents )
{
m_checkContents = false;
OnSelfStoppedMovingEvent();
}
}
public override void CalculateCustomGraphDepth()
{
if ( m_graphDepthAnalized )
return;
m_graphDepth = int.MinValue;
int count = m_nodesOnCommentary.Count;
for ( int i = 0; i < count; i++ )
{
if ( m_nodesOnCommentary[ i ].ConnStatus == NodeConnectionStatus.Island )
{
m_nodesOnCommentary[ i ].CalculateCustomGraphDepth();
}
if ( m_nodesOnCommentary[ i ].GraphDepth >= m_graphDepth )
{
m_graphDepth = m_nodesOnCommentary[ i ].GraphDepth + 1;
}
}
m_graphDepthAnalized = true;
}
public override Rect Position { get { return Event.current.alt ? m_position : m_auxHeaderPos; } }
public override bool Contains( Vector3 pos )
{
return Event.current.alt ? m_globalPosition.Contains( pos ) : ( m_headerPosition.Contains( pos ) || m_resizeRightIconCoords.Contains( pos ) || m_resizeLeftIconCoords.Contains( pos ) );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 08f1d9c1d8cbe5841a6429d565096eab
timeCreated: 1481126953
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e7354e1a2beece044944bc1cba85aebc
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,507 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Color", "Constants And Properties", "Color property", null, KeyCode.Alpha5 )]
public sealed class ColorNode : PropertyNode
{
private const string ColorSpaceStr = "Color Space";
[SerializeField]
#if UNITY_2018_1_OR_NEWER
[ColorUsage( true, true )]
#else
[ColorUsage( true, true, float.MinValue, float.MinValue, float.MinValue, float.MaxValue )]
#endif
private Color m_defaultValue = new Color( 0, 0, 0, 0 );
[SerializeField]
#if UNITY_2018_1_OR_NEWER
[ColorUsage( true, true )]
#else
[ColorUsage( true, true, float.MinValue, float.MinValue, float.MinValue, float.MaxValue )]
#endif
private Color m_materialValue = new Color( 0, 0, 0, 0 );
[SerializeField]
private bool m_isHDR = false;
//[SerializeField]
//private ASEColorSpace m_colorSpace = ASEColorSpace.Auto;
#if !UNITY_2018_1_OR_NEWER
private ColorPickerHDRConfig m_hdrConfig = new ColorPickerHDRConfig( 0, float.MaxValue, 0, float.MaxValue );
#endif
private GUIContent m_dummyContent;
private int m_cachedPropertyId = -1;
private bool m_isEditingFields;
[SerializeField]
private bool m_autoGammaToLinearConversion = true;
private const string AutoGammaToLinearConversion = "IsGammaSpace() ? {0} : {1}";
private const string AutoGammaToLinearStr = "Auto Gamma To Linear";
public ColorNode() : base() { }
public ColorNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Color" );
m_insideSize.Set( 100, 50 );
m_dummyContent = new GUIContent();
AddOutputColorPorts( "RGBA" );
m_drawPreview = false;
m_drawPreviewExpander = false;
m_canExpand = false;
m_showHybridInstancedUI = true;
m_selectedLocation = PreviewLocation.BottomCenter;
m_previewShaderGUID = "6cf365ccc7ae776488ae8960d6d134c3";
m_srpBatcherCompatible = true;
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
if( m_cachedPropertyId == -1 )
m_cachedPropertyId = Shader.PropertyToID( "_InputColor" );
if( m_materialMode && m_currentParameterType != PropertyType.Constant )
PreviewMaterial.SetColor( m_cachedPropertyId, m_materialValue );
else
PreviewMaterial.SetColor( m_cachedPropertyId, m_defaultValue );
}
public override void CopyDefaultsToMaterial()
{
m_materialValue = m_defaultValue;
}
public override void DrawSubProperties()
{
m_textLabelWidth = ( m_currentParameterType == PropertyType.Constant ) ? 152 : 105;
#if UNITY_2018_1_OR_NEWER
m_defaultValue = EditorGUILayoutColorField( Constants.DefaultValueLabelContent, m_defaultValue, false, true, m_isHDR );
#else
m_defaultValue = EditorGUILayoutColorField( Constants.DefaultValueLabelContent, m_defaultValue, false, true, m_isHDR, m_hdrConfig );
#endif
if( m_currentParameterType == PropertyType.Constant )
{
m_autoGammaToLinearConversion = EditorGUILayoutToggle( AutoGammaToLinearStr, m_autoGammaToLinearConversion );
}
}
//public override void DrawMainPropertyBlock()
//{
// EditorGUILayout.BeginVertical();
// {
// PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType );
// if( parameterType != m_currentParameterType )
// {
// ChangeParameterType( parameterType );
// BeginPropertyFromInspectorCheck();
// }
// switch( m_currentParameterType )
// {
// case PropertyType.Property:
// case PropertyType.InstancedProperty:
// {
// ShowPropertyInspectorNameGUI();
// ShowPropertyNameGUI( true );
// ShowVariableMode();
// ShowPrecision();
// ShowToolbar();
// }
// break;
// case PropertyType.Global:
// {
// ShowPropertyInspectorNameGUI();
// ShowPropertyNameGUI( false );
// ShowVariableMode();
// ShowPrecision();
// ShowDefaults();
// }
// break;
// case PropertyType.Constant:
// {
// ShowPropertyInspectorNameGUI();
// ShowPrecision();
// m_colorSpace = (ASEColorSpace)EditorGUILayoutEnumPopup( ColorSpaceStr, m_colorSpace );
// ShowDefaults();
// }
// break;
// }
// }
// EditorGUILayout.EndVertical();
//}
public override void DrawMaterialProperties()
{
if( m_materialMode )
EditorGUI.BeginChangeCheck();
#if UNITY_2018_1_OR_NEWER
m_materialValue = EditorGUILayoutColorField( Constants.MaterialValueLabelContent, m_materialValue, false, true, m_isHDR );
#else
m_materialValue = EditorGUILayoutColorField( Constants.MaterialValueLabelContent, m_materialValue, false, true, m_isHDR, m_hdrConfig );
#endif
if( m_materialMode && EditorGUI.EndChangeCheck() )
m_requireMaterialUpdate = true;
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_propertyDrawPos = m_globalPosition;
m_propertyDrawPos.x = m_remainingBox.x;
m_propertyDrawPos.y = m_remainingBox.y;
m_propertyDrawPos.width = 80 * drawInfo.InvertedZoom;
m_propertyDrawPos.height = m_remainingBox.height;
}
public override void DrawGUIControls( DrawInfo drawInfo )
{
base.DrawGUIControls( drawInfo );
if( drawInfo.CurrentEventType != EventType.MouseDown )
return;
Rect hitBox = m_remainingBox;
//hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom;
bool insideBox = hitBox.Contains( drawInfo.MousePosition );
if( insideBox )
{
m_isEditingFields = true;
}
else if( m_isEditingFields && !insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = false;
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( !m_isVisible )
return;
if( m_isEditingFields && m_currentParameterType != PropertyType.Global )
{
if( m_materialMode && m_currentParameterType != PropertyType.Constant )
{
EditorGUI.BeginChangeCheck();
#if UNITY_2018_1_OR_NEWER
m_materialValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR );
#else
m_materialValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_materialValue, false, true, m_isHDR, m_hdrConfig );
#endif
if( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
m_requireMaterialUpdate = true;
if( m_currentParameterType != PropertyType.Constant )
{
BeginDelayedDirtyProperty();
}
}
}
else
{
EditorGUI.BeginChangeCheck();
#if UNITY_2018_1_OR_NEWER
m_defaultValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR );
#else
m_defaultValue = EditorGUIColorField( m_propertyDrawPos, m_dummyContent, m_defaultValue, false, true, m_isHDR, m_hdrConfig );
#endif
if( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
BeginDelayedDirtyProperty();
}
}
}
else if( drawInfo.CurrentEventType == EventType.Repaint )
{
if( m_materialMode && m_currentParameterType != PropertyType.Constant )
EditorGUIUtility.DrawColorSwatch( m_propertyDrawPos, m_materialValue );
else
EditorGUIUtility.DrawColorSwatch( m_propertyDrawPos, m_defaultValue );
GUI.Label( m_propertyDrawPos, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
}
}
public override void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector )
{
Color color = m_defaultValue;
//switch( m_colorSpace )
//{
// default:
// case ASEColorSpace.Auto: color = m_defaultValue; break;
// case ASEColorSpace.Gamma: color = m_defaultValue.gamma; break;
// case ASEColorSpace.Linear: color = m_defaultValue.linear; break;
//}
dataCollector.AddLocalVariable( UniqueId, CreateLocalVarDec( color.r + "," + color.g + "," + color.b + "," + color.a ) );
m_outputPorts[ 0 ].SetLocalValue( m_propertyName , dataCollector.PortCategory);
m_outputPorts[ 1 ].SetLocalValue( m_propertyName + ".r", dataCollector.PortCategory );
m_outputPorts[ 2 ].SetLocalValue( m_propertyName + ".g", dataCollector.PortCategory );
m_outputPorts[ 3 ].SetLocalValue( m_propertyName + ".b", dataCollector.PortCategory );
m_outputPorts[ 4 ].SetLocalValue( m_propertyName + ".a", dataCollector.PortCategory );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
if( m_currentParameterType != PropertyType.Constant )
return GetOutputVectorItem( 0, outputId, PropertyData( dataCollector.PortCategory ) );
// Constant Only Code
if( m_outputPorts[ outputId ].IsLocalValue(dataCollector.PortCategory) )
{
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
}
if( m_autoGammaToLinearConversion )
{
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue(dataCollector.PortCategory) );
Color linear = m_defaultValue.linear;
string colorGamma = m_precisionString + "(" + m_defaultValue.r + "," + m_defaultValue.g + "," + m_defaultValue.b + "," + m_defaultValue.a + ")";
string colorLinear = m_precisionString + "(" + linear.r + "," + linear.g + "," + linear.b + "," + m_defaultValue.a + ")";
string result = string.Format( AutoGammaToLinearConversion, colorGamma, colorLinear );
RegisterLocalVariable( 0, result, ref dataCollector, "color" + OutputId );
return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
}
else
{
if( CheckLocalVariable( ref dataCollector ) )
{
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
}
Color color = m_defaultValue;
//switch( m_colorSpace )
//{
// default:
// case ASEColorSpace.Auto: color = m_defaultValue; break;
// case ASEColorSpace.Gamma: color = m_defaultValue.gamma; break;
// case ASEColorSpace.Linear: color = m_defaultValue.linear; break;
//}
string result = string.Empty;
switch( outputId )
{
case 0:
{
result = m_precisionString + "(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")";
}
break;
case 1:
{
result = color.r.ToString();
}
break;
case 2:
{
result = color.g.ToString();
}
break;
case 3:
{
result = color.b.ToString();
}
break;
case 4:
{
result = color.a.ToString();
}
break;
}
return result;
}
}
protected override void OnAtrributesChanged()
{
CheckIfHDR();
CheckHeaderAttribute();
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
CheckIfHDR();
}
void CheckIfHDR()
{
int count = m_selectedAttribs.Count;
bool hdrBuffer = m_isHDR;
m_isHDR = false;
for( int i = 0; i < count; i++ )
{
if( m_selectedAttribs[ i ] == 1 /*HDR Property ID*/)
{
m_isHDR = true;
break;
}
}
if( hdrBuffer && !m_isHDR )
{
bool fireDirtyProperty = false;
if( m_defaultValue.r > 1 || m_defaultValue.g > 1 || m_defaultValue.b > 1 )
{
float defaultColorLength = Mathf.Sqrt( m_defaultValue.r * m_defaultValue.r + m_defaultValue.g * m_defaultValue.g + m_defaultValue.b * m_defaultValue.b );
m_defaultValue.r /= defaultColorLength;
m_defaultValue.g /= defaultColorLength;
m_defaultValue.b /= defaultColorLength;
fireDirtyProperty = true;
}
if( m_materialValue.r > 1 || m_materialValue.g > 1 || m_materialValue.b > 1 )
{
float materialColorLength = Mathf.Sqrt( m_materialValue.r * m_materialValue.r + m_materialValue.g * m_materialValue.g + m_materialValue.b * m_materialValue.b );
m_materialValue.r /= materialColorLength;
m_materialValue.g /= materialColorLength;
m_materialValue.b /= materialColorLength;
fireDirtyProperty = true;
}
if( fireDirtyProperty )
BeginDelayedDirtyProperty();
}
}
public override string GetPropertyValue()
{
return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Color) = (" + m_defaultValue.r + "," + m_defaultValue.g + "," + m_defaultValue.b + "," + m_defaultValue.a + ")";
}
public override void UpdateMaterial( Material mat )
{
base.UpdateMaterial( mat );
if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction )
{
mat.SetColor( m_propertyName, m_materialValue );
}
}
public override void SetMaterialMode( Material mat, bool fetchMaterialValues )
{
base.SetMaterialMode( mat, fetchMaterialValues );
if( m_materialMode && fetchMaterialValues )
{
if( UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) )
MaterialValue = mat.GetColor( m_propertyName );
}
}
public override void ForceUpdateFromMaterial( Material material )
{
if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) )
{
MaterialValue = material.GetColor( m_propertyName );
PreviewIsDirty = true;
}
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_defaultValue = IOUtils.StringToColor( GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() > 14101 )
{
m_materialValue = IOUtils.StringToColor( GetCurrentParam( ref nodeParams ) );
}
if( UIUtils.CurrentShaderVersion() > 15900 )
{
m_autoGammaToLinearConversion = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
else
{
m_autoGammaToLinearConversion = false;
}
//if( UIUtils.CurrentShaderVersion() > 14202 )
//{
// m_colorSpace = (ASEColorSpace)Enum.Parse( typeof( ASEColorSpace ), GetCurrentParam( ref nodeParams ) );
//}
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.ColorToString( m_defaultValue ) );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.ColorToString( m_materialValue ) );
IOUtils.AddFieldValueToString( ref nodeInfo, m_autoGammaToLinearConversion );
//IOUtils.AddFieldValueToString( ref nodeInfo, m_colorSpace );
}
public override void SetGlobalValue() { Shader.SetGlobalColor( m_propertyName, m_defaultValue ); }
public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalColor( m_propertyName ); }
public override string GetPropertyValStr()
{
return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue.r.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_materialValue.g.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_materialValue.b.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_materialValue.a.ToString( Constants.PropertyVectorFormatLabel ) :
m_defaultValue.r.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_defaultValue.g.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_defaultValue.b.ToString( Constants.PropertyVectorFormatLabel ) + IOUtils.VECTOR_SEPARATOR +
m_defaultValue.a.ToString( Constants.PropertyVectorFormatLabel );
}
private Color MaterialValue
{
set
{
if( !m_isHDR && ( value.r > 1 || value.g > 1 || value.r > 1 ) )
{
float materialColorLength = Mathf.Sqrt( value.r * value.r + value.g * value.g + value.b * value.b );
m_materialValue.r = value.r / materialColorLength;
m_materialValue.g = value.g / materialColorLength;
m_materialValue.b = value.b / materialColorLength;
m_materialValue.a = value.a;
}
else
{
m_materialValue = value;
}
}
}
public Color Value
{
get { return m_defaultValue; }
set { m_defaultValue = value; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4b99bcf4cd965c648bbbc1de0d1b152a
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,486 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
//
// Custom Node Global Array
// Donated by Johann van Berkel
using System;
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Global Array", "Constants And Properties", "The node returns a value from a global array, which you can configure by entering the name of the array in the node's settings.", null, KeyCode.None, true, false, null, null, "Johann van Berkel" )]
public sealed class GlobalArrayNode : ParentNode
{
private const string DefaultArrayName = "MyGlobalArray";
private const string TypeStr = "Type";
private const string AutoRangeCheckStr = "Range Check";
private const string ArrayFormatStr = "{0}[{1}]";
private const string JaggedArrayFormatStr = "{0}[{1}][{2}]";
private const string IsJaggedStr = "Is Jagged";
private const string AutoRegisterStr = "Auto-Register";
private readonly string[] AvailableTypesLabel = { "Float", "Color", "Vector4", "Matrix4" };
private readonly WirePortDataType[] AvailableTypesValues = { WirePortDataType.FLOAT, WirePortDataType.COLOR, WirePortDataType.FLOAT4, WirePortDataType.FLOAT4x4 };
[SerializeField]
private string m_name = DefaultArrayName;
[SerializeField]
private int m_indexX = 0;
[SerializeField]
private int m_indexY = 0;
[SerializeField]
private int m_arrayLengthX = 1;
[SerializeField]
private int m_arrayLengthY = 1;
[SerializeField]
private int m_type = 0;
[SerializeField]
private bool m_autoRangeCheck = false;
[SerializeField]
private bool m_isJagged = false;
[SerializeField]
private bool m_autoRegister = false;
//////////////////////////////////////////////////////////////////
private readonly Color ReferenceHeaderColor = new Color( 0.6f, 3.0f, 1.25f, 1.0f );
[SerializeField]
private TexReferenceType m_referenceType = TexReferenceType.Object;
[SerializeField]
private int m_referenceArrayId = -1;
[SerializeField]
private int m_referenceNodeId = -1;
private GlobalArrayNode m_referenceNode = null;
private bool m_updated = false;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.INT, false, "Index", -1, MasterNodePortCategory.Fragment, 0 );
AddInputPort( WirePortDataType.INT, false, "Index Y", -1, MasterNodePortCategory.Fragment, 2 );
AddInputPort( WirePortDataType.INT, false, "Array Length", -1, MasterNodePortCategory.Fragment, 1 );
AddInputPort( WirePortDataType.INT, false, "Array Length Y", -1, MasterNodePortCategory.Fragment, 3 );
AddOutputPort( WirePortDataType.FLOAT, "Out" );
m_textLabelWidth = 95;
SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) );
UpdatePorts();
}
protected override void OnUniqueIDAssigned()
{
base.OnUniqueIDAssigned();
UIUtils.CurrentWindow.OutsideGraph.GlobalArrayNodes.AddNode( this );
}
public override void Destroy()
{
base.Destroy();
UIUtils.CurrentWindow.OutsideGraph.GlobalArrayNodes.RemoveNode( this );
}
void UpdatePorts()
{
InputPort indexXPort = GetInputPortByUniqueId( 0 );
InputPort arrayLengthPortX = GetInputPortByUniqueId( 1 );
InputPort indexYPort = GetInputPortByUniqueId( 2 );
InputPort arrayLengthPortY = GetInputPortByUniqueId( 3 );
if( m_referenceType == TexReferenceType.Object )
{
m_headerColorModifier = Color.white;
SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) );
arrayLengthPortX.Visible = true;
if( m_isJagged )
{
indexXPort.Name = "Index X";
arrayLengthPortX.Name = "Array Length X";
indexYPort.Visible = true;
arrayLengthPortY.Visible = true;
}
else
{
indexXPort.Name = "Index";
arrayLengthPortX.Name = "Array Length";
indexYPort.Visible = false;
arrayLengthPortY.Visible = false;
}
}
else if( m_referenceNodeId > -1 )
{
m_headerColorModifier = ReferenceHeaderColor;
if( m_referenceNode == null )
m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode;
if( m_referenceNode != null )
{
SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_referenceNode.DataToArray ) );
arrayLengthPortX.Visible = false;
arrayLengthPortY.Visible = false;
if( m_referenceNode.IsJagged )
{
indexXPort.Name = "Index X";
indexYPort.Visible = true;
}
else
{
indexXPort.Name = "Index";
indexYPort.Visible = false;
}
}
}
m_sizeIsDirty = true;
}
void DrawObjectProperties()
{
EditorGUI.BeginChangeCheck();
m_name = EditorGUILayoutStringField( "Name", m_name );
if( EditorGUI.EndChangeCheck() )
{
m_updated = true;
m_name = UIUtils.RemoveInvalidCharacters( m_name );
if( string.IsNullOrEmpty( m_name ) )
m_name = DefaultArrayName;
UIUtils.UpdateGlobalArrayDataNode( UniqueId, m_name );
SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) );
}
m_autoRegister = EditorGUILayoutToggle( AutoRegisterStr, m_autoRegister );
EditorGUI.BeginChangeCheck();
m_isJagged = EditorGUILayoutToggle( IsJaggedStr, m_isJagged );
if( EditorGUI.EndChangeCheck() )
{
m_updated = true;
UpdatePorts();
}
InputPort indexXPort = GetInputPortByUniqueId( 0 );
if( !indexXPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_indexX = EditorGUILayoutIntField( indexXPort.Name, m_indexX );
if( EditorGUI.EndChangeCheck() )
{
m_indexX = Mathf.Clamp( m_indexX, 0, ( m_arrayLengthX - 1 ) );
}
}
if( m_isJagged )
{
InputPort indexYPort = GetInputPortByUniqueId( 2 );
if( !indexYPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_indexY = EditorGUILayoutIntField( indexYPort.Name, m_indexY );
if( EditorGUI.EndChangeCheck() )
{
m_indexY = Mathf.Clamp( m_indexY, 0, ( m_arrayLengthY - 1 ) );
}
}
}
InputPort arrayLengthXPort = GetInputPortByUniqueId( 1 );
if( !arrayLengthXPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_arrayLengthX = EditorGUILayoutIntField( arrayLengthXPort.Name, m_arrayLengthX );
if( EditorGUI.EndChangeCheck() )
{
m_arrayLengthX = Mathf.Max( 1, m_arrayLengthX );
}
}
if( m_isJagged )
{
InputPort arrayLengthYPort = GetInputPortByUniqueId( 3 );
if( !arrayLengthYPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_arrayLengthY = EditorGUILayoutIntField( arrayLengthYPort.Name, m_arrayLengthY );
if( EditorGUI.EndChangeCheck() )
{
m_arrayLengthY = Mathf.Max( 1, m_arrayLengthY );
}
}
}
EditorGUI.BeginChangeCheck();
m_type = EditorGUILayoutPopup( TypeStr, m_type, AvailableTypesLabel );
if( EditorGUI.EndChangeCheck() )
{
m_outputPorts[ 0 ].ChangeType( (WirePortDataType)AvailableTypesValues[ m_type ], false );
}
m_autoRangeCheck = EditorGUILayoutToggle( AutoRangeCheckStr, m_autoRangeCheck );
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_updated = false;
if( m_referenceType == TexReferenceType.Instance )
{
if( m_referenceNodeId > -1 && m_referenceNode == null )
{
m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode;
if( m_referenceNode == null )
{
m_referenceNodeId = -1;
}
}
if( m_referenceNode != null && m_referenceNode.Updated)
{
UpdatePorts();
}
}
}
void DrawInstancedProperties()
{
string[] arr = UIUtils.GlobalArrayNodeArr();
bool guiEnabledBuffer = GUI.enabled;
if( arr != null && arr.Length > 0 )
{
GUI.enabled = true;
}
else
{
m_referenceArrayId = -1;
m_referenceNodeId = -1;
m_referenceNode = null;
GUI.enabled = false;
}
EditorGUI.BeginChangeCheck();
m_referenceArrayId = EditorGUILayoutPopup( Constants.AvailableReferenceStr, m_referenceArrayId, arr );
if( EditorGUI.EndChangeCheck() )
{
m_referenceNode = UIUtils.GetGlobalArrayNode( m_referenceArrayId );
if( m_referenceNode != null )
{
m_referenceNodeId = m_referenceNode.UniqueId;
}
UpdatePorts();
}
GUI.enabled = guiEnabledBuffer;
InputPort indexXPort = GetInputPortByUniqueId( 0 );
if( !indexXPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_indexX = EditorGUILayoutIntField( indexXPort.Name, m_indexX );
if( EditorGUI.EndChangeCheck() )
{
m_indexX = Mathf.Clamp( m_indexX, 0, ( m_arrayLengthX - 1 ) );
}
}
if( m_isJagged )
{
InputPort indexYPort = GetInputPortByUniqueId( 2 );
if( !indexYPort.IsConnected )
{
EditorGUI.BeginChangeCheck();
m_indexY = EditorGUILayoutIntField( indexYPort.Name, m_indexY );
if( EditorGUI.EndChangeCheck() )
{
m_indexY = Mathf.Clamp( m_indexY, 0, ( m_arrayLengthY - 1 ) );
}
}
}
}
public override void DrawProperties()
{
EditorGUI.BeginChangeCheck();
m_referenceType = (TexReferenceType)EditorGUILayoutPopup( Constants.ReferenceTypeStr, (int)m_referenceType, Constants.ReferenceArrayLabels );
if( EditorGUI.EndChangeCheck() )
{
UpdatePorts();
}
if( m_referenceType == TexReferenceType.Object )
DrawObjectProperties();
else
DrawInstancedProperties();
}
public string GetArrayValue( string indexX, string indexY = null )
{
if( m_isJagged )
return string.Format( JaggedArrayFormatStr, m_name, indexX, indexY );
return string.Format( ArrayFormatStr, m_name, indexX );
}
public string GenerateInstancedShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
string result = string.Empty;
if( m_referenceNode != null )
{
InputPort indexXPort = GetInputPortByUniqueId( 0 );
if( m_referenceNode.IsJagged )
{
InputPort indexYPort = GetInputPortByUniqueId( 2 );
string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString();
string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString();
result = m_referenceNode.GetArrayValue( arrayIndexX, arrayIndexY );
}
else
{
string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString();
result = m_referenceNode.GetArrayValue( arrayIndexX );
}
}
m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory );
return result;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
if( m_referenceType == TexReferenceType.Instance )
return GenerateInstancedShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
string dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, AvailableTypesValues[ m_type ] );
InputPort indexXPort = GetInputPortByUniqueId( 0 );
InputPort arrayLengthXPort = GetInputPortByUniqueId( 1 );
string result = string.Empty;
if( m_isJagged )
{
InputPort indexYPort = GetInputPortByUniqueId( 2 );
InputPort arrayLengthYPort = GetInputPortByUniqueId( 3 );
string arrayIndexX = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString();
string arrayLengthX = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString();
string arrayIndexY = indexYPort.IsConnected ? indexYPort.GeneratePortInstructions( ref dataCollector ) : m_indexY.ToString();
string arrayLengthY = arrayLengthYPort.IsConnected ? arrayLengthYPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthY.ToString();
dataCollector.AddToUniforms( UniqueId, dataType, string.Format( JaggedArrayFormatStr, m_name, arrayLengthX, arrayLengthY ) );
if( m_autoRangeCheck )
{
arrayIndexX = string.Format( "clamp({0},0,({1} - 1))", arrayIndexX, arrayLengthX );
arrayIndexY = string.Format( "clamp({0},0,({1} - 1))", arrayIndexY, arrayLengthY );
}
result = string.Format( JaggedArrayFormatStr, m_name, arrayIndexX, arrayIndexY );
}
else
{
string arrayIndex = indexXPort.IsConnected ? indexXPort.GeneratePortInstructions( ref dataCollector ) : m_indexX.ToString();
string arrayLength = arrayLengthXPort.IsConnected ? arrayLengthXPort.GeneratePortInstructions( ref dataCollector ) : m_arrayLengthX.ToString();
dataCollector.AddToUniforms( UniqueId, dataType, string.Format( ArrayFormatStr, m_name, arrayLength ) );
if( m_autoRangeCheck )
arrayIndex = string.Format( "clamp({0},0,({1} - 1))", arrayIndex, arrayLength );
result = string.Format( ArrayFormatStr, m_name, arrayIndex );
}
m_outputPorts[ 0 ].SetLocalValue( result, dataCollector.PortCategory );
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
}
public void CheckIfAutoRegister( ref MasterNodeDataCollector dataCollector )
{
if( m_referenceType == TexReferenceType.Object && m_autoRegister && m_connStatus != NodeConnectionStatus.Connected )
{
string dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, AvailableTypesValues[ m_type ] );
if( m_isJagged )
{
dataCollector.AddToUniforms( UniqueId, dataType, string.Format( JaggedArrayFormatStr, m_name, m_arrayLengthX, m_arrayLengthY ) );
}
else
{
dataCollector.AddToUniforms( UniqueId, dataType, string.Format( ArrayFormatStr, m_name, m_arrayLengthX ) );
}
}
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_name );
IOUtils.AddFieldValueToString( ref nodeInfo, m_indexX );
IOUtils.AddFieldValueToString( ref nodeInfo, m_arrayLengthX );
IOUtils.AddFieldValueToString( ref nodeInfo, m_type );
IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRangeCheck );
IOUtils.AddFieldValueToString( ref nodeInfo, m_isJagged );
IOUtils.AddFieldValueToString( ref nodeInfo, m_indexY );
IOUtils.AddFieldValueToString( ref nodeInfo, m_arrayLengthY );
IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRegister );
IOUtils.AddFieldValueToString( ref nodeInfo, m_referenceType );
IOUtils.AddFieldValueToString( ref nodeInfo, m_referenceNodeId );
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_name = GetCurrentParam( ref nodeParams );
m_indexX = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
m_arrayLengthX = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
m_type = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
m_autoRangeCheck = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() > 15801 )
{
m_isJagged = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
m_indexY = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
m_arrayLengthY = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
m_autoRegister = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
m_referenceType = (TexReferenceType)Enum.Parse( typeof( TexReferenceType ), GetCurrentParam( ref nodeParams ) );
m_referenceNodeId = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
}
SetAdditonalTitleText( string.Format( Constants.SubTitleValueFormatStr, m_name ) );
UpdatePorts();
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( m_referenceType == TexReferenceType.Instance && m_referenceNodeId > -1 )
{
m_referenceNode = UIUtils.GetNode( m_referenceNodeId ) as GlobalArrayNode;
if( m_referenceNode != null )
{
m_referenceArrayId = UIUtils.GetGlobalArrayNodeRegisterId( m_referenceNodeId );
UpdatePorts();
}
else
{
m_referenceNodeId = -1;
}
}
}
public bool AutoRegister { get { return m_autoRegister; } }
public bool IsJagged { get { return m_isJagged; } }
public bool Updated { get { return m_updated; } }
public override string DataToArray { get { return m_name; } }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 833b18e1479dbd24c80c5b990e16e2bb
timeCreated: 1499769855
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,230 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Gradient", "Constants And Properties", "Gradient property" )]
public sealed class GradientNode : ParentNode
{
[SerializeField]
private Gradient m_gradient = new Gradient();
private string m_functionHeader = "NewGradient( {0}, {1}, {2}," +
" {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}," +
" {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18} )";
private string m_functionBody = string.Empty;
private string m_functionHeaderStruct = "Gradient( {0} )";
private string m_functionBodyStruct = string.Empty;
public Gradient Gradient { get { return m_gradient; } }
public GradientNode() : base() { }
public GradientNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
m_insideSize.Set( 128, m_insideSize.y );
AddOutputPort( WirePortDataType.OBJECT, Constants.EmptyPortValue );
m_autoWrapProperties = true;
m_textLabelWidth = 100;
}
public override void DrawProperties()
{
base.DrawProperties();
m_gradient = EditorGUILayoutEx.GradientField( "Gradient", m_gradient );
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( !m_isVisible )
return;
m_gradient = EditorGUIEx.GradientField( m_remainingBox, m_gradient );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
m_functionBodyStruct = string.Empty;
m_functionBody = string.Empty;
if( !dataCollector.IsSRP )
{
GenerateGradientStruct( ref m_functionBodyStruct );
dataCollector.AddFunctions( m_functionHeaderStruct, m_functionBodyStruct, "0" );
GenerateGradient( ref m_functionBody );
}
else
{
dataCollector.AddToIncludes( UniqueId, "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" );
}
string[] colors = new string[ 8 ];
for( int i = 0; i < 8; i++ )
{
if( i < m_gradient.colorKeys.Length )
{
colors[ i ] = "float4( " + m_gradient.colorKeys[ i ].color.r + ", " + m_gradient.colorKeys[ i ].color.g + ", " + m_gradient.colorKeys[ i ].color.b + ", " + m_gradient.colorKeys[ i ].time + " )";
}
else
{
colors[ i ] = "0";
}
}
string[] alphas = new string[ 8 ];
for( int i = 0; i < 8; i++ )
{
if( i < m_gradient.alphaKeys.Length )
{
alphas[ i ] = "float2( " + m_gradient.alphaKeys[ i ].alpha + ", " + m_gradient.alphaKeys[ i ].time + " )";
}
else
{
alphas[ i ] = "0";
}
}
string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, (int)m_gradient.mode, m_gradient.colorKeys.Length, m_gradient.alphaKeys.Length
, colors[ 0 ], colors[ 1 ], colors[ 2 ], colors[ 3 ], colors[ 4 ], colors[ 5 ], colors[ 6 ], colors[ 7 ]
, alphas[ 0 ], alphas[ 1 ], alphas[ 2 ], alphas[ 3 ], alphas[ 4 ], alphas[ 5 ], alphas[ 6 ], alphas[ 7 ] );
dataCollector.AddLocalVariable( UniqueId, "Gradient gradient" + OutputId + " = " + functionResult + ";" );
return "gradient" + OutputId;
}
public static void GenerateGradientStruct( ref string body )
{
body = string.Empty;
IOUtils.AddFunctionHeader( ref body, "struct Gradient" );
IOUtils.AddFunctionLine( ref body, "int type;" );
IOUtils.AddFunctionLine( ref body, "int colorsLength;" );
IOUtils.AddFunctionLine( ref body, "int alphasLength;" );
IOUtils.AddFunctionLine( ref body, "float4 colors[8];" );
IOUtils.AddFunctionLine( ref body, "float2 alphas[8];" );
IOUtils.AddSingleLineFunction( ref body, "};\n" );
}
public static void GenerateGradient( ref string body )
{
body = string.Empty;
IOUtils.AddFunctionHeader( ref body, "Gradient NewGradient(int type, int colorsLength, int alphasLength, \n\t\tfloat4 colors0, float4 colors1, float4 colors2, float4 colors3, float4 colors4, float4 colors5, float4 colors6, float4 colors7,\n\t\tfloat2 alphas0, float2 alphas1, float2 alphas2, float2 alphas3, float2 alphas4, float2 alphas5, float2 alphas6, float2 alphas7)" );
IOUtils.AddFunctionLine( ref body, "Gradient g;" );
IOUtils.AddFunctionLine( ref body, "g.type = type;" );
IOUtils.AddFunctionLine( ref body, "g.colorsLength = colorsLength;" );
IOUtils.AddFunctionLine( ref body, "g.alphasLength = alphasLength;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 0 ] = colors0;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 1 ] = colors1;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 2 ] = colors2;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 3 ] = colors3;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 4 ] = colors4;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 5 ] = colors5;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 6 ] = colors6;" );
IOUtils.AddFunctionLine( ref body, "g.colors[ 7 ] = colors7;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 0 ] = alphas0;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 1 ] = alphas1;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 2 ] = alphas2;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 3 ] = alphas3;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 4 ] = alphas4;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 5 ] = alphas5;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 6 ] = alphas6;" );
IOUtils.AddFunctionLine( ref body, "g.alphas[ 7 ] = alphas7;" );
IOUtils.AddFunctionLine( ref body, "return g;" );
IOUtils.CloseFunctionBody( ref body );
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_gradient.mode = (GradientMode)Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
int colorCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
int alphaCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
var colorKeys = new GradientColorKey[ colorCount ];
for( int i = 0; i < colorCount; i++ )
{
Vector4 colorKey = IOUtils.StringToVector4( GetCurrentParam( ref nodeParams ) );
colorKeys[ i ].color = colorKey;
colorKeys[ i ].time = colorKey.w;
}
m_gradient.colorKeys = colorKeys;
var alphaKeys = new GradientAlphaKey[ alphaCount ];
for( int i = 0; i < alphaCount; i++ )
{
Vector2 alphaKey = IOUtils.StringToVector2( GetCurrentParam( ref nodeParams ) );
alphaKeys[ i ].alpha = alphaKey.x;
alphaKeys[ i ].time = alphaKey.y;
}
m_gradient.alphaKeys = alphaKeys;
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, (int)m_gradient.mode );
IOUtils.AddFieldValueToString( ref nodeInfo, m_gradient.colorKeys.Length );
IOUtils.AddFieldValueToString( ref nodeInfo, m_gradient.alphaKeys.Length );
for( int i = 0; i < m_gradient.colorKeys.Length; i++ )
{
Vector4 colorKey = new Vector4( m_gradient.colorKeys[ i ].color.r, m_gradient.colorKeys[ i ].color.g, m_gradient.colorKeys[ i ].color.b, m_gradient.colorKeys[ i ].time );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector4ToString( colorKey ) );
}
for( int i = 0; i < m_gradient.alphaKeys.Length; i++ )
{
Vector2 alphaKey = new Vector4( m_gradient.alphaKeys[ i ].alpha, m_gradient.alphaKeys[ i ].time );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector2ToString( alphaKey ) );
}
}
}
internal static class EditorGUILayoutEx
{
public static System.Type Type = typeof( EditorGUILayout );
public static Gradient GradientField( Gradient value, params GUILayoutOption[] options )
{
#if UNITY_2018_3_OR_NEWER
return EditorGUILayout.GradientField( value, options );
#else
MethodInfo method = EditorGUILayoutEx.Type.GetMethod( "GradientField", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof( Gradient ), typeof( GUILayoutOption[] ) }, null );
return (Gradient)method.Invoke( Type, new object[] { value, options } );
#endif
}
public static Gradient GradientField( string label, Gradient value, params GUILayoutOption[] options )
{
#if UNITY_2018_3_OR_NEWER
return EditorGUILayout.GradientField( label, value, options );
#else
MethodInfo method = EditorGUILayoutEx.Type.GetMethod( "GradientField", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof( string ), typeof( Gradient ), typeof( GUILayoutOption[] ) }, null );
return (Gradient)method.Invoke( Type, new object[] { label, value, options } );
#endif
}
}
internal static class EditorGUIEx
{
public static System.Type Type = typeof( EditorGUI );
public static Gradient GradientField( Rect position, Gradient gradient )
{
#if UNITY_2018_3_OR_NEWER
return EditorGUI.GradientField( position, gradient );
#else
return (Gradient)EditorGUIEx.Type.InvokeMember( "GradientField", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[] { position, gradient } );
#endif
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 98100a8a545b8ce42bc5657fd40a24a5
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,300 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Int", "Constants And Properties", "Int property", null, KeyCode.Alpha0 )]
public sealed class IntNode : PropertyNode
{
[SerializeField]
private int m_defaultValue;
[SerializeField]
private int m_materialValue;
[SerializeField]
private bool m_setAsUINT = false;
private const float LabelWidth = 8;
private int m_cachedPropertyId = -1;
private bool m_isEditingFields;
private int m_previousValue;
private string m_fieldText = "0";
public IntNode() : base() { }
public IntNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Int" );
AddOutputPort( WirePortDataType.INT, Constants.EmptyPortValue );
m_insideSize.Set( 50, 10 );
m_selectedLocation = PreviewLocation.BottomCenter;
m_drawPrecisionUI = false;
m_showHybridInstancedUI = true;
m_availableAttribs.Add( new PropertyAttributes( "Enum", "[Enum]" ) );
m_previewShaderGUID = "0f64d695b6ffacc469f2dd31432a232a";
m_srpBatcherCompatible = true;
}
protected override void OnUniqueIDAssigned()
{
base.OnUniqueIDAssigned();
UIUtils.RegisterFloatIntNode( this );
}
public override void Destroy()
{
base.Destroy();
UIUtils.UnregisterFloatIntNode( this );
}
public override void OnDirtyProperty()
{
UIUtils.UpdateFloatIntDataNode( UniqueId, PropertyInspectorName );
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
OnPropertyNameChanged();
OnDirtyProperty();
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
if( m_cachedPropertyId == -1 )
m_cachedPropertyId = Shader.PropertyToID( "_InputInt" );
if( m_materialMode && m_currentParameterType != PropertyType.Constant )
PreviewMaterial.SetInt( m_cachedPropertyId, m_materialValue );
else
PreviewMaterial.SetInt( m_cachedPropertyId, m_defaultValue );
}
public override void CopyDefaultsToMaterial()
{
m_materialValue = m_defaultValue;
DrawSetAsUINT();
}
public override void DrawSubProperties()
{
m_defaultValue = EditorGUILayoutIntField( Constants.DefaultValueLabel, m_defaultValue );
DrawSetAsUINT();
}
private void DrawSetAsUINT()
{
EditorGUI.BeginChangeCheck();
m_setAsUINT = EditorGUILayoutToggle( "Set as UINT", m_setAsUINT );
if( EditorGUI.EndChangeCheck() )
{
WirePortDataType portType = m_setAsUINT ? WirePortDataType.UINT : WirePortDataType.INT;
m_outputPorts[ 0 ].ChangeType( portType, false );
}
}
public override void DrawMaterialProperties()
{
if( m_materialMode )
EditorGUI.BeginChangeCheck();
m_materialValue = EditorGUILayoutIntField( Constants.MaterialValueLabel, m_materialValue );
if( m_materialMode && EditorGUI.EndChangeCheck() )
{
m_requireMaterialUpdate = true;
}
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_propertyDrawPos = m_remainingBox;
m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom;
m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE;
m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE;
}
public override void DrawGUIControls( DrawInfo drawInfo )
{
base.DrawGUIControls( drawInfo );
if( drawInfo.CurrentEventType != EventType.MouseDown )
return;
Rect hitBox = m_remainingBox;
hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom;
bool insideBox = hitBox.Contains( drawInfo.MousePosition );
if( insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = true;
}
else if( m_isEditingFields && !insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = false;
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( !m_isVisible )
return;
if( m_isEditingFields && m_currentParameterType != PropertyType.Global )
{
float labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = LabelWidth * drawInfo.InvertedZoom;
if( m_materialMode && m_currentParameterType != PropertyType.Constant )
{
EditorGUI.BeginChangeCheck();
m_materialValue = EditorGUIIntField( m_propertyDrawPos, " ", m_materialValue, UIUtils.MainSkin.textField );
if( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
m_requireMaterialUpdate = true;
if( m_currentParameterType != PropertyType.Constant )
BeginDelayedDirtyProperty();
}
}
else
{
EditorGUI.BeginChangeCheck();
m_defaultValue = EditorGUIIntField( m_propertyDrawPos, " ", m_defaultValue, UIUtils.MainSkin.textField );
if( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
BeginDelayedDirtyProperty();
}
}
EditorGUIUtility.labelWidth = labelWidth;
}
else if( drawInfo.CurrentEventType == EventType.Repaint )
{
bool guiEnabled = GUI.enabled;
GUI.enabled = m_currentParameterType != PropertyType.Global;
Rect fakeField = m_propertyDrawPos;
fakeField.xMin += LabelWidth * drawInfo.InvertedZoom;
if( GUI.enabled )
{
Rect fakeLabel = m_propertyDrawPos;
fakeLabel.xMax = fakeField.xMin;
EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow );
EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text );
}
bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant;
int value = currMode ? m_materialValue : m_defaultValue;
if( m_previousValue != value )
{
m_previousValue = value;
m_fieldText = value.ToString();
}
GUI.Label( fakeField, m_fieldText, UIUtils.MainSkin.textField );
GUI.enabled = guiEnabled;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
if( m_currentParameterType != PropertyType.Constant )
return PropertyData( dataCollector.PortCategory );
return m_defaultValue.ToString();
}
public override string GetPropertyValue()
{
return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Int) = " + m_defaultValue;
}
public override void UpdateMaterial( Material mat )
{
base.UpdateMaterial( mat );
if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction )
{
mat.SetInt( m_propertyName, m_materialValue );
}
}
public override void SetMaterialMode( Material mat, bool fetchMaterialValues )
{
base.SetMaterialMode( mat, fetchMaterialValues );
if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) )
{
m_materialValue = mat.GetInt( m_propertyName );
}
}
public override void ForceUpdateFromMaterial( Material material )
{
if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) )
{
m_materialValue = material.GetInt( m_propertyName );
PreviewIsDirty = true;
}
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_defaultValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() > 14101 )
m_materialValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() > 18500 )
m_setAsUINT = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultValue );
IOUtils.AddFieldValueToString( ref nodeInfo, m_materialValue );
IOUtils.AddFieldValueToString( ref nodeInfo, m_setAsUINT );
}
public override string GetPropertyValStr()
{
return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ?
m_materialValue.ToString( Mathf.Abs( m_materialValue ) > 1000 ? Constants.PropertyBigIntFormatLabel : Constants.PropertyIntFormatLabel ) :
m_defaultValue.ToString( Mathf.Abs( m_defaultValue ) > 1000 ? Constants.PropertyBigIntFormatLabel : Constants.PropertyIntFormatLabel );
}
public override void SetGlobalValue() { Shader.SetGlobalInt( m_propertyName, m_defaultValue ); }
public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalInt( m_propertyName ); }
public int Value
{
get { return m_defaultValue; }
set { m_defaultValue = value; }
}
public void SetMaterialValueFromInline( int val )
{
m_materialValue = val;
m_requireMaterialUpdate = true;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 86df2da3da3b1eb4493b968b47030b17
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,261 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Matrix3X3", "Constants And Properties", "Matrix3X3 property" )]
public sealed class Matrix3X3Node : MatrixParentNode
{
private string[,] m_fieldText = new string[ 3, 3 ] { { "0", "0", "0" }, { "0", "0", "0" }, { "0", "0", "0" } };
public Matrix3X3Node() : base() { }
public Matrix3X3Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Matrix" );
AddOutputPort( WirePortDataType.FLOAT3x3, Constants.EmptyPortValue );
m_insideSize.Set( Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE * 3 + Constants.FLOAT_WIDTH_SPACING * 2, Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE * 3 + Constants.FLOAT_WIDTH_SPACING * 2 + Constants.OUTSIDE_WIRE_MARGIN );
//m_defaultValue = new Matrix4x4();
//m_materialValue = new Matrix4x4();
m_drawPreview = false;
}
public override void CopyDefaultsToMaterial()
{
m_materialValue = m_defaultValue;
}
public override void DrawSubProperties()
{
EditorGUILayout.LabelField( Constants.DefaultValueLabel );
for( int row = 0; row < 3; row++ )
{
EditorGUILayout.BeginHorizontal();
for( int column = 0; column < 3; column++ )
{
m_defaultValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_defaultValue[ row, column ], GUILayout.MaxWidth( 76 ) );
}
EditorGUILayout.EndHorizontal();
}
}
public override void DrawMaterialProperties()
{
if( m_materialMode )
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField( Constants.MaterialValueLabel );
for( int row = 0; row < 3; row++ )
{
EditorGUILayout.BeginHorizontal();
for( int column = 0; column < 3; column++ )
{
m_materialValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_materialValue[ row, column ], GUILayout.MaxWidth( 76 ) );
}
EditorGUILayout.EndHorizontal();
}
if( m_materialMode && EditorGUI.EndChangeCheck() )
m_requireMaterialUpdate = true;
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_propertyDrawPos.position = m_remainingBox.position;
m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE;
m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE;
}
public override void DrawGUIControls( DrawInfo drawInfo )
{
base.DrawGUIControls( drawInfo );
if( drawInfo.CurrentEventType != EventType.MouseDown )
return;
Rect hitBox = m_remainingBox;
hitBox.height = m_insideSize.y * drawInfo.InvertedZoom;
bool insideBox = hitBox.Contains( drawInfo.MousePosition );
if( insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = true;
}
else if( m_isEditingFields && !insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = false;
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( !m_isVisible )
return;
if( m_isEditingFields && m_currentParameterType != PropertyType.Global )
{
bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant;
Matrix4x4 value = currMode ? m_materialValue : m_defaultValue;
EditorGUI.BeginChangeCheck();
for( int row = 0; row < 3; row++ )
{
for( int column = 0; column < 3; column++ )
{
m_propertyDrawPos.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row );
value[ row, column ] = EditorGUIFloatField( m_propertyDrawPos, string.Empty, value[ row, column ], UIUtils.MainSkin.textField );
}
}
if( currMode )
{
m_materialValue = value;
}
else
{
m_defaultValue = value;
}
if( EditorGUI.EndChangeCheck() )
{
m_requireMaterialUpdate = m_materialMode;
BeginDelayedDirtyProperty();
}
}
else if( drawInfo.CurrentEventType == EventType.Repaint )
{
bool guiEnabled = GUI.enabled;
GUI.enabled = m_currentParameterType != PropertyType.Global;
bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant;
Matrix4x4 value = currMode ? m_materialValue : m_defaultValue;
for( int row = 0; row < 3; row++ )
{
for( int column = 0; column < 3; column++ )
{
Rect fakeField = m_propertyDrawPos;
fakeField.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row );
if( GUI.enabled )
EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text );
if( m_previousValue[ row, column ] != value[ row, column ] )
{
m_previousValue[ row, column ] = value[ row, column ];
m_fieldText[ row, column ] = value[ row, column ].ToString();
}
GUI.Label( fakeField, m_fieldText[ row, column ], UIUtils.MainSkin.textField );
}
}
GUI.enabled = guiEnabled;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
if( m_currentParameterType != PropertyType.Constant )
{
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
string localVarName = PropertyData( dataCollector.PortCategory ) + "Local3x3";
string localVarValue = string.Format( "float3x3({0}._m00,{0}._m01,{0}._m02,{0}._m10,{0}._m11,{0}._m12,{0}._m20,{0}._m21,{0}._m22 )", PropertyData( dataCollector.PortCategory ) );
RegisterLocalVariable( 0, localVarValue, ref dataCollector, localVarName );
return localVarName;
}
Matrix4x4 value = m_defaultValue;
return m_precisionString + "(" + value[ 0, 0 ] + "," + value[ 0, 1 ] + "," + value[ 0, 2 ] + "," +
+value[ 1, 0 ] + "," + value[ 1, 1 ] + "," + value[ 1, 2 ] + "," +
+value[ 2, 0 ] + "," + value[ 2, 1 ] + "," + value[ 2, 2 ] + ")";
}
public override void UpdateMaterial( Material mat )
{
base.UpdateMaterial( mat );
if( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction )
{
Shader.SetGlobalMatrix( m_propertyName, m_materialValue );
//mat.SetMatrix( m_propertyName, m_materialValue );
}
}
public override bool GetUniformData( out string dataType, out string dataName, ref bool fullValue )
{
dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, WirePortDataType.FLOAT4x4 );
dataName = m_propertyName;
return true;
}
public override void SetMaterialMode( Material mat, bool fetchMaterialValues )
{
base.SetMaterialMode( mat, fetchMaterialValues );
if( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) )
{
m_materialValue = mat.GetMatrix( m_propertyName );
}
}
public override void ForceUpdateFromMaterial( Material material )
{
if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) )
{
m_materialValue = material.GetMatrix( m_propertyName );
PreviewIsDirty = true;
}
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_defaultValue = IOUtils.StringToMatrix3x3( GetCurrentParam( ref nodeParams ) );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix3x3ToString( m_defaultValue ) );
}
public override void ReadAdditionalClipboardData( ref string[] nodeParams )
{
base.ReadAdditionalClipboardData( ref nodeParams );
m_materialValue = IOUtils.StringToMatrix3x3( GetCurrentParam( ref nodeParams ) );
}
public override void WriteAdditionalClipboardData( ref string nodeInfo )
{
base.WriteAdditionalClipboardData( ref nodeInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix3x3ToString( m_materialValue ) );
}
public override string GetPropertyValStr()
{
return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue[ 0, 0 ].ToString( Mathf.Abs( m_materialValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 1 ].ToString( Mathf.Abs( m_materialValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 2 ].ToString( Mathf.Abs( m_materialValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_materialValue[ 1, 0 ].ToString( Mathf.Abs( m_materialValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 1 ].ToString( Mathf.Abs( m_materialValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 2 ].ToString( Mathf.Abs( m_materialValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_materialValue[ 2, 0 ].ToString( Mathf.Abs( m_materialValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 1 ].ToString( Mathf.Abs( m_materialValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 2 ].ToString( Mathf.Abs( m_materialValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) :
m_defaultValue[ 0, 0 ].ToString( Mathf.Abs( m_defaultValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 1 ].ToString( Mathf.Abs( m_defaultValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 2 ].ToString( Mathf.Abs( m_defaultValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_defaultValue[ 1, 0 ].ToString( Mathf.Abs( m_defaultValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 1 ].ToString( Mathf.Abs( m_defaultValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 2 ].ToString( Mathf.Abs( m_defaultValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_defaultValue[ 2, 0 ].ToString( Mathf.Abs( m_defaultValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 1 ].ToString( Mathf.Abs( m_defaultValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 2 ].ToString( Mathf.Abs( m_defaultValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 01e5a5829caac674fa819ed229de31b6
timeCreated: 1481126953
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,248 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Matrix4X4", "Constants And Properties", "Matrix4X4 property" )]
public sealed class Matrix4X4Node : MatrixParentNode
{
private string[,] m_fieldText = new string[ 4, 4 ] { { "0", "0", "0", "0" }, { "0", "0", "0", "0" }, { "0", "0", "0", "0" }, { "0", "0", "0", "0" } };
public Matrix4X4Node() : base() { }
public Matrix4X4Node( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Matrix" );
AddOutputPort( WirePortDataType.FLOAT4x4, Constants.EmptyPortValue );
m_insideSize.Set( Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE * 4 + Constants.FLOAT_WIDTH_SPACING * 3, Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE * 4 + Constants.FLOAT_WIDTH_SPACING * 3 + Constants.OUTSIDE_WIRE_MARGIN );
//m_defaultValue = new Matrix4x4();
//m_materialValue = new Matrix4x4();
m_drawPreview = false;
}
public override void CopyDefaultsToMaterial()
{
m_materialValue = m_defaultValue;
}
public override void DrawSubProperties()
{
EditorGUILayout.LabelField( Constants.DefaultValueLabel );
for ( int row = 0; row < 4; row++ )
{
EditorGUILayout.BeginHorizontal();
for ( int column = 0; column < 4; column++ )
{
m_defaultValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_defaultValue[ row, column ], GUILayout.MaxWidth( 55 ) );
}
EditorGUILayout.EndHorizontal();
}
}
public override void DrawMaterialProperties()
{
if ( m_materialMode )
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField( Constants.MaterialValueLabel );
for ( int row = 0; row < 4; row++ )
{
EditorGUILayout.BeginHorizontal();
for ( int column = 0; column < 4; column++ )
{
m_materialValue[ row, column ] = EditorGUILayoutFloatField( string.Empty, m_materialValue[ row, column ], GUILayout.MaxWidth( 55 ) );
}
EditorGUILayout.EndHorizontal();
}
if ( m_materialMode && EditorGUI.EndChangeCheck() )
m_requireMaterialUpdate = true;
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_propertyDrawPos.position = m_remainingBox.position;
m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE;
m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE;
}
public override void DrawGUIControls( DrawInfo drawInfo )
{
base.DrawGUIControls( drawInfo );
if ( drawInfo.CurrentEventType != EventType.MouseDown )
return;
Rect hitBox = m_remainingBox;
hitBox.height = m_insideSize.y * drawInfo.InvertedZoom;
bool insideBox = hitBox.Contains( drawInfo.MousePosition );
if ( insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = true;
}
else if ( m_isEditingFields && !insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = false;
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if ( !m_isVisible )
return;
if ( m_isEditingFields && m_currentParameterType != PropertyType.Global )
{
bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant;
Matrix4x4 value = currMode ? m_materialValue : m_defaultValue;
EditorGUI.BeginChangeCheck();
for ( int row = 0; row < 4; row++ )
{
for ( int column = 0; column < 4; column++ )
{
m_propertyDrawPos.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row );
value[ row, column ] = EditorGUIFloatField( m_propertyDrawPos, string.Empty, value[ row, column ], UIUtils.MainSkin.textField );
}
}
if ( currMode )
{
m_materialValue = value;
}
else
{
m_defaultValue = value;
}
if ( EditorGUI.EndChangeCheck() )
{
m_requireMaterialUpdate = m_materialMode;
BeginDelayedDirtyProperty();
}
}
else if ( drawInfo.CurrentEventType == EventType.Repaint )
{
bool guiEnabled = GUI.enabled;
GUI.enabled = m_currentParameterType != PropertyType.Global;
bool currMode = m_materialMode && m_currentParameterType != PropertyType.Constant;
Matrix4x4 value = currMode ? m_materialValue : m_defaultValue;
for ( int row = 0; row < 4; row++ )
{
for ( int column = 0; column < 4; column++ )
{
Rect fakeField = m_propertyDrawPos;
fakeField.position = m_remainingBox.position + Vector2.Scale( m_propertyDrawPos.size, new Vector2( column, row ) ) + new Vector2( Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * column, Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * row );
if( GUI.enabled )
EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text );
if ( m_previousValue[ row, column ] != value[ row, column ] )
{
m_previousValue[ row, column ] = value[ row, column ];
m_fieldText[ row, column ] = value[ row, column ].ToString();
}
GUI.Label( fakeField, m_fieldText[ row, column ], UIUtils.MainSkin.textField );
}
}
GUI.enabled = guiEnabled;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
if ( m_currentParameterType != PropertyType.Constant )
return PropertyData( dataCollector.PortCategory );
Matrix4x4 value = m_defaultValue;
return m_precisionString+"(" + value[ 0, 0 ] + "," + value[ 0, 1 ] + "," + value[ 0, 2 ] + "," + value[ 0, 3 ] + "," +
+value[ 1, 0 ] + "," + value[ 1, 1 ] + "," + value[ 1, 2 ] + "," + value[ 1, 3 ] + "," +
+value[ 2, 0 ] + "," + value[ 2, 1 ] + "," + value[ 2, 2 ] + "," + value[ 2, 3 ] + "," +
+value[ 3, 0 ] + "," + value[ 3, 1 ] + "," + value[ 3, 2 ] + "," + value[ 3, 3 ] + ")";
}
public override void UpdateMaterial( Material mat )
{
base.UpdateMaterial( mat );
if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction )
{
mat.SetMatrix( m_propertyName, m_materialValue );
}
}
public override void SetMaterialMode( Material mat , bool fetchMaterialValues )
{
base.SetMaterialMode( mat , fetchMaterialValues );
if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) )
{
m_materialValue = mat.GetMatrix( m_propertyName );
}
}
public override void ForceUpdateFromMaterial( Material material )
{
if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) )
{
m_materialValue = material.GetMatrix( m_propertyName );
PreviewIsDirty = true;
}
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_defaultValue = IOUtils.StringToMatrix4x4( GetCurrentParam( ref nodeParams ) );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix4x4ToString( m_defaultValue ) );
}
public override void ReadAdditionalClipboardData( ref string[] nodeParams )
{
base.ReadAdditionalClipboardData( ref nodeParams );
m_materialValue = IOUtils.StringToMatrix4x4( GetCurrentParam( ref nodeParams ) );
}
public override void WriteAdditionalClipboardData( ref string nodeInfo )
{
base.WriteAdditionalClipboardData( ref nodeInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Matrix4x4ToString( m_materialValue ) );
}
public override string GetPropertyValStr()
{
return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ? m_materialValue[ 0, 0 ].ToString( Mathf.Abs( m_materialValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 1 ].ToString( Mathf.Abs( m_materialValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 2 ].ToString( Mathf.Abs( m_materialValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 0, 3 ].ToString( Mathf.Abs( m_materialValue[ 0, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_materialValue[ 1, 0 ].ToString( Mathf.Abs( m_materialValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 1 ].ToString( Mathf.Abs( m_materialValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 2 ].ToString( Mathf.Abs( m_materialValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 1, 3 ].ToString( Mathf.Abs( m_materialValue[ 1, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_materialValue[ 2, 0 ].ToString( Mathf.Abs( m_materialValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 1 ].ToString( Mathf.Abs( m_materialValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 2 ].ToString( Mathf.Abs( m_materialValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 2, 3 ].ToString( Mathf.Abs( m_materialValue[ 2, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_materialValue[ 3, 0 ].ToString( Mathf.Abs( m_materialValue[ 3, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 1 ].ToString( Mathf.Abs( m_materialValue[ 3, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 2 ].ToString( Mathf.Abs( m_materialValue[ 3, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_materialValue[ 3, 3 ].ToString( Mathf.Abs( m_materialValue[ 3, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) :
m_defaultValue[ 0, 0 ].ToString( Mathf.Abs( m_defaultValue[ 0, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 1 ].ToString( Mathf.Abs( m_defaultValue[ 0, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 2 ].ToString( Mathf.Abs( m_defaultValue[ 0, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 0, 3 ].ToString( Mathf.Abs( m_defaultValue[ 0, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_defaultValue[ 1, 0 ].ToString( Mathf.Abs( m_defaultValue[ 1, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 1 ].ToString( Mathf.Abs( m_defaultValue[ 1, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 2 ].ToString( Mathf.Abs( m_defaultValue[ 1, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 1, 3 ].ToString( Mathf.Abs( m_defaultValue[ 1, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_defaultValue[ 2, 0 ].ToString( Mathf.Abs( m_defaultValue[ 2, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 1 ].ToString( Mathf.Abs( m_defaultValue[ 2, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 2 ].ToString( Mathf.Abs( m_defaultValue[ 2, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 2, 3 ].ToString( Mathf.Abs( m_defaultValue[ 2, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.MATRIX_DATA_SEPARATOR +
m_defaultValue[ 3, 0 ].ToString( Mathf.Abs( m_defaultValue[ 3, 0 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 1 ].ToString( Mathf.Abs( m_defaultValue[ 3, 1 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 2 ].ToString( Mathf.Abs( m_defaultValue[ 3, 2 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel ) + IOUtils.VECTOR_SEPARATOR + m_defaultValue[ 3, 3 ].ToString( Mathf.Abs( m_defaultValue[ 3, 3 ] ) > 1000 ? Constants.PropertyBigMatrixFormatLabel : Constants.PropertyMatrixFormatLabel );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4fa5db614b9379b4da27edafa0a8f4e9
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
public class MatrixParentNode : PropertyNode
{
private readonly string[] AvailablePropertyTypeLabels = { PropertyType.Constant.ToString(), PropertyType.Global.ToString(), "Instanced" };
private readonly int[] AvailablePropertyTypeValues = { (int)PropertyType.Constant, (int)PropertyType.Global , (int)PropertyType.InstancedProperty };
protected bool m_isEditingFields;
[SerializeField]
protected Matrix4x4 m_defaultValue = Matrix4x4.identity;
[SerializeField]
protected Matrix4x4 m_materialValue = Matrix4x4.identity;
[NonSerialized]
protected Matrix4x4 m_previousValue;
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
public MatrixParentNode() : base() { }
public MatrixParentNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
m_freeType = false;
m_showVariableMode = true;
}
public override void AfterCommonInit()
{
base.AfterCommonInit();
m_hasLeftDropdown = true;
m_drawAttributes = false;
m_availableAttribs.Clear();
if( PaddingTitleLeft == 0 )
{
PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
if( PaddingTitleRight == 0 )
PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
}
}
protected void DrawParameterType()
{
PropertyType parameterType = (PropertyType)EditorGUILayoutIntPopup( ParameterTypeStr, (int)m_currentParameterType, AvailablePropertyTypeLabels, AvailablePropertyTypeValues );
if( parameterType != m_currentParameterType )
{
ChangeParameterType( parameterType );
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
PropertyType parameterType = (PropertyType)m_upperLeftWidget.DrawWidget( this, (int)m_currentParameterType, AvailablePropertyTypeLabels, AvailablePropertyTypeValues );
if( parameterType != m_currentParameterType )
{
ChangeParameterType( parameterType );
}
}
public override void DrawMainPropertyBlock()
{
DrawParameterType();
base.DrawMainPropertyBlock();
}
public override void Destroy()
{
base.Destroy();
m_upperLeftWidget = null;
}
public override void SetGlobalValue() { Shader.SetGlobalMatrix( m_propertyName, m_defaultValue ); }
public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalMatrix( m_propertyName ); }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d31dc25864c509a4f967e32079a27d6f
timeCreated: 1507902748
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "PI", "Constants And Properties", "PI constant : 3.14159265359" )]
public sealed class PiNode : ParentNode
{
public PiNode() : base() { }
public PiNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT, true, "Multiplier" );
AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
m_textLabelWidth = 70;
InputPorts[ 0 ].FloatInternalData = 1;
m_useInternalPortData = true;
m_previewShaderGUID = "bf4a65726dab3d445a69fb1d0945c33e";
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
string finalValue = string.Empty;
string piString = dataCollector.IsSRP ? "PI" : "UNITY_PI";
if( !InputPorts[ 0 ].IsConnected && InputPorts[ 0 ].FloatInternalData == 1 )
{
finalValue = piString;
} else
{
string multiplier = InputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
finalValue = "( " + multiplier + " * " + piString + " )";
}
if ( finalValue.Equals( string.Empty ) )
{
UIUtils.ShowMessage( UniqueId, "PINode generating empty code", MessageSeverity.Warning );
}
return finalValue;
}
//public override void ReadFromString( ref string[] nodeParams )
//{
// base.ReadFromString( ref nodeParams );
// Removed on version 5004
//m_value = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
//}
//public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
//{
// base.WriteToString( ref nodeInfo, ref connectionsInfo );
//}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a8a03953b97a594b81b2fb71d4a57ec
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5bbfd66571b12f84983b398231271694
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,535 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Float", "Constants And Properties", "Float property", null, KeyCode.Alpha1 )]
public sealed class RangedFloatNode : PropertyNode
{
private const int OriginalFontSize = 11;
private const string MinValueStr = "Min";
private const string MaxValueStr = "Max";
private const float LabelWidth = 8;
[SerializeField]
private float m_defaultValue = 0;
[SerializeField]
private float m_materialValue = 0;
[SerializeField]
private float m_min = 0;
[SerializeField]
private float m_max = 0;
[SerializeField]
private bool m_floatMode = true;
private int m_cachedPropertyId = -1;
private bool m_isEditingFields;
private Vector3 m_previousValue = Vector3.zero;
private string[] m_fieldText = new string[] { "0", "0", "0" };
public RangedFloatNode() : base() { }
public RangedFloatNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
GlobalTypeWarningText = string.Format( GlobalTypeWarningText, "Float" );
AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
m_insideSize.Set( 50, 0 );
m_showPreview = false;
m_showHybridInstancedUI = true;
m_selectedLocation = PreviewLocation.BottomCenter;
m_availableAttribs.Add( new PropertyAttributes( "Toggle", "[Toggle]" ) );
#if UNITY_2018_1_OR_NEWER
m_availableAttribs.Add( new PropertyAttributes( "No Keyword Toggle", "[ToggleUI]","[NoKeywordToggle]" ) );
#else
m_availableAttribs.Add( new PropertyAttributes( "No Keyword Toggle", "[NoKeywordToggle]" ) );
#endif
m_availableAttribs.Add( new PropertyAttributes( "Int Range", "[IntRange]" ) );
m_availableAttribs.Add( new PropertyAttributes( "Enum", "[Enum]" ) );
m_previewShaderGUID = "d9ca47581ac157145bff6f72ac5dd73e";
m_srpBatcherCompatible = true;
}
protected override void OnUniqueIDAssigned()
{
base.OnUniqueIDAssigned();
UIUtils.RegisterFloatIntNode( this );
}
public override void Destroy()
{
base.Destroy();
UIUtils.UnregisterFloatIntNode( this );
}
public override void OnDirtyProperty()
{
UIUtils.UpdateFloatIntDataNode( UniqueId, PropertyInspectorName );
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
OnPropertyNameChanged();
OnDirtyProperty();
}
public void SetFloatMode( bool value )
{
if ( m_floatMode == value )
return;
m_floatMode = value;
if ( value )
{
m_insideSize.x = 50;// + ( m_showPreview ? 50 : 0 );
//m_firstPreviewDraw = true;
}
else
{
m_insideSize.x = 200;// + ( m_showPreview ? 0 : 0 );
//m_firstPreviewDraw = true;
}
m_sizeIsDirty = true;
}
public override void CopyDefaultsToMaterial()
{
m_materialValue = m_defaultValue;
}
void DrawMinMaxUI()
{
EditorGUI.BeginChangeCheck();
m_min = EditorGUILayoutFloatField( MinValueStr, m_min );
m_max = EditorGUILayoutFloatField( MaxValueStr, m_max );
if ( m_min > m_max )
m_min = m_max;
if ( m_max < m_min )
m_max = m_min;
if ( EditorGUI.EndChangeCheck() )
{
SetFloatMode( m_min == m_max );
}
}
public override void DrawSubProperties()
{
DrawMinMaxUI();
if ( m_floatMode )
{
m_defaultValue = EditorGUILayoutFloatField( Constants.DefaultValueLabel, m_defaultValue );
}
else
{
m_defaultValue = EditorGUILayoutSlider( Constants.DefaultValueLabel, m_defaultValue, m_min, m_max );
}
}
public override void DrawMaterialProperties()
{
DrawMinMaxUI();
EditorGUI.BeginChangeCheck();
if ( m_floatMode )
{
m_materialValue = EditorGUILayoutFloatField( Constants.MaterialValueLabel, m_materialValue );
}
else
{
m_materialValue = EditorGUILayoutSlider( Constants.MaterialValueLabel, m_materialValue, m_min, m_max );
}
if ( EditorGUI.EndChangeCheck() )
{
//MarkForPreviewUpdate();
if ( m_materialMode )
m_requireMaterialUpdate = true;
}
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
if ( m_cachedPropertyId == -1 )
m_cachedPropertyId = Shader.PropertyToID( "_InputFloat" );
if ( m_materialMode && m_currentParameterType != PropertyType.Constant )
PreviewMaterial.SetFloat( m_cachedPropertyId, m_materialValue );
else
PreviewMaterial.SetFloat( m_cachedPropertyId, m_defaultValue );
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
if ( m_floatMode )
{
m_propertyDrawPos = m_remainingBox;
m_propertyDrawPos.x = m_remainingBox.x - LabelWidth * drawInfo.InvertedZoom;
m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE;
m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE;
}
else
{
m_propertyDrawPos = m_remainingBox;
m_propertyDrawPos.width = m_outputPorts[ 0 ].Position.x - m_propertyDrawPos.x - (m_outputPorts[ 0 ].LabelSize.x + (Constants.PORT_TO_LABEL_SPACE_X + 3) * drawInfo.InvertedZoom + 2);
m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE;
}
}
public override void DrawGUIControls( DrawInfo drawInfo )
{
base.DrawGUIControls( drawInfo );
if ( drawInfo.CurrentEventType != EventType.MouseDown )
return;
Rect hitBox = m_remainingBox;
hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom;
bool insideBox = hitBox.Contains( drawInfo.MousePosition );
if ( insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = true;
}
else if ( m_isEditingFields && !insideBox )
{
GUI.FocusControl( null );
m_isEditingFields = false;
}
}
void DrawFakeFloatMaterial( DrawInfo drawInfo )
{
if( m_floatMode )
{
//UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_materialValue, LabelWidth * drawInfo.InvertedZoom );
Rect fakeField = m_propertyDrawPos;
fakeField.xMin += LabelWidth * drawInfo.InvertedZoom;
if( GUI.enabled )
{
Rect fakeLabel = m_propertyDrawPos;
fakeLabel.xMax = fakeField.xMin;
EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow );
EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text );
}
if( m_previousValue[ 0 ] != m_materialValue )
{
m_previousValue[ 0 ] = m_materialValue;
m_fieldText[ 0 ] = m_materialValue.ToString();
}
GUI.Label( fakeField, m_fieldText[ 0 ], UIUtils.MainSkin.textField );
}
else
{
DrawFakeSlider( ref m_materialValue, drawInfo );
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if ( !m_isVisible )
return;
if ( m_isEditingFields && m_currentParameterType != PropertyType.Global )
{
if ( m_materialMode && m_currentParameterType != PropertyType.Constant )
{
EditorGUI.BeginChangeCheck();
if ( m_floatMode )
{
UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_materialValue, LabelWidth * drawInfo.InvertedZoom );
}
else
{
DrawSlider( ref m_materialValue, drawInfo );
}
if ( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
m_requireMaterialUpdate = true;
if ( m_currentParameterType != PropertyType.Constant )
{
BeginDelayedDirtyProperty();
}
}
}
else
{
EditorGUI.BeginChangeCheck();
if ( m_floatMode )
{
UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_defaultValue, LabelWidth * drawInfo.InvertedZoom );
}
else
{
DrawSlider( ref m_defaultValue, drawInfo );
}
if ( EditorGUI.EndChangeCheck() )
{
PreviewIsDirty = true;
BeginDelayedDirtyProperty();
}
}
}
else if ( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
{
if( m_currentParameterType == PropertyType.Global )
{
bool guiEnabled = GUI.enabled;
GUI.enabled = false;
DrawFakeFloatMaterial( drawInfo );
GUI.enabled = guiEnabled;
}
else if ( m_materialMode && m_currentParameterType != PropertyType.Constant )
{
DrawFakeFloatMaterial( drawInfo );
}
else
{
if ( m_floatMode )
{
//UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_defaultValue, LabelWidth * drawInfo.InvertedZoom );
Rect fakeField = m_propertyDrawPos;
fakeField.xMin += LabelWidth * drawInfo.InvertedZoom;
Rect fakeLabel = m_propertyDrawPos;
fakeLabel.xMax = fakeField.xMin;
EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow );
EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text );
if ( m_previousValue[ 0 ] != m_defaultValue )
{
m_previousValue[ 0 ] = m_defaultValue;
m_fieldText[ 0 ] = m_defaultValue.ToString();
}
GUI.Label( fakeField, m_fieldText[ 0 ], UIUtils.MainSkin.textField );
}
else
{
DrawFakeSlider( ref m_defaultValue, drawInfo );
}
}
}
}
void DrawFakeSlider( ref float value, DrawInfo drawInfo )
{
float rangeWidth = 30 * drawInfo.InvertedZoom;
float rangeSpacing = 5 * drawInfo.InvertedZoom;
//Min
Rect minRect = m_propertyDrawPos;
minRect.width = rangeWidth;
EditorGUIUtility.AddCursorRect( minRect, MouseCursor.Text );
if ( m_previousValue[ 1 ] != m_min )
{
m_previousValue[ 1 ] = m_min;
m_fieldText[ 1 ] = m_min.ToString();
}
GUI.Label( minRect, m_fieldText[ 1 ], UIUtils.MainSkin.textField );
//Value Area
Rect valRect = m_propertyDrawPos;
valRect.width = rangeWidth;
valRect.x = m_propertyDrawPos.xMax - rangeWidth - rangeWidth - rangeSpacing;
EditorGUIUtility.AddCursorRect( valRect, MouseCursor.Text );
if ( m_previousValue[ 0 ] != value )
{
m_previousValue[ 0 ] = value;
m_fieldText[ 0 ] = value.ToString();
}
GUI.Label( valRect, m_fieldText[ 0 ], UIUtils.MainSkin.textField );
//Max
Rect maxRect = m_propertyDrawPos;
maxRect.width = rangeWidth;
maxRect.x = m_propertyDrawPos.xMax - rangeWidth;
EditorGUIUtility.AddCursorRect( maxRect, MouseCursor.Text );
if ( m_previousValue[ 2 ] != m_max )
{
m_previousValue[ 2 ] = m_max;
m_fieldText[ 2 ] = m_max.ToString();
}
GUI.Label( maxRect, m_fieldText[ 2 ], UIUtils.MainSkin.textField );
Rect sliderValRect = m_propertyDrawPos;
sliderValRect.x = minRect.xMax + rangeSpacing;
sliderValRect.xMax = valRect.xMin - rangeSpacing;
Rect sliderBackRect = sliderValRect;
sliderBackRect.height = 5 * drawInfo.InvertedZoom;
sliderBackRect.center = new Vector2( sliderValRect.center.x, Mathf.Round( sliderValRect.center.y ) );
GUI.Label( sliderBackRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SliderStyle ) );
sliderValRect.width = 10;
float percent = ( value - m_min) / ( m_max-m_min );
percent = Mathf.Clamp01( percent );
sliderValRect.x += percent * (sliderBackRect.width - 10 * drawInfo.InvertedZoom );
GUI.Label( sliderValRect, string.Empty, UIUtils.RangedFloatSliderThumbStyle );
}
void DrawSlider( ref float value, DrawInfo drawInfo )
{
float rangeWidth = 30 * drawInfo.InvertedZoom;
float rangeSpacing = 5 * drawInfo.InvertedZoom;
//Min
Rect minRect = m_propertyDrawPos;
minRect.width = rangeWidth;
m_min = EditorGUIFloatField( minRect, m_min, UIUtils.MainSkin.textField );
//Value Area
Rect valRect = m_propertyDrawPos;
valRect.width = rangeWidth;
valRect.x = m_propertyDrawPos.xMax - rangeWidth - rangeWidth - rangeSpacing;
value = EditorGUIFloatField( valRect, value, UIUtils.MainSkin.textField );
//Max
Rect maxRect = m_propertyDrawPos;
maxRect.width = rangeWidth;
maxRect.x = m_propertyDrawPos.xMax - rangeWidth;
m_max = EditorGUIFloatField( maxRect, m_max, UIUtils.MainSkin.textField );
//Value Slider
Rect sliderValRect = m_propertyDrawPos;
sliderValRect.x = minRect.xMax + rangeSpacing;
sliderValRect.xMax = valRect.xMin - rangeSpacing;
Rect sliderBackRect = sliderValRect;
sliderBackRect.height = 5 * drawInfo.InvertedZoom;
sliderBackRect.center = new Vector2( sliderValRect.center.x, Mathf.Round( sliderValRect.center.y ));
GUI.Label( sliderBackRect, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SliderStyle ) );
value = GUIHorizontalSlider( sliderValRect, value, m_min, m_max, GUIStyle.none, UIUtils.RangedFloatSliderThumbStyle );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
if ( m_currentParameterType != PropertyType.Constant )
return PropertyData( dataCollector.PortCategory );
return IOUtils.Floatify( m_defaultValue );
}
public override string GetPropertyValue()
{
if ( m_floatMode )
{
return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Float) = " + m_defaultValue;
}
else
{
return PropertyAttributes + m_propertyName + "(\"" + m_propertyInspectorName + "\", Range( " + m_min + " , " + m_max + ")) = " + m_defaultValue;
}
}
public override void UpdateMaterial( Material mat )
{
base.UpdateMaterial( mat );
if ( UIUtils.IsProperty( m_currentParameterType ) && !InsideShaderFunction )
{
mat.SetFloat( m_propertyName, m_materialValue );
}
}
public override void SetMaterialMode( Material mat , bool fetchMaterialValues )
{
base.SetMaterialMode( mat , fetchMaterialValues );
if ( fetchMaterialValues && m_materialMode && UIUtils.IsProperty( m_currentParameterType ) && mat.HasProperty( m_propertyName ) )
{
m_materialValue = mat.GetFloat( m_propertyName );
}
}
public override void ForceUpdateFromMaterial( Material material )
{
if( UIUtils.IsProperty( m_currentParameterType ) && material.HasProperty( m_propertyName ) )
{
m_materialValue = material.GetFloat( m_propertyName );
PreviewIsDirty = true;
}
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_defaultValue = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() > 14101 )
{
m_materialValue = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
}
m_min = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
m_max = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
SetFloatMode( m_min == m_max );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultValue );
IOUtils.AddFieldValueToString( ref nodeInfo, m_materialValue );
IOUtils.AddFieldValueToString( ref nodeInfo, m_min );
IOUtils.AddFieldValueToString( ref nodeInfo, m_max );
}
public override string GetPropertyValStr()
{
return ( m_materialMode && m_currentParameterType != PropertyType.Constant ) ?
m_materialValue.ToString( Mathf.Abs( m_materialValue ) > 1000 ? Constants.PropertyBigFloatFormatLabel : Constants.PropertyFloatFormatLabel ) :
m_defaultValue.ToString( Mathf.Abs( m_defaultValue ) > 1000 ? Constants.PropertyBigFloatFormatLabel : Constants.PropertyFloatFormatLabel );
}
public override void SetGlobalValue() { Shader.SetGlobalFloat( m_propertyName, m_defaultValue ); }
public override void FetchGlobalValue() { m_materialValue = Shader.GetGlobalFloat( m_propertyName ); }
public float Value
{
get { return m_defaultValue; }
set { m_defaultValue = value; }
}
public void SetMaterialValueFromInline( float val )
{
m_materialValue = val;
m_requireMaterialUpdate = true;
}
public override void GeneratePPSInfo( ref string propertyDeclaration, ref string propertySet )
{
string additionalHeaders = string.Empty;
if( !m_floatMode )
{
additionalHeaders = string.Format( "Range( {0}, {1} ),", m_min, m_max );
}
propertyDeclaration += string.Format( ASEPPSHelperTool.PPSPropertyDecFormat, additionalHeaders, PropertyInspectorName,
ASEPPSHelperTool.WireToPPSType[ WirePortDataType.FLOAT ], PropertyName, m_defaultValue );
propertySet += string.Format( ASEPPSHelperTool.PPSPropertySetFormat, "Float", PropertyName );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e81453c5ad3b8224db874b56bf00cad2
timeCreated: 1481126960
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 92f993d3ba8b1394eaf8c4fe308cab11
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8c4b0845954941d4d9809abaa67bdc2b
folderAsset: yes
timeCreated: 1481126947
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
public enum BuiltInShaderCameraTypes
{
unity_CameraProjection = 0,
unity_CameraInvProjection
}
[Serializable]
[NodeAttributes( "Projection Matrices", "Camera And Screen", "Camera's Projection/Inverse Projection matrix" )]
public sealed class CameraProjectionNode : ShaderVariablesNode
{
private const string _projMatrixLabelStr = "Projection Matrix";
private readonly string[] _projMatrixValuesStr = { "Camera Projection",
"Inverse Camera Projection"};
[SerializeField]
private BuiltInShaderCameraTypes m_selectedType = BuiltInShaderCameraTypes.unity_CameraProjection;
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, _projMatrixValuesStr[ (int)m_selectedType ], WirePortDataType.FLOAT4x4 );
m_textLabelWidth = 115;
m_autoWrapProperties = true;
m_hasLeftDropdown = true;
}
public override void AfterCommonInit()
{
base.AfterCommonInit();
if( PaddingTitleLeft == 0 )
{
PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
if( PaddingTitleRight == 0 )
PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
}
}
public override void Destroy()
{
base.Destroy();
m_upperLeftWidget = null;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
EditorGUI.BeginChangeCheck();
m_selectedType = (BuiltInShaderCameraTypes)m_upperLeftWidget.DrawWidget( this, (int)m_selectedType, _projMatrixValuesStr );
if( EditorGUI.EndChangeCheck() )
{
ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] );
SetSaveIsDirty();
}
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_selectedType = (BuiltInShaderCameraTypes)EditorGUILayoutPopup( _projMatrixLabelStr, (int)m_selectedType, _projMatrixValuesStr );
if( EditorGUI.EndChangeCheck() )
{
ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] );
SetSaveIsDirty();
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector );
return m_selectedType.ToString();
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_selectedType = (BuiltInShaderCameraTypes)Enum.Parse( typeof( BuiltInShaderCameraTypes ), GetCurrentParam( ref nodeParams ) );
ChangeOutputName( 0, _projMatrixValuesStr[ (int)m_selectedType ] );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f776bdd36b750304c8e0de8ee1f31fc0
timeCreated: 1481126960
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
public enum BuiltInShaderClipPlanesTypes
{
Left = 0,
Right,
Bottom,
Top,
Near,
Far
}
[Serializable]
[NodeAttributes( "Clip Planes", "Camera And Screen", "Camera World Clip Planes" )]
public sealed class CameraWorldClipPlanes : ShaderVariablesNode
{
[SerializeField]
private BuiltInShaderClipPlanesTypes m_selectedType = BuiltInShaderClipPlanesTypes.Left;
private const string LabelStr = "Plane";
private const string ValueStr = "unity_CameraWorldClipPlanes";
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
private int m_planeId;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "ABCD", WirePortDataType.FLOAT4 );
m_textLabelWidth = 55;
m_autoWrapProperties = true;
m_hasLeftDropdown = true;
SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) );
m_previewShaderGUID = "6afe5a4ad7bbd0e4ab352c758f543a09";
}
public override void OnEnable()
{
base.OnEnable();
m_planeId = Shader.PropertyToID( "_PlaneId" );
}
public override void AfterCommonInit()
{
base.AfterCommonInit();
if( PaddingTitleLeft == 0 )
{
PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
if( PaddingTitleRight == 0 )
PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
}
}
public override void Destroy()
{
base.Destroy();
m_upperLeftWidget = null;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
m_upperLeftWidget.DrawWidget<BuiltInShaderClipPlanesTypes>(ref m_selectedType, this, OnWidgetUpdate );
}
private readonly Action<ParentNode> OnWidgetUpdate = ( x ) => {
x.SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, ( x as CameraWorldClipPlanes ).Type ) );
};
public BuiltInShaderClipPlanesTypes Type { get { return m_selectedType; } }
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_selectedType = ( BuiltInShaderClipPlanesTypes ) EditorGUILayoutEnumPopup( LabelStr, m_selectedType );
if ( EditorGUI.EndChangeCheck() )
{
SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) );
SetSaveIsDirty();
}
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
PreviewMaterial.SetInt( m_planeId, (int)m_selectedType );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
return ValueStr + "[" + ( int ) m_selectedType + "]";
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_selectedType = ( BuiltInShaderClipPlanesTypes ) Enum.Parse( typeof( BuiltInShaderClipPlanesTypes ), GetCurrentParam( ref nodeParams ) );
SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_selectedType ) );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e5a9a010f1c8dda449c8ca7ee9e25869
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Ortho Params", "Camera And Screen", "Orthographic Parameters" )]
public sealed class OrthoParams : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "Ortho Cam Width" );
ChangeOutputName( 2, "Ortho Cam Height" );
ChangeOutputName( 3, "Unused" );
ChangeOutputName( 4, "Projection Mode" );
m_value = "unity_OrthoParams";
m_previewShaderGUID = "88a910ece3dce224793e669bb1bc158d";
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
if( !m_outputPorts[ 3 ].IsConnected )
{
m_outputPorts[ 3 ].Visible = false;
m_sizeIsDirty = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f9431cdf8e81c1d4f902b3fa7d04f7ac
timeCreated: 1481126960
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Projection Params", "Camera And Screen", "Projection Near/Far parameters" )]
public sealed class ProjectionParams : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "Flipped" );
ChangeOutputName( 2, "Near Plane" );
ChangeOutputName( 3, "Far Plane" );
ChangeOutputName( 4, "1/Far Plane" );
m_value = "_ProjectionParams";
m_previewShaderGUID = "97ae846cb0a6b044388fad3bc03bb4c2";
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ba1ca8bace2c2dd4dafac6f73f4dfb1b
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Screen Params", "Camera And Screen", "Camera's Render Target size parameters" )]
public sealed class ScreenParams : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "RT Width" );
ChangeOutputName( 2, "RT Height" );
ChangeOutputName( 3, "1+1/Width" );
ChangeOutputName( 4, "1+1/Height" );
m_value = "_ScreenParams";
m_previewShaderGUID = "78173633b803de4419206191fed3d61e";
}
//public override void RefreshExternalReferences()
//{
// base.RefreshExternalReferences();
// if( !m_outputPorts[ 0 ].IsConnected )
// {
// m_outputPorts[ 0 ].Visible = false;
// m_sizeIsDirty = true;
// }
//}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2e593f23857d59643b5b5f6dd6264e1b
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "World Space Camera Pos", "Camera And Screen", "World Space Camera position" )]
public sealed class WorldSpaceCameraPos : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "XYZ", WirePortDataType.FLOAT3 );
AddOutputPort( WirePortDataType.FLOAT, "X" );
AddOutputPort( WirePortDataType.FLOAT, "Y" );
AddOutputPort( WirePortDataType.FLOAT, "Z" );
m_value = "_WorldSpaceCameraPos";
m_previewShaderGUID = "6b0c78411043dd24dac1152c84bb63ba";
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
return GetOutputVectorItem( 0, outputId, base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ) );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 972d92a6008896f4292a61726e18f667
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Z-Buffer Params", "Camera And Screen", "Linearized Z buffer values" )]
public sealed class ZBufferParams : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "1-far/near" );
ChangeOutputName( 2, "far/near" );
ChangeOutputName( 3, "[0]/far" );
ChangeOutputName( 4, "[1]/far" );
m_value = "_ZBufferParams";
m_previewShaderGUID = "56c42c106bcb497439187f5bb6b6f94d";
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2765a41106f478f4982e859b978bdec4
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using System;
namespace AmplifyShaderEditor
{
[Serializable]
public class ConstVecShaderVariable : ShaderVariablesNode
{
[SerializeField]
protected string m_value;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, " ", WirePortDataType.FLOAT4 );
AddOutputPort( WirePortDataType.FLOAT, "0" );
AddOutputPort( WirePortDataType.FLOAT, "1" );
AddOutputPort( WirePortDataType.FLOAT, "2" );
AddOutputPort( WirePortDataType.FLOAT, "3" );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
switch ( outputId )
{
case 0: return m_value;
case 1: return ( m_value + ".x" );
case 2: return ( m_value + ".y" );
case 3: return ( m_value + ".z" );
case 4: return ( m_value + ".w" );
}
UIUtils.ShowMessage( UniqueId, "ConstVecShaderVariable generating empty code", MessageSeverity.Warning );
return string.Empty;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9102c0b554fd5ad4785acf870dcc17eb
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
public class ConstantShaderVariable : ShaderVariablesNode
{
[SerializeField]
protected string m_value;
[SerializeField]
protected string m_HDValue = string.Empty;
[SerializeField]
protected string m_LWValue = string.Empty;
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
if( dataCollector.IsTemplate )
{
if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_HDValue ) )
return m_HDValue;
if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_LWValue ))
return m_LWValue;
}
return m_value;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 266391c3c4308014e9ce246e5484b917
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 78eb7b1e34d423c40a949c9e75b5f24a
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
public enum BuiltInFogAndAmbientColors
{
UNITY_LIGHTMODEL_AMBIENT = 0,
unity_AmbientSky,
unity_AmbientEquator,
unity_AmbientGround,
unity_FogColor
}
[Serializable]
[NodeAttributes( "Fog And Ambient Colors", "Light", "Fog and Ambient colors" )]
public sealed class FogAndAmbientColorsNode : ShaderVariablesNode
{
private const string ColorLabelStr = "Color";
private readonly string[] ColorValuesStr = {
"Ambient light ( Legacy )",
"Sky ambient light",
"Equator ambient light",
"Ground ambient light",
"Fog"
};
[SerializeField]
private BuiltInFogAndAmbientColors m_selectedType = BuiltInFogAndAmbientColors.UNITY_LIGHTMODEL_AMBIENT;
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, ColorValuesStr[ ( int ) m_selectedType ], WirePortDataType.COLOR );
m_textLabelWidth = 50;
m_autoWrapProperties = true;
m_hasLeftDropdown = true;
m_previewShaderGUID = "937c7bde062f0f942b600d9950d2ebb2";
}
public override void AfterCommonInit()
{
base.AfterCommonInit();
if( PaddingTitleLeft == 0 )
{
PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
if( PaddingTitleRight == 0 )
PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
}
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
m_previewMaterialPassId = (int)m_selectedType;
}
public override void Destroy()
{
base.Destroy();
m_upperLeftWidget = null;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
EditorGUI.BeginChangeCheck();
m_selectedType = (BuiltInFogAndAmbientColors)m_upperLeftWidget.DrawWidget( this, (int)m_selectedType, ColorValuesStr );
if( EditorGUI.EndChangeCheck() )
{
ChangeOutputName( 0, ColorValuesStr[ (int)m_selectedType ] );
}
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_selectedType = ( BuiltInFogAndAmbientColors ) EditorGUILayoutPopup( ColorLabelStr, ( int ) m_selectedType, ColorValuesStr );
if ( EditorGUI.EndChangeCheck() )
{
ChangeOutputName( 0, ColorValuesStr[ ( int ) m_selectedType ] );
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
if( dataCollector.IsTemplate && dataCollector.CurrentSRPType == TemplateSRPType.HD )
{
switch( m_selectedType )
{
case BuiltInFogAndAmbientColors.unity_AmbientSky:
return "_Ambient_ColorSky";
case BuiltInFogAndAmbientColors.unity_AmbientEquator:
return "_Ambient_Equator";
case BuiltInFogAndAmbientColors.unity_AmbientGround:
return "_Ambient_Ground";
case BuiltInFogAndAmbientColors.unity_FogColor:
return "_FogColor";
}
}
return m_selectedType.ToString();
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
m_selectedType = ( BuiltInFogAndAmbientColors ) Enum.Parse( typeof( BuiltInFogAndAmbientColors ), GetCurrentParam( ref nodeParams ) );
ChangeOutputName( 0, ColorValuesStr[ ( int ) m_selectedType ] );
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e2bdfc2fa6fcd0640b01a8b7448a1a11
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Fog Params", "Light", "Parameters for fog calculation" )]
public sealed class FogParamsNode : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "Density/Sqrt(Ln(2))" );
ChangeOutputName( 2, "Density/Ln(2)" );
ChangeOutputName( 3, "-1/(End-Start)" );
ChangeOutputName( 4, "End/(End-Start))" );
m_value = "unity_FogParams";
m_previewShaderGUID = "42abde3281b1848438c3b53443c91a1e";
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a3d8c31159e07bc419a7484ab5e894ed
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 47f503bcb5935b649beee3296dd40260
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,197 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
using UnityEditor;
using System;
namespace AmplifyShaderEditor
{
public enum ASEStandardSurfaceWorkflow
{
Metallic = 0,
Specular
}
[Serializable]
[NodeAttributes( "Standard Surface Light", "Light", "Provides a way to create a standard surface light model in custom lighting mode", NodeAvailabilityFlags = (int)NodeAvailability.CustomLighting )]
public sealed class CustomStandardSurface : ParentNode
{
private const string WorkflowStr = "Workflow";
[SerializeField]
private ASEStandardSurfaceWorkflow m_workflow = ASEStandardSurfaceWorkflow.Metallic;
[SerializeField]
private ViewSpace m_normalSpace = ViewSpace.Tangent;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT3, false, "Albedo" );
AddInputPort( WirePortDataType.FLOAT3, false, "Normal" );
m_inputPorts[ 1 ].Vector3InternalData = Vector3.forward;
AddInputPort( WirePortDataType.FLOAT3, false, "Emission" );
AddInputPort( WirePortDataType.FLOAT, false, "Metallic" );
AddInputPort( WirePortDataType.FLOAT, false, "Smoothness" );
AddInputPort( WirePortDataType.FLOAT, false, "Occlusion" );
m_inputPorts[ 5 ].FloatInternalData = 1;
AddOutputPort( WirePortDataType.FLOAT3, "RGB" );
m_autoWrapProperties = true;
m_textLabelWidth = 100;
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = "This node only returns correct information using a custom light model, otherwise returns 0";
}
public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
{
base.PropagateNodeData( nodeData, ref dataCollector );
if( m_inputPorts[ 1 ].IsConnected && m_normalSpace == ViewSpace.Tangent )
dataCollector.DirtyNormal = true;
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_workflow = (ASEStandardSurfaceWorkflow)EditorGUILayoutEnumPopup( WorkflowStr, m_workflow );
if( EditorGUI.EndChangeCheck() )
{
UpdateSpecularMetallicPorts();
}
EditorGUI.BeginChangeCheck();
m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace );
if( EditorGUI.EndChangeCheck() )
{
UpdatePort();
}
}
private void UpdatePort()
{
if( m_normalSpace == ViewSpace.World )
m_inputPorts[ 1 ].Name = "World Normal";
else
m_inputPorts[ 1 ].Name = "Normal";
m_sizeIsDirty = true;
}
void UpdateSpecularMetallicPorts()
{
if( m_workflow == ASEStandardSurfaceWorkflow.Specular )
m_inputPorts[ 3 ].ChangeProperties( "Specular", WirePortDataType.FLOAT3, false );
else
m_inputPorts[ 3 ].ChangeProperties( "Metallic", WirePortDataType.FLOAT, false );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
return "float3(0,0,0)";
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
string specularMode = string.Empty;
if( m_workflow == ASEStandardSurfaceWorkflow.Specular )
specularMode = "Specular";
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
if( dataCollector.DirtyNormal )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
dataCollector.ForceNormal = true;
}
dataCollector.AddLocalVariable( UniqueId, "SurfaceOutputStandard" + specularMode + " s" + OutputId + " = (SurfaceOutputStandard" + specularMode + " ) 0;" );
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Albedo = " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + ";" );
string normal = string.Empty;
if( m_inputPorts[ 1 ].IsConnected )
{
normal = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
if( m_normalSpace == ViewSpace.Tangent )
{
normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )";
}
}
else
{
normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId );
}
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Normal = "+ normal + ";" );
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Emission = " + m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ) + ";" );
if( m_workflow == ASEStandardSurfaceWorkflow.Specular )
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Specular = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ";" );
else
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Metallic = " + m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector ) + ";" );
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Smoothness = " + m_inputPorts[ 4 ].GeneratePortInstructions( ref dataCollector ) + ";" );
dataCollector.AddLocalVariable( UniqueId, "s" + OutputId + ".Occlusion = " + m_inputPorts[ 5 ].GeneratePortInstructions( ref dataCollector ) + ";\n" );
dataCollector.AddLocalVariable( UniqueId, "data.light = gi.light;\n", true );
dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi;" );
dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDBASE", true );
dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( s" + OutputId + ".Smoothness, data.worldViewDir, s" + OutputId + ".Normal, float3(0,0,0));" );
dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGlobalIllumination( data, s" + OutputId + ".Occlusion, s" + OutputId + ".Normal, g" + OutputId + " );" );
dataCollector.AddLocalVariable( UniqueId, "#endif\n", true );
dataCollector.AddLocalVariable( UniqueId, "float3 surfResult" + OutputId + " = LightingStandard" + specularMode + " ( s" + OutputId + ", viewDir, gi" + OutputId + " ).rgb;" );
//Emission must be always added to trick Unity, so it knows what needs to be created p.e. world pos
dataCollector.AddLocalVariable( UniqueId, "surfResult" + OutputId + " += s" + OutputId + ".Emission;\n" );
m_outputPorts[ 0 ].SetLocalValue( "surfResult" + OutputId, dataCollector.PortCategory );
//Remove emission contribution from Forward Add
dataCollector.AddLocalVariable( UniqueId, "#ifdef UNITY_PASS_FORWARDADD//" + OutputId );
dataCollector.AddLocalVariable( UniqueId, string.Format( "surfResult{0} -= s{0}.Emission;", OutputId ));
dataCollector.AddLocalVariable( UniqueId, "#endif//" + OutputId );
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader || ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) )
m_showErrorMessage = true;
else
m_showErrorMessage = false;
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
if( UIUtils.CurrentShaderVersion() < 13204 )
{
m_workflow = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ) ? ASEStandardSurfaceWorkflow.Specular : ASEStandardSurfaceWorkflow.Metallic;
}
else
{
m_workflow = (ASEStandardSurfaceWorkflow)Enum.Parse( typeof( ASEStandardSurfaceWorkflow ), GetCurrentParam( ref nodeParams ) );
}
UpdateSpecularMetallicPorts();
if( UIUtils.CurrentShaderVersion() >= 14402 )
{
m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) );
}
UpdatePort();
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_workflow );
IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 78916999fd7bc3c4e9767bc9cf0698c0
timeCreated: 1500054866
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,367 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Indirect Diffuse Light", "Light", "Indirect Lighting", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )]
public sealed class IndirectDiffuseLighting : ParentNode
{
[SerializeField]
private ViewSpace m_normalSpace = ViewSpace.Tangent;
private int m_cachedIntensityId = -1;
private const string FwdBasePragma = "#pragma multi_compile_fwdbase";
private readonly string LWIndirectDiffuseHeader = "ASEIndirectDiffuse( {0}, {1})";
private readonly string[] LWIndirectDiffuseBody =
{
"float3 ASEIndirectDiffuse( float2 uvStaticLightmap, float3 normalWS )\n",
"{\n",
"#ifdef LIGHTMAP_ON\n",
"\treturn SampleLightmap( uvStaticLightmap, normalWS );\n",
"#else\n",
"\treturn SampleSH(normalWS);\n",
"#endif\n",
"}\n"
};
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT3, false, "Normal" );
AddOutputPort( WirePortDataType.FLOAT3, "RGB" );
m_inputPorts[ 0 ].Vector3InternalData = Vector3.forward;
m_autoWrapProperties = true;
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = "This node only returns correct information using a custom light model, otherwise returns 0";
m_previewShaderGUID = "b45d57fa606c1ea438fe9a2c08426bc7";
m_drawPreviewAsSphere = true;
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
m_previewMaterialPassId = 1;
else
m_previewMaterialPassId = 2;
}
else
{
m_previewMaterialPassId = 0;
}
if( m_cachedIntensityId == -1 )
m_cachedIntensityId = Shader.PropertyToID( "_Intensity" );
PreviewMaterial.SetFloat( m_cachedIntensityId, RenderSettings.ambientIntensity );
}
public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
{
base.PropagateNodeData( nodeData, ref dataCollector );
// This needs to be rechecked
//if( m_inputPorts[ 0 ].IsConnected )
dataCollector.DirtyNormal = true;
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace );
if( EditorGUI.EndChangeCheck() )
{
UpdatePort();
}
}
private void UpdatePort()
{
if( m_normalSpace == ViewSpace.World )
m_inputPorts[ 0 ].ChangeProperties( "World Normal", m_inputPorts[ 0 ].DataType, false );
else
m_inputPorts[ 0 ].ChangeProperties( "Normal", m_inputPorts[ 0 ].DataType, false );
m_sizeIsDirty = true;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) )
m_showErrorMessage = true;
else
m_showErrorMessage = false;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
string finalValue = string.Empty;
if( dataCollector.IsTemplate && dataCollector.IsFragmentCategory )
{
if( !dataCollector.IsSRP )
{
dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib );
dataCollector.AddToDirectives( FwdBasePragma );
string texcoord1 = string.Empty;
string texcoord2 = string.Empty;
if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName;
else
texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false );
if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) )
texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName;
else
texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false );
string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName;
string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName;
TemplateVertexData data = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lmap" );
string varName = "ase_lmap";
if( data != null )
varName = data.VarName;
dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef DYNAMICLIGHTMAP_ON //dynlm" );
dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //dynlm" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef LIGHTMAP_ON //stalm" );
dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + "." + varName + ".xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw;" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //stalm" );
TemplateVertexData shdata = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT3, false, "ase_sh" );
string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Vertex );
string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex );
//Debug.Log( shdata );
string shVarName = "ase_sh";
if( shdata != null )
shVarName = shdata.VarName;
string outSH = vOutName + "." + shVarName + ".xyz";
dataCollector.AddToVertexLocalVariables( UniqueId, "#ifndef LIGHTMAP_ON //nstalm" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //sh" );
dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = 0;" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#ifdef VERTEXLIGHT_ON //vl" );
dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " += Shade4PointLights (" );
dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0," );
dataCollector.AddToVertexLocalVariables( UniqueId, "unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb," );
dataCollector.AddToVertexLocalVariables( UniqueId, "unity_4LightAtten0, " + worldPos + ", " + worldNormal + ");" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //vl" );
dataCollector.AddToVertexLocalVariables( UniqueId, outSH + " = ShadeSHPerVertex (" + worldNormal + ", " + outSH + ");" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //sh" );
dataCollector.AddToVertexLocalVariables( UniqueId, "#endif //nstalm" );
//dataCollector.AddToPragmas( UniqueId, "multi_compile_fwdbase" );
string fragWorldNormal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId );
else
fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
}
else
{
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment );
}
dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data" + OutputId + ";" );
dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data" + OutputId + " );" );
dataCollector.AddLocalVariable( UniqueId, "#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) //dylm" + OutputId );
dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".lightmapUV = " + fInName + "." + varName + ";" );
dataCollector.AddLocalVariable( UniqueId, "#endif //dylm" + OutputId );
dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SHOULD_SAMPLE_SH //fsh" + OutputId );
dataCollector.AddLocalVariable( UniqueId, "data" + OutputId + ".ambient = " + fInName + "." + shVarName + ";" );
dataCollector.AddLocalVariable( UniqueId, "#endif //fsh" + OutputId );
dataCollector.AddToLocalVariables( UniqueId, "UnityGI gi" + OutputId + " = UnityGI_Base(data" + OutputId + ", 1, " + fragWorldNormal + ");" );
finalValue = "gi" + OutputId + ".indirect.diffuse";
m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory );
return finalValue;
}
else
{
if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
{
string texcoord1 = string.Empty;
if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName;
else
texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false );
string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName;
string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName;
if( !dataCollector.TemplateDataCollectorInstance.HasRawInterpolatorOfName( "lightmapUVOrVertexSH" ) )
{
string worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Vertex );
dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "lightmapUVOrVertexSH" );
dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_LIGHTMAP_UV( " + texcoord1 + ", unity_LightmapST, " + vOutName + ".lightmapUVOrVertexSH.xy );" );
dataCollector.AddToVertexLocalVariables( UniqueId, "OUTPUT_SH( " + worldNormal + ", " + vOutName + ".lightmapUVOrVertexSH.xyz );" );
dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" );
dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" );
}
string fragWorldNormal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId );
else
fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
}
else
{
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment );
}
//SAMPLE_GI
//This function may not do full pixel and does not behave correctly with given normal thus is commented out
//dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SAMPLE_GI( " + fInName + ".lightmapUVOrVertexSH.xy, " + fInName + ".lightmapUVOrVertexSH.xyz, " + fragWorldNormal + " );" );
dataCollector.AddFunction( LWIndirectDiffuseBody[ 0 ], LWIndirectDiffuseBody, false );
finalValue = "bakedGI" + OutputId;
string result = string.Format( LWIndirectDiffuseHeader, fInName + ".lightmapUVOrVertexSH.xy", fragWorldNormal );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, finalValue, result );
m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory );
return finalValue;
}
else if( dataCollector.CurrentSRPType == TemplateSRPType.HD )
{
string texcoord1 = string.Empty;
string texcoord2 = string.Empty;
if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ) )
texcoord1 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES1, false, MasterNodePortCategory.Vertex ).VarName;
else
texcoord1 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES1, TemplateSemantics.TEXCOORD1, "texcoord1", WirePortDataType.FLOAT4, PrecisionType.Float, false );
if( dataCollector.TemplateDataCollectorInstance.HasInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ) )
texcoord2 = dataCollector.TemplateDataCollectorInstance.GetInfo( TemplateInfoOnSematics.TEXTURE_COORDINATES2, false, MasterNodePortCategory.Vertex ).VarName;
else
texcoord2 = dataCollector.TemplateDataCollectorInstance.RegisterInfoOnSemantic( MasterNodePortCategory.Vertex, TemplateInfoOnSematics.TEXTURE_COORDINATES2, TemplateSemantics.TEXCOORD2, "texcoord2", WirePortDataType.FLOAT4, PrecisionType.Float, false );
dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false, "ase_lightmapUVs" );
string vOutName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName;
string fInName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName;
dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.xy = " + texcoord1 + ".xy * unity_LightmapST.xy + unity_LightmapST.zw;" );
dataCollector.AddToVertexLocalVariables( UniqueId, vOutName + ".ase_lightmapUVs.zw = " + texcoord2 + ".xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;" );
string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos( false, MasterNodePortCategory.Fragment );
dataCollector.AddToPragmas( UniqueId, "multi_compile _ LIGHTMAP_ON" );
dataCollector.AddToPragmas( UniqueId, "multi_compile _ DIRLIGHTMAP_COMBINED" );
dataCollector.AddToPragmas( UniqueId, "multi_compile _ DYNAMICLIGHTMAP_ON" );
string fragWorldNormal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId );
else
fragWorldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
}
else
{
fragWorldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment );
}
//SAMPLE_GI
dataCollector.AddLocalVariable( UniqueId, "float3 bakedGI" + OutputId + " = SampleBakedGI( " + worldPos + ", " + fragWorldNormal + ", " + fInName + ".ase_lightmapUVs.xy, " + fInName + ".ase_lightmapUVs.zw );" );
finalValue = "bakedGI" + OutputId;
m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory );
return finalValue;
}
}
}
if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
return "float3(0,0,0)";
string normal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
dataCollector.ForceNormal = true;
normal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
if( m_normalSpace == ViewSpace.Tangent )
normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )";
}
else
{
if( dataCollector.IsFragmentCategory )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
if( dataCollector.DirtyNormal )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
dataCollector.ForceNormal = true;
}
}
normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId );
}
if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
{
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "ShadeSH9( float4( " + normal + ", 1 ) )" );
}
else
{
dataCollector.AddLocalVariable( UniqueId, "UnityGI gi" + OutputId + " = gi;" );
dataCollector.AddLocalVariable( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT3, "diffNorm" + OutputId, normal );
dataCollector.AddLocalVariable( UniqueId, "gi" + OutputId + " = UnityGI_Base( data, 1, diffNorm" + OutputId + " );" );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectDiffuse" + OutputId, "gi" + OutputId + ".indirect.diffuse + diffNorm" + OutputId + " * 0.0001" );
}
finalValue = "indirectDiffuse" + OutputId;
m_outputPorts[ 0 ].SetLocalValue( finalValue, dataCollector.PortCategory );
return finalValue;
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
if( UIUtils.CurrentShaderVersion() > 13002 )
m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) );
UpdatePort();
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 11bf17b0757d57c47add2eb50c62c75e
timeCreated: 1495726164
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,268 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEngine;
using UnityEditor;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Indirect Specular Light", "Light", "Indirect Specular Light", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )]
public sealed class IndirectSpecularLight : ParentNode
{
[SerializeField]
private ViewSpace m_normalSpace = ViewSpace.Tangent;
private const string DefaultErrorMessage = "This node only returns correct information using a custom light model, otherwise returns 0";
private bool m_upgradeMessage = false;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT3, false, "Normal" );
AddInputPort( WirePortDataType.FLOAT, false, "Smoothness" );
AddInputPort( WirePortDataType.FLOAT, false, "Occlusion" );
m_inputPorts[ 0 ].Vector3InternalData = Vector3.forward;
m_inputPorts[ 1 ].FloatInternalData = 0.5f;
m_inputPorts[ 2 ].FloatInternalData = 1;
m_inputPorts[ 1 ].AutoDrawInternalData = true;
m_inputPorts[ 2 ].AutoDrawInternalData = true;
m_autoWrapProperties = true;
AddOutputPort( WirePortDataType.FLOAT3, "RGB" );
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = DefaultErrorMessage;
m_previewShaderGUID = "d6e441d0a8608954c97fa347d3735e92";
m_drawPreviewAsSphere = true;
}
public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
{
base.PropagateNodeData( nodeData, ref dataCollector );
if( m_inputPorts[ 0 ].IsConnected )
dataCollector.DirtyNormal = true;
}
public override void SetPreviewInputs()
{
base.SetPreviewInputs();
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
m_previewMaterialPassId = 1;
else
m_previewMaterialPassId = 2;
}
else
{
m_previewMaterialPassId = 0;
}
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUI.BeginChangeCheck();
m_normalSpace = (ViewSpace)EditorGUILayoutEnumPopup( "Normal Space", m_normalSpace );
if( EditorGUI.EndChangeCheck() )
{
UpdatePort();
}
if( !m_inputPorts[ 1 ].IsConnected )
m_inputPorts[ 1 ].FloatInternalData = EditorGUILayout.FloatField( m_inputPorts[ 1 ].Name, m_inputPorts[ 1 ].FloatInternalData );
if( !m_inputPorts[ 2 ].IsConnected )
m_inputPorts[ 2 ].FloatInternalData = EditorGUILayout.FloatField( m_inputPorts[ 2 ].Name, m_inputPorts[ 2 ].FloatInternalData );
}
private void UpdatePort()
{
if( m_normalSpace == ViewSpace.World )
m_inputPorts[ 0 ].ChangeProperties( "World Normal", m_inputPorts[ 0 ].DataType, false );
else
m_inputPorts[ 0 ].ChangeProperties( "Normal", m_inputPorts[ 0 ].DataType, false );
m_sizeIsDirty = true;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( m_upgradeMessage || ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) )
m_showErrorMessage = true;
else
m_showErrorMessage = false;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.IsTemplate )
{
if( !dataCollector.IsSRP )
{
dataCollector.AddToIncludes( UniqueId, Constants.UnityLightingLib );
string worldPos = dataCollector.TemplateDataCollectorInstance.GetWorldPos();
string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment );
string worldNormal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId );
else
worldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
}
else
{
worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment );
}
string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data;" );
dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data );" );
dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ";" );
dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + worldViewDir + ";" );
dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR;" );
dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR;" );
dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[0] = unity_SpecCube0_BoxMin;" );
dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" );
dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[0] = unity_SpecCube0_BoxMax;" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[0] = unity_SpecCube0_ProbePosition;" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMax[1] = unity_SpecCube1_BoxMax;" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.boxMin[1] = unity_SpecCube1_BoxMin;" );
dataCollector.AddLocalVariable( UniqueId, "\tdata.probePosition[1] = unity_SpecCube1_ProbePosition;" );
dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" );
dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + tempsmoothness + ", " + worldViewDir + ", " + worldNormal + ", float3(0,0,0));" );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + tempocclusion + ", " + worldNormal + ", g" + OutputId + " )" );
return "indirectSpecular" + OutputId;
}
else
{
if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
{
string worldViewDir = dataCollector.TemplateDataCollectorInstance.GetViewDir( false, MasterNodePortCategory.Fragment );
string worldNormal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
if( m_normalSpace == ViewSpace.Tangent )
worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ), OutputId );
else
worldNormal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
}
else
{
worldNormal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( PrecisionType.Float, false, MasterNodePortCategory.Fragment );
}
string tempsmoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
string tempocclusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
dataCollector.AddLocalVariable( UniqueId, "half3 reflectVector" + OutputId + " = reflect( -" + worldViewDir + ", " + worldNormal + " );" );
dataCollector.AddLocalVariable( UniqueId, "float3 indirectSpecular" + OutputId + " = GlossyEnvironmentReflection( reflectVector" + OutputId + ", 1.0 - " + tempsmoothness + ", " + tempocclusion + " );" );
return "indirectSpecular" + OutputId;
}
else if( dataCollector.CurrentSRPType == TemplateSRPType.HD )
{
UIUtils.ShowMessage( UniqueId, "Indirect Specular Light node currently not supported on HDRP" );
return m_outputPorts[0].ErrorValue;
}
}
}
if( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
return m_outputPorts[0].ErrorValue;
string normal = string.Empty;
if( m_inputPorts[ 0 ].IsConnected )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
dataCollector.ForceNormal = true;
normal = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
if( m_normalSpace == ViewSpace.Tangent )
normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )";
dataCollector.AddLocalVariable( UniqueId, "float3 indirectNormal" + OutputId + " = " + normal + ";" );
normal = "indirectNormal" + OutputId;
}
else
{
if( dataCollector.IsFragmentCategory )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
if( dataCollector.DirtyNormal )
{
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
dataCollector.ForceNormal = true;
}
}
normal = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId );
}
string smoothness = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
string occlusion = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
string viewDir = "data.worldViewDir";
if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
{
string worldPos = GeneratorUtils.GenerateWorldPosition( ref dataCollector, UniqueId );
viewDir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId );
dataCollector.AddLocalVariable( UniqueId, "UnityGIInput data;" );
dataCollector.AddLocalVariable( UniqueId, "UNITY_INITIALIZE_OUTPUT( UnityGIInput, data );" );
dataCollector.AddLocalVariable( UniqueId, "data.worldPos = " + worldPos + ";" );
dataCollector.AddLocalVariable( UniqueId, "data.worldViewDir = " + viewDir + ";" );
dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[0] = unity_SpecCube0_HDR;" );
dataCollector.AddLocalVariable( UniqueId, "data.probeHDR[1] = unity_SpecCube1_HDR;" );
dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION //specdataif0" );
dataCollector.AddLocalVariable( UniqueId, "data.boxMin[0] = unity_SpecCube0_BoxMin;" );
dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif0" );
dataCollector.AddLocalVariable( UniqueId, "#if UNITY_SPECCUBE_BOX_PROJECTION //specdataif1" );
dataCollector.AddLocalVariable( UniqueId, "data.boxMax[0] = unity_SpecCube0_BoxMax;" );
dataCollector.AddLocalVariable( UniqueId, "data.probePosition[0] = unity_SpecCube0_ProbePosition;" );
dataCollector.AddLocalVariable( UniqueId, "data.boxMax[1] = unity_SpecCube1_BoxMax;" );
dataCollector.AddLocalVariable( UniqueId, "data.boxMin[1] = unity_SpecCube1_BoxMin;" );
dataCollector.AddLocalVariable( UniqueId, "data.probePosition[1] = unity_SpecCube1_ProbePosition;" );
dataCollector.AddLocalVariable( UniqueId, "#endif //specdataif1" );
}
dataCollector.AddLocalVariable( UniqueId, "Unity_GlossyEnvironmentData g" + OutputId + " = UnityGlossyEnvironmentSetup( " + smoothness + ", " + viewDir + ", " + normal + ", float3(0,0,0));" );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, "indirectSpecular" + OutputId, "UnityGI_IndirectSpecular( data, " + occlusion + ", " + normal + ", g" + OutputId + " )" );
return "indirectSpecular" + OutputId;
}
public override void ReadFromString( ref string[] nodeParams )
{
base.ReadFromString( ref nodeParams );
if( UIUtils.CurrentShaderVersion() > 13002 )
m_normalSpace = (ViewSpace)Enum.Parse( typeof( ViewSpace ), GetCurrentParam( ref nodeParams ) );
if( UIUtils.CurrentShaderVersion() < 13804 )
{
m_errorMessageTooltip = "Smoothness port was previously being used as Roughness, please check if you are correctly using it and save to confirm.";
m_upgradeMessage = true;
UIUtils.ShowMessage( UniqueId, "Indirect Specular Light node: Smoothness port was previously being used as Roughness, please check if you are correctly using it and save to confirm." );
}
UpdatePort();
}
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo, ref connectionsInfo );
IOUtils.AddFieldValueToString( ref nodeInfo, m_normalSpace );
m_errorMessageTooltip = DefaultErrorMessage;
m_upgradeMessage = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0820850e74009954188ff84e2f5cc4f2
timeCreated: 1495817589
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,134 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Light Attenuation", "Light", "Contains light attenuation for all types of light", NodeAvailabilityFlags = (int)( NodeAvailability.CustomLighting | NodeAvailability.TemplateShader ) )]
public sealed class LightAttenuation : ParentNode
{
static readonly string SurfaceError = "This node only returns correct information using a custom light model, otherwise returns 1";
static readonly string TemplateError = "This node will only produce proper attenuation if the template contains a shadow caster pass";
private const string ASEAttenVarName = "ase_lightAtten";
private readonly string[] LightweightPragmaMultiCompiles =
{
"multi_compile _ _MAIN_LIGHT_SHADOWS",
"multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE",
"multi_compile _ _SHADOWS_SOFT"
};
//private readonly string[] LightweightVertexInstructions =
//{
// /*local vertex position*/"VertexPositionInputs ase_vertexInput = GetVertexPositionInputs ({0});",
// "#ifdef _MAIN_LIGHT_SHADOWS//ase_lightAtten_vert",
// /*available interpolator*/"{0} = GetShadowCoord( ase_vertexInput );",
// "#endif//ase_lightAtten_vert"
//};
private const string LightweightLightAttenDecl = "float ase_lightAtten = 0;";
private readonly string[] LightweightFragmentInstructions =
{
/*shadow coords*/"Light ase_lightAtten_mainLight = GetMainLight( {0} );",
"ase_lightAtten = ase_lightAtten_mainLight.distanceAttenuation * ase_lightAtten_mainLight.shadowAttenuation;"
};
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddOutputPort( WirePortDataType.FLOAT, "Out" );
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = SurfaceError;
m_previewShaderGUID = "4b12227498a5c8d46b6c44ea018e5b56";
m_drawPreviewAsSphere = true;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.IsTemplate )
{
if( !dataCollector.IsSRP )
{
string result = string.Empty;
if( dataCollector.TemplateDataCollectorInstance.ContainsSpecialLocalFragVar( TemplateInfoOnSematics.SHADOWCOORDS, WirePortDataType.FLOAT4, ref result ) )
{
return result;
}
return dataCollector.TemplateDataCollectorInstance.GetLightAtten( UniqueId );
}
else
{
if( dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
{
if( dataCollector.HasLocalVariable( LightweightLightAttenDecl ))
return ASEAttenVarName;
// Pragmas
for( int i = 0; i < LightweightPragmaMultiCompiles.Length; i++ )
dataCollector.AddToPragmas( UniqueId, LightweightPragmaMultiCompiles[ i ] );
string shadowCoords = dataCollector.TemplateDataCollectorInstance.GetShadowCoords( UniqueId/*, false, dataCollector.PortCategory*/ );
//return shadowCoords;
// Vertex Instructions
//TemplateVertexData shadowCoordsData = dataCollector.TemplateDataCollectorInstance.RequestNewInterpolator( WirePortDataType.FLOAT4, false );
//string vertexInterpName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.VertexFunctionData.OutVarName;
//string vertexShadowCoords = vertexInterpName + "." + shadowCoordsData.VarNameWithSwizzle;
//string vertexPos = dataCollector.TemplateDataCollectorInstance.GetVertexPosition( WirePortDataType.FLOAT3, PrecisionType.Float ,false,MasterNodePortCategory.Vertex );
//dataCollector.AddToVertexLocalVariables( UniqueId, string.Format( LightweightVertexInstructions[ 0 ], vertexPos ));
//dataCollector.AddToVertexLocalVariables( UniqueId, LightweightVertexInstructions[ 1 ]);
//dataCollector.AddToVertexLocalVariables( UniqueId, string.Format( LightweightVertexInstructions[ 2 ], vertexShadowCoords ) );
//dataCollector.AddToVertexLocalVariables( UniqueId, LightweightVertexInstructions[ 3 ]);
// Fragment Instructions
//string fragmentInterpName = dataCollector.TemplateDataCollectorInstance.CurrentTemplateData.FragmentFunctionData.InVarName;
//string fragmentShadowCoords = fragmentInterpName + "." + shadowCoordsData.VarNameWithSwizzle;
dataCollector.AddLocalVariable( UniqueId, LightweightLightAttenDecl );
dataCollector.AddLocalVariable( UniqueId, string.Format( LightweightFragmentInstructions[ 0 ], shadowCoords ) );
dataCollector.AddLocalVariable( UniqueId, LightweightFragmentInstructions[ 1 ] );
return ASEAttenVarName;
}
else
{
UIUtils.ShowMessage( UniqueId, "Light Attenuation node currently not supported on HDRP" );
return "1";
}
}
}
if ( dataCollector.GenType == PortGenType.NonCustomLighting || dataCollector.CurrentCanvasMode != NodeAvailability.CustomLighting )
{
UIUtils.ShowMessage( UniqueId, "Light Attenuation node currently not supported on non-custom lighting surface shaders" );
return "1";
}
dataCollector.UsingLightAttenuation = true;
return ASEAttenVarName;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader && ContainerGraph.CurrentSRPType != TemplateSRPType.Lightweight )
{
m_showErrorMessage = true;
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = TemplateError;
} else
{
m_errorMessageTypeIsError = NodeMessageType.Error;
m_errorMessageTooltip = SurfaceError;
if ( ( ContainerGraph.CurrentStandardSurface != null && ContainerGraph.CurrentStandardSurface.CurrentLightingModel != StandardShaderLightModel.CustomLighting ) )
m_showErrorMessage = true;
else
m_showErrorMessage = false;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4e205b44d56609f459ffc558febe2792
timeCreated: 1495449979
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEngine;
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Light Color", "Light", "Light Color, RGB value already contains light intensity while A only contains light intensity" )]
public sealed class LightColorNode : ShaderVariablesNode
{
private const string m_lightColorValue = "_LightColor0";
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "RGBA", WirePortDataType.COLOR );
AddOutputPort( WirePortDataType.FLOAT3, "Color" );
AddOutputPort( WirePortDataType.FLOAT, "Intensity" );
m_previewShaderGUID = "43f5d3c033eb5044e9aeb40241358349";
}
public override void RenderNodePreview()
{
//Runs at least one time
if( !m_initialized )
{
// nodes with no preview don't update at all
PreviewIsDirty = false;
return;
}
if( !PreviewIsDirty )
return;
int count = m_outputPorts.Count;
for( int i = 0; i < count; i++ )
{
RenderTexture temp = RenderTexture.active;
RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture;
Graphics.Blit( null, m_outputPorts[ i ].OutputPreviewTexture, PreviewMaterial, i );
RenderTexture.active = temp;
}
PreviewIsDirty = m_continuousPreviewRefresh;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.IsTemplate && !dataCollector.IsSRP )
dataCollector.AddToIncludes( -1, Constants.UnityLightingLib );
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
string finalVar = m_lightColorValue;
if( dataCollector.IsTemplate && dataCollector.IsSRP )
{
if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD )
{
dataCollector.TemplateDataCollectorInstance.AddHDLightInfo();
finalVar = string.Format( TemplateHelperFunctions.HDLightInfoFormat, "0", "color" ); ;
}
else
{
finalVar = "_MainLightColor";
}
}
else
{
dataCollector.AddLocalVariable( UniqueId, "#if defined(LIGHTMAP_ON) && ( UNITY_VERSION < 560 || ( defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) ) )//aselc" );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, "ase_lightColor", "0" );
dataCollector.AddLocalVariable( UniqueId, "#else //aselc" );
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, "ase_lightColor", finalVar );
dataCollector.AddLocalVariable( UniqueId, "#endif //aselc" );
finalVar = "ase_lightColor";
}
//else if( ContainerGraph.CurrentStandardSurface.CurrentLightingModel == StandardShaderLightModel.CustomLighting )
// finalVar = "gi.light.color";
switch( outputId )
{
default:
case 0: return finalVar;
case 1: return finalVar + ".rgb";
case 2: return finalVar + ".a";
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 275270020c577924caf04492f73b2ea6
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,92 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "World Space Light Pos", "Light", "Light Position" )]
public sealed class WorldSpaceLightPos : ShaderVariablesNode
{
private const string HelperText =
"This node will behave differently according to light type." +
"\n\n- For directional lights the Dir/Pos output will specify a world space direction and Type will be set to 0." +
"\n\n- For other light types the Dir/Pos output will specify a world space position and Type will be set to 1.";
private const string m_lightPosValue = "_WorldSpaceLightPos0";
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, Constants.EmptyPortValue, WirePortDataType.FLOAT4 );
AddOutputPort( WirePortDataType.FLOAT3, "Dir/Pos" );
AddOutputPort( WirePortDataType.FLOAT, "Type" );
m_previewShaderGUID = "2292a614672283c41a367b22cdde4620";
m_drawPreviewAsSphere = true;
}
public override void DrawProperties()
{
base.DrawProperties();
EditorGUILayout.HelpBox( HelperText, MessageType.Info );
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalVar );
string finalVar = m_lightPosValue;
if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.IsSRP )
finalVar = "_MainLightPosition";
if( outputId == 1 )
{
return finalVar + ".xyz";
}
else if( outputId == 2 )
{
return finalVar + ".w";
}
else
{
return finalVar;
}
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
public override void RenderNodePreview()
{
//Runs at least one time
if( !m_initialized )
{
// nodes with no preview don't update at all
PreviewIsDirty = false;
return;
}
if( !PreviewIsDirty )
return;
SetPreviewInputs();
RenderTexture temp = RenderTexture.active;
RenderTexture.active = m_outputPorts[ 0 ].OutputPreviewTexture;
Graphics.Blit( null, m_outputPorts[ 0 ].OutputPreviewTexture, PreviewMaterial, 0 );
Graphics.Blit( m_outputPorts[ 0 ].OutputPreviewTexture, m_outputPorts[ 1 ].OutputPreviewTexture );
RenderTexture.active = m_outputPorts[ 2 ].OutputPreviewTexture;
Graphics.Blit( null, m_outputPorts[ 2 ].OutputPreviewTexture, PreviewMaterial, 1 );
RenderTexture.active = temp;
PreviewIsDirty = m_continuousPreviewRefresh;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: db94d973647dae9488d3ef5ee2fd95a4
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
public class ShaderVariablesNode : ParentNode
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddOutputPort( WirePortDataType.OBJECT, "Out" );
}
public override string GetIncludes()
{
return Constants.UnityShaderVariables;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( !( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.IsSRP ) )
dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables );
return string.Empty;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1eb723e6ceff9a345a9dbfe04aa3dc11
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7c77e88b33fec7c429412624a7b2c620
folderAsset: yes
timeCreated: 1481126947
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Cos Time", "Time", "Cosine of time" )]
public sealed class CosTime : ConstVecShaderVariable
{
#if UNITY_2018_3_OR_NEWER
private readonly string[] SRPTime =
{
"cos( _TimeParameters.x * 0.125 )",
"cos( _TimeParameters.x * 0.25 )",
"cos( _TimeParameters.x * 0.5 )",
"_TimeParameters.z",
};
#endif
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "t/8" );
ChangeOutputName( 2, "t/4" );
ChangeOutputName( 3, "t/2" );
ChangeOutputName( 4, "t" );
m_value = "_CosTime";
m_previewShaderGUID = "3093999b42c3c0940a71799511d7781c";
m_continuousPreviewRefresh = true;
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
#if UNITY_2018_3_OR_NEWER
if( outputId > 0 && dataCollector.IsTemplate )
{
if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ||
( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) )
return SRPTime[ outputId - 1 ];
}
#endif
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 447e504f2ca5aaf4bbf0fdbce33596bc
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Delta Time", "Time", "Delta time" )]
public sealed class DeltaTime : ConstVecShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "dt" );
ChangeOutputName( 2, "1/dt" );
ChangeOutputName( 3, "smoothDt" );
ChangeOutputName( 4, "1/smoothDt" );
m_value = "unity_DeltaTime";
m_previewShaderGUID = "9d69a693042c443498f96d6da60535eb";
m_continuousPreviewRefresh = true;
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3ddde7ed1ab4f8044a9a6aa3891f5ca4
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Time", "Time", "Time in seconds with a scale multiplier" )]
public sealed class SimpleTimeNode : ShaderVariablesNode
{
private const string TimeStandard = "_Time.y";
#if UNITY_2018_3_OR_NEWER
private const string TimeSRP = "_TimeParameters.x";
#endif
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT );
AddInputPort( WirePortDataType.FLOAT, false, "Scale" );
m_inputPorts[ 0 ].FloatInternalData = 1;
m_useInternalPortData = true;
m_previewShaderGUID = "45b7107d5d11f124fad92bcb1fa53661";
m_continuousPreviewRefresh = true;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
string multiplier = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
string timeGlobalVar = TimeStandard;
#if UNITY_2018_3_OR_NEWER
if( dataCollector.IsTemplate )
{
if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ||
( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) )
timeGlobalVar = TimeSRP;
}
#endif
if( multiplier == "1.0" )
return timeGlobalVar;
string scaledVarName = "mulTime" + OutputId;
string scaledVarValue = timeGlobalVar + " * " + multiplier;
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, scaledVarName, scaledVarValue );
return scaledVarName;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f36e4491ee33fe74fa51cfb5ad450c6e
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using UnityEditor;
using UnityEngine;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Sin Time", "Time", "Unity sin time" )]
public sealed class SinTimeNode : ConstVecShaderVariable
{
//double m_time;
#if UNITY_2018_3_OR_NEWER
private readonly string[] SRPTime =
{
"sin( _TimeParameters.x * 0.125 )",
"sin( _TimeParameters.x * 0.25 )",
"sin( _TimeParameters.x * 0.5 )",
"_TimeParameters.y",
};
#endif
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "t/8" );
ChangeOutputName( 2, "t/4" );
ChangeOutputName( 3, "t/2" );
ChangeOutputName( 4, "t" );
m_value = "_SinTime";
m_previewShaderGUID = "e4ba809e0badeb94994170b2cbbbba10";
m_continuousPreviewRefresh = true;
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
#if UNITY_2018_3_OR_NEWER
if( outputId > 0 && dataCollector.IsTemplate )
{
if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ||
( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ) )
return SRPTime[ outputId - 1 ];
}
#endif
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 796acd44fcf330e4e921855630007b9b
timeCreated: 1481126957
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
namespace AmplifyShaderEditor
{
[Serializable]
[NodeAttributes( "Time Parameters", "Time", "Time since level load" )]
public sealed class TimeNode : ConstVecShaderVariable
{
#if UNITY_2018_3_OR_NEWER
private readonly string[] SRPTime =
{
"( _TimeParameters.x * 0.05 )",
"( _TimeParameters.x )",
"( _TimeParameters.x * 2 )",
"( _TimeParameters.x * 3 )",
};
#endif
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputName( 1, "t/20" );
ChangeOutputName( 2, "t" );
ChangeOutputName( 3, "t*2" );
ChangeOutputName( 4, "t*3" );
m_value = "_Time";
m_previewShaderGUID = "73abc10c8d1399444827a7eeb9c24c2a";
m_continuousPreviewRefresh = true;
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
if( !m_outputPorts[ 0 ].IsConnected )
{
m_outputPorts[ 0 ].Visible = false;
m_sizeIsDirty = true;
}
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
#if UNITY_2018_3_OR_NEWER
if( outputId > 0 && dataCollector.IsTemplate )
{
if( ( dataCollector.TemplateDataCollectorInstance.IsHDRP && ASEPackageManagerHelper.CurrentHDVersion > ASESRPVersions.ASE_SRP_5_16_1 ) ||
( dataCollector.TemplateDataCollectorInstance.IsLWRP && ASEPackageManagerHelper.CurrentLWVersion > ASESRPVersions.ASE_SRP_5_16_1 ))
return SRPTime[ outputId - 1 ];
}
#endif
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d8c6b7bfb7784e14d8708ab6fb981268
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2ce97203c4871664493f8760d88d0d4d
folderAsset: yes
timeCreated: 1481126946
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Camera To World Matrix", "Matrix Transform", "Current camera to world matrix" )]
public sealed class CameraToWorldMatrix : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "unity_CameraToWorld";
m_drawPreview = false;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
GeneratorUtils.RegisterUnity2019MatrixDefines( ref dataCollector );
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6accfe0f350cf064dae07041fe90446b
timeCreated: 1481126959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Inverse Projection Matrix", "Matrix Transform", "Current inverse projection matrix", NodeAvailabilityFlags = (int)( NodeAvailability.TemplateShader ) )]
public sealed class InverseProjectionMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_I_P";
m_drawPreview = false;
m_matrixId = 1;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.IsTemplate && dataCollector.IsSRP )
{
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
else
{
return GeneratorUtils.GenerateIdentity4x4( ref dataCollector, UniqueId );
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ContainerGraph.IsSRP )
{
m_showErrorMessage = false;
}
else
{
m_showErrorMessage = true;
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = "This node only works for Scriptable Render Pipeline (LWRP, HDRP, URP)";
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0fdbc380972c44b489c5f948a40b8e69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Inverse Transpose Model View Matrix", "Matrix Transform", "All Transformation types" )]
public sealed class InverseTranspMVMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_IT_MV";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3a71f1e560487aa4c8484c4153941884
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Inverse View Matrix", "Matrix Transform", "Current inverse view matrix" )]
public sealed class InverseViewMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_I_V";
m_drawPreview = false;
m_matrixId = 0;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dd0c1c252c062184e9ad592b91e7fcd2
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Inverse View Projection Matrix", "Matrix Transform", "Current view inverse projection matrix", NodeAvailabilityFlags = (int)( NodeAvailability.TemplateShader ) )]
public sealed class InverseViewProjectionMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_I_VP";
m_drawPreview = false;
m_matrixId = 1;
}
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
{
if( dataCollector.IsTemplate && dataCollector.IsSRP )
{
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
}
else
{
return GeneratorUtils.GenerateIdentity4x4( ref dataCollector, UniqueId );
}
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ContainerGraph.IsSRP )
{
m_showErrorMessage = false;
}
else
{
m_showErrorMessage = true;
m_errorMessageTypeIsError = NodeMessageType.Warning;
m_errorMessageTooltip = "This node only works for Scriptable Render Pipeline (LWRP, HDRP, URP)";
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6f151774e252dd4fb2b9ee440ec8eed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Model Matrix", "Matrix Transform", "Current model matrix" )]
public sealed class MMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_M";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 503a386043991354eaca2410683d836a
timeCreated: 1481126955
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Model View Matrix", "Matrix Transform", "Current model * view matrix" )]
public sealed class MVMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_MV";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 30c7936db4e6fe5488076d799841f857
timeCreated: 1481126954
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Model View Projection Matrix", "Matrix Transform", "Current model * view * projection matrix" )]
public sealed class MVPMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_MVP";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 74e00fb3d8e161f498c078795184bae4
timeCreated: 1481126956
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Object To World Matrix", "Matrix Transform", "Current model matrix" )]
public sealed class ObjectToWorldMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "unity_ObjectToWorld";
m_HDValue = "GetObjectToWorldMatrix()";
m_LWValue = "GetObjectToWorldMatrix()";
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a0c0180a327eba54c832fbb695dd282f
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Projection Matrix", "Matrix Transform", "Current projection matrix" )]
public sealed class ProjectionMatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_P";
m_drawPreview = false;
m_matrixId = 1;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 008fd07cf3f9a7140a9e23be43733f7c
timeCreated: 1481126953
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Texture 0 Matrix", "Matrix Transform", "Texture 0 Matrix", null, UnityEngine.KeyCode.None, true, true )]
public sealed class Texture0MatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_TEXTURE0";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f57a1d05f7a9c5847912566ff1605c6d
timeCreated: 1481126960
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Texture 1 Matrix", "Matrix Transform", "Texture 1 Matrix", null, UnityEngine.KeyCode.None, true, true )]
public sealed class Texture1MatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_TEXTURE1";
m_drawPreview = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9ef360a7c6005ad479d7a3e6db1d32f4
timeCreated: 1481126958
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
namespace AmplifyShaderEditor
{
[System.Serializable]
[NodeAttributes( "Texture 2 Matrix", "Matrix Transform", "Texture 2 Matrix", null, UnityEngine.KeyCode.None, true, true )]
public sealed class Texture2MatrixNode : ConstantShaderVariable
{
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
ChangeOutputProperties( 0, "Out", WirePortDataType.FLOAT4x4 );
m_value = "UNITY_MATRIX_TEXTURE2";
m_drawPreview = false;
}
}
}

Some files were not shown because too many files have changed in this diff Show More