diff options
author | chai <chaifix@163.com> | 2020-10-22 23:30:02 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-22 23:30:02 +0800 |
commit | 917e9e0b320775634dc2e710f7deac74fd0822f0 (patch) | |
tree | 637f3cccc80e7738c8a077fa3ff59218b8b18ee8 /Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation | |
parent | 8268e4e308bd110dfea4ad849a7ff74e66951349 (diff) |
* amplify shader editor
Diffstat (limited to 'Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation')
6 files changed, 173 insertions, 0 deletions
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs new file mode 100644 index 00000000..48de5fbe --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs @@ -0,0 +1,30 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Object To World", "Object Transform", "Transforms input to World Space" )] + public sealed class ObjectToWorldTransfNode : ParentTransfNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_matrixName = "unity_ObjectToWorld"; + m_matrixHDName = "GetObjectToWorldMatrix()"; + m_matrixLWName = "GetObjectToWorldMatrix()"; + m_previewShaderGUID = "a4044ee165813654486d0cecd0de478c"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string result = base.GenerateShaderForOutput( 0, ref dataCollector, ignoreLocalvar ); + if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_matrixHDName ) ) + { + dataCollector.AddLocalVariable( UniqueId, string.Format( "{0}.xyz", result ), string.Format( "GetAbsolutePositionWS(({0}).xyz);", result ) ); + } + + return GetOutputVectorItem( 0, outputId, result ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs.meta new file mode 100644 index 00000000..40b45c87 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ObjectToWorldTransfNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 545417ad304cea84b9f625a3b6ad4e56 +timeCreated: 1488205951 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs new file mode 100644 index 00000000..5781e115 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs @@ -0,0 +1,53 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + public class ParentTransfNode : ParentNode + { + protected string m_matrixName; + protected string m_matrixHDName; + protected string m_matrixLWName; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT4, false, string.Empty ); + AddOutputVectorPorts( WirePortDataType.FLOAT4, "XYZW" ); + m_useInternalPortData = true; + m_inputPorts[ 0 ].Vector4InternalData = new UnityEngine.Vector4( 0, 0, 0, 1 ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string matrixName = string.Empty; + if( dataCollector.IsTemplate ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_matrixHDName ) ) + { + matrixName = m_matrixHDName; + } + else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_matrixLWName ) ) + { + matrixName = m_matrixLWName; + } + else + { + matrixName = m_matrixName; + } + } + else + { + matrixName = m_matrixName; + } + + RegisterLocalVariable( 0, string.Format( "mul({0},{1})", matrixName, value ),ref dataCollector,"transform"+ OutputId ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs.meta new file mode 100644 index 00000000..5a714ba2 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/ParentTransfNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 11f04432b7f1ffb43b584adb226614c6 +timeCreated: 1488206086 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs new file mode 100644 index 00000000..ccc57813 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs @@ -0,0 +1,54 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "World To Object", "Object Transform", "Transforms input to Object Space" )] + public sealed class WorldToObjectTransfNode : ParentTransfNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_matrixName = "unity_WorldToObject"; + m_matrixHDName = "GetWorldToObjectMatrix()"; + m_matrixLWName = "GetWorldToObjectMatrix()"; + m_previewShaderGUID = "79a5efd1e3309f54d8ba3e7fdf5e459b"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string matrixName = string.Empty; + if( dataCollector.IsTemplate ) + { + if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_matrixHDName ) ) + { + string varName = "localWorldVar" + OutputId; + dataCollector.AddLocalVariable( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT4, varName, value ); + dataCollector.AddLocalVariable( UniqueId, string.Format( "({0}).xyz", varName ), string.Format( "GetCameraRelativePositionWS(({0}).xyz);", varName ) ); + value = varName; + matrixName = m_matrixHDName; + } + else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_matrixLWName ) ) + { + matrixName = m_matrixLWName; + } + else + { + matrixName = m_matrixName; + } + } + else + { + matrixName = m_matrixName; + } + + RegisterLocalVariable( 0, string.Format( "mul({0},{1})", matrixName, value ), ref dataCollector, "transform" + OutputId ); + return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs.meta new file mode 100644 index 00000000..8ad85ca4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/Transformation/WorldToObjectTransfNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8a25ccf8973bfae46ae3df2823f58229 +timeCreated: 1488205986 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |