summaryrefslogtreecommitdiff
path: root/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-22 23:30:02 +0800
committerchai <chaifix@163.com>2020-10-22 23:30:02 +0800
commit917e9e0b320775634dc2e710f7deac74fd0822f0 (patch)
tree637f3cccc80e7738c8a077fa3ff59218b8b18ee8 /Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting
parent8268e4e308bd110dfea4ad849a7ff74e66951349 (diff)
* amplify shader editor
Diffstat (limited to 'Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting')
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs197
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta12
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs366
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta12
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs268
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta12
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs128
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta12
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs88
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta12
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs92
-rw-r--r--Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta12
12 files changed, 1211 insertions, 0 deletions
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs
new file mode 100644
index 00000000..d985714c
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs
@@ -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 );
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta
new file mode 100644
index 00000000..172f37cd
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/CustomStandardSurface.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 78916999fd7bc3c4e9767bc9cf0698c0
+timeCreated: 1500054866
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs
new file mode 100644
index 00000000..c58da735
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs
@@ -0,0 +1,366 @@
+// 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 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 );
+
+ 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 );
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta
new file mode 100644
index 00000000..2e9b5ba5
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectDiffuseLighting.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 11bf17b0757d57c47add2eb50c62c75e
+timeCreated: 1495726164
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs
new file mode 100644
index 00000000..197e193e
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs
@@ -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;
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta
new file mode 100644
index 00000000..0c0bb141
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/IndirectSpecularLight.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0820850e74009954188ff84e2f5cc4f2
+timeCreated: 1495817589
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs
new file mode 100644
index 00000000..57ad0f44
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs
@@ -0,0 +1,128 @@
+// 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 )
+ {
+ 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;
+ }
+
+
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta
new file mode 100644
index 00000000..05a8aa70
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightAttenuation.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4e205b44d56609f459ffc558febe2792
+timeCreated: 1495449979
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs
new file mode 100644
index 00000000..92021081
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs
@@ -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";
+ }
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta
new file mode 100644
index 00000000..9acf2a10
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/LightColorNode.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 275270020c577924caf04492f73b2ea6
+timeCreated: 1481126954
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs
new file mode 100644
index 00000000..80aae5df
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs
@@ -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;
+ }
+ }
+}
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta
new file mode 100644
index 00000000..79f4fc5b
--- /dev/null
+++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Constants/ShaderVariables/Lighting/WorldSpaceLightPos.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: db94d973647dae9488d3ef5ee2fd95a4
+timeCreated: 1481126959
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: