You've already forked FateViewer
Add project files.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Camera Depth Fade", "Camera And Screen", "Outputs a 0 - 1 gradient representing the distance between the surface of this object and camera near plane" )]
|
||||
public sealed class CameraDepthFade : ParentNode
|
||||
{
|
||||
//{0} - Eye Depth
|
||||
//{1} - Offset
|
||||
//{2} - Distance
|
||||
private const string CameraDepthFadeFormat = "(( {0} -_ProjectionParams.y - {1} ) / {2})";
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Vertex Position", -1, MasterNodePortCategory.Fragment, 2 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Length", -1, MasterNodePortCategory.Fragment, 0 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Offset", -1, MasterNodePortCategory.Fragment, 1 );
|
||||
GetInputPortByUniqueId( 0 ).FloatInternalData = 1;
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Out" );
|
||||
m_useInternalPortData = true;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
InputPort vertexPort = GetInputPortByUniqueId( 2 );
|
||||
InputPort lengthPort = GetInputPortByUniqueId( 0 );
|
||||
InputPort offsetPort = GetInputPortByUniqueId( 1 );
|
||||
|
||||
string distance = lengthPort.GeneratePortInstructions( ref dataCollector );
|
||||
string offset = offsetPort.GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
string value = string.Empty;
|
||||
string eyeDepth = string.Empty;
|
||||
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
if( vertexPort.IsConnected )
|
||||
{
|
||||
string varName = "customSurfaceDepth" + OutputId;
|
||||
GenerateInputInVertex( ref dataCollector, 2, varName, false );
|
||||
|
||||
string formatStr = string.Empty;
|
||||
if( dataCollector.IsSRP )
|
||||
formatStr = "-TransformWorldToView(TransformObjectToWorld({0})).z";
|
||||
else
|
||||
formatStr = "-UnityObjectToViewPos({0}).z";
|
||||
|
||||
string eyeInstruction = string.Format( formatStr, varName );
|
||||
eyeDepth = "customEye" + OutputId;
|
||||
dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( eyeDepth, WirePortDataType.FLOAT, CurrentPrecisionType, eyeInstruction );
|
||||
}
|
||||
else
|
||||
{
|
||||
eyeDepth = dataCollector.TemplateDataCollectorInstance.GetEyeDepth( CurrentPrecisionType );
|
||||
}
|
||||
|
||||
value = string.Format( CameraDepthFadeFormat, eyeDepth, offset, distance );
|
||||
RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId );
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
|
||||
if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
|
||||
{
|
||||
string vertexVarName = string.Empty;
|
||||
if( vertexPort.IsConnected )
|
||||
{
|
||||
vertexVarName = vertexPort.GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz";
|
||||
}
|
||||
|
||||
//dataCollector.AddVertexInstruction( "float cameraDepthFade" + UniqueId + " = (( -UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z -_ProjectionParams.y - " + offset + " ) / " + distance + ");", UniqueId );
|
||||
value = string.Format( CameraDepthFadeFormat, "-UnityObjectToViewPos( " + vertexVarName + " ).z", offset, distance );
|
||||
RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId );
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables );
|
||||
|
||||
if( dataCollector.TesselationActive )
|
||||
{
|
||||
if( vertexPort.IsConnected )
|
||||
{
|
||||
string vertexValue = vertexPort.GeneratePortInstructions( ref dataCollector );
|
||||
eyeDepth = "customSurfaceDepth" + OutputId;
|
||||
RegisterLocalVariable( 0, string.Format( "-UnityObjectToViewPos( {0} ).z", vertexValue ), ref dataCollector, eyeDepth );
|
||||
}
|
||||
else
|
||||
{
|
||||
eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag( ref dataCollector, UniqueId, CurrentPrecisionType );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if( vertexPort.IsConnected )
|
||||
{
|
||||
string varName = "customSurfaceDepth" + OutputId;
|
||||
GenerateInputInVertex( ref dataCollector, 2, varName, false );
|
||||
dataCollector.AddToInput( UniqueId, varName, WirePortDataType.FLOAT );
|
||||
string vertexInstruction = "-UnityObjectToViewPos( " + varName + " ).z";
|
||||
dataCollector.AddToVertexLocalVariables( UniqueId, Constants.VertexShaderOutputStr + "." + varName + " = " + vertexInstruction + ";" );
|
||||
eyeDepth = Constants.InputVarStr + "." + varName;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToInput( UniqueId, "eyeDepth", WirePortDataType.FLOAT );
|
||||
string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z";
|
||||
dataCollector.AddToVertexLocalVariables( UniqueId, Constants.VertexShaderOutputStr + ".eyeDepth = " + instruction + ";" );
|
||||
eyeDepth = Constants.InputVarStr + ".eyeDepth";
|
||||
}
|
||||
}
|
||||
|
||||
value = string.Format( CameraDepthFadeFormat, eyeDepth, offset, distance );
|
||||
RegisterLocalVariable( 0, value, ref dataCollector, "cameraDepthFade" + OutputId );
|
||||
//dataCollector.AddToLocalVariables( UniqueId, "float cameraDepthFade" + UniqueId + " = (( " + Constants.InputVarStr + ".eyeDepth -_ProjectionParams.y - "+ offset + " ) / " + distance + ");" );
|
||||
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96f38a9f14906ca49b505b8e305c37ec
|
||||
timeCreated: 1491316341
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Compute Grab Screen Pos", "Camera And Screen", "Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position" )]
|
||||
public sealed class ComputeGrabScreenPosHlpNode : HelperParentNode
|
||||
{
|
||||
private readonly string[] ComputeGrabScreenPosFunction =
|
||||
{
|
||||
"inline float4 ComputeGrabScreenPos( float4 pos )\n",
|
||||
"{\n",
|
||||
"#if UNITY_UV_STARTS_AT_TOP\n",
|
||||
"\tfloat scale = -1.0;\n",
|
||||
"#else\n",
|
||||
"\tfloat scale = 1.0;\n",
|
||||
"#endif\n",
|
||||
"\tfloat4 o = pos * 0.5f;\n",
|
||||
"\to.xy = float2( o.x, o.y*scale ) + o.w;\n",
|
||||
"#ifdef UNITY_SINGLE_PASS_STEREO\n",
|
||||
"\to.xy = TransformStereoScreenSpaceTex ( o.xy, pos.w );\n",
|
||||
"#endif\n",
|
||||
"\to.zw = pos.zw;\n",
|
||||
"\treturn o;\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "ComputeGrabScreenPos";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZW";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "computeGrabScreenPos" + OutputId;
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsTemplate && dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD )
|
||||
{
|
||||
dataCollector.AddFunction( m_funcType, ComputeGrabScreenPosFunction, false );
|
||||
}
|
||||
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fe7f4be962b9e8459eb156503b99d41
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
using UnityEngine;
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Compute Screen Pos", "Camera And Screen", "Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position" )]
|
||||
public sealed class ComputeScreenPosHlpNode : HelperParentNode
|
||||
{
|
||||
[SerializeField]
|
||||
private bool m_normalize = false;
|
||||
private string NormalizeStr = "Normalize";
|
||||
private readonly string[] NormalizeOps =
|
||||
{ "{0} = {0} / {0}.w;",
|
||||
"{0}.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? {0}.z : {0}.z* 0.5 + 0.5;"
|
||||
};
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "ComputeScreenPos";
|
||||
m_funcHDFormatOverride = "ComputeScreenPos( {0} , _ProjectionParams.x )";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZW";
|
||||
m_autoWrapProperties = true;
|
||||
m_previewShaderGUID = "97bd4895d847d764eb21d2bf7aa13671";
|
||||
}
|
||||
|
||||
public override void SetPreviewInputs()
|
||||
{
|
||||
base.SetPreviewInputs();
|
||||
m_previewMaterialPassId = m_normalize ? 1 : 0;
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "computeScreenPos" + OutputId;
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
m_normalize = EditorGUILayoutToggle( NormalizeStr, m_normalize );
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
string result = base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
if( m_normalize )
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, string.Format( NormalizeOps[ 0 ], m_localVarName ) );
|
||||
dataCollector.AddLocalVariable( UniqueId, string.Format( NormalizeOps[ 1 ], m_localVarName ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_normalize );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() > 15404 )
|
||||
{
|
||||
m_normalize = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c220606396d6e6048a901f217be1435e
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Decode Depth Normal", "Miscellaneous", "Decodes both Depth and Normal from a previously encoded pixel value" )]
|
||||
public sealed class DecodeDepthNormalNode : ParentNode
|
||||
{
|
||||
// URP will only have support for depth normals texture over v.10 ... must revisit this node when it comes out
|
||||
private const string SRPErrorMessage = "This node is only currently supported on the Built-in pipeline";
|
||||
private const string DecodeDepthNormalFunc = "DecodeDepthNormal( {0}, {1}, {2} );";
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT4, false, "Encoded" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Depth" );
|
||||
AddOutputPort( WirePortDataType.FLOAT3, "Normal" );
|
||||
m_previewShaderGUID = "dbf37c4d3ce0f0b41822584d6c9ba203";
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsSRP )
|
||||
{
|
||||
UIUtils.ShowMessage( SRPErrorMessage, MessageSeverity.Error );
|
||||
return GenerateErrorValue( outputId );
|
||||
}
|
||||
|
||||
if( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) )
|
||||
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
string encodedValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string depthDecodedVal = "depthDecodedVal" + OutputId;
|
||||
string normalDecodedVal = "normalDecodedVal" + OutputId;
|
||||
RegisterLocalVariable( 0, "0", ref dataCollector, depthDecodedVal );
|
||||
RegisterLocalVariable( 1, "float3(0,0,0)", ref dataCollector, normalDecodedVal );
|
||||
dataCollector.AddLocalVariable( UniqueId, string.Format( DecodeDepthNormalFunc, encodedValue , depthDecodedVal, normalDecodedVal) );
|
||||
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cc4e3c718669d54c97614ac6abcfaff
|
||||
timeCreated: 1513695160
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Decode Float RGBA", "Miscellaneous", "Decodes RGBA color into a float" )]
|
||||
public sealed class DecodeFloatRGBAHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "DecodeFloatRGBA";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_inputPorts[ 0 ].Name = "RGBA";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false );
|
||||
m_previewShaderGUID = "f71b31b15ff3f2042bafbed40acd29f4";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "decodeFloatRGBA" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c5479ff48207cf43a308ec9f110fa9f
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Decode Float RG", "Miscellaneous", "Decodes a previously-encoded RG float" )]
|
||||
public sealed class DecodeFloatRGHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "DecodeFloatRG";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
|
||||
m_inputPorts[ 0 ].Name = "RG";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false );
|
||||
m_previewShaderGUID = "1fb3121b1c8febb4dbcc2a507a2df2db";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "decodeFloatRG" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a965812ada2b83343a1f511273fcfc52
|
||||
timeCreated: 1481126958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Decode Lightmap", "Miscellaneous", "Decodes color from Unity lightmap (RGBM or dLDR depending on platform)" )]
|
||||
public sealed class DecodeLightmapHlpNode : ParentNode
|
||||
{
|
||||
private const string m_funcStandard = "DecodeLightmap({0})";
|
||||
private string m_funcSRP = "DecodeLightmap({0},{1})";
|
||||
|
||||
private const string DecodeInstructionsLWValueStr = "half4 decodeLightmapInstructions = half4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0h, 0.0h);";
|
||||
private const string DecodeInstructionsNameStr = "decodeLightmapInstructions";
|
||||
private readonly string[] DecodeInstructionsHDValueStr =
|
||||
{
|
||||
"#ifdef UNITY_LIGHTMAP_FULL_HDR//ase_decode_lightmap_0",
|
||||
"\tbool useRGBMLightmap = false;//ase_decode_lightmap_1",
|
||||
"\tfloat4 decodeLightmapInstructions = float4( 0.0, 0.0, 0.0, 0.0 );//ase_decode_lightmap_2",
|
||||
"#else//ase_decode_lightmap//ase_decode_lightmap_3",
|
||||
"\tbool useRGBMLightmap = true;//ase_decode_lightmap_4",
|
||||
"#if defined(UNITY_LIGHTMAP_RGBM_ENCODING)//ase_decode_lightmap_5",
|
||||
"\tfloat4 decodeLightmapInstructions = float4(34.493242, 2.2, 0.0, 0.0);//ase_decode_lightmap_6",
|
||||
"#else//ase_decode_lightmap_7",
|
||||
"\tfloat4 decodeLightmapInstructions = float4( 2.0, 2.2, 0.0, 0.0 );//ase_decode_lightmap_8",
|
||||
"#endif//ase_decode_lightmap_9",
|
||||
"#endif//ase_decode_lightmap_10"
|
||||
};
|
||||
private string m_localVarName = null;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT4, false, "Value" );
|
||||
AddInputPort( WirePortDataType.FLOAT4, false, "Instructions" );
|
||||
|
||||
AddOutputPort( WirePortDataType.FLOAT3, Constants.EmptyPortValue );
|
||||
|
||||
m_previewShaderGUID = "c2d3bee1aee183343b31b9208cb402e9";
|
||||
m_useInternalPortData = true;
|
||||
}
|
||||
|
||||
public override string GetIncludes()
|
||||
{
|
||||
return Constants.UnityCgLibFuncs;
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "decodeLightMap" + OutputId;
|
||||
}
|
||||
|
||||
public override void OnNodeLogicUpdate( DrawInfo drawInfo )
|
||||
{
|
||||
base.OnNodeLogicUpdate( drawInfo );
|
||||
m_inputPorts[ 1 ].Visible = m_containerGraph.ParentWindow.IsShaderFunctionWindow || m_containerGraph.IsSRP;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
|
||||
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
|
||||
string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string finalResult = string.Empty;
|
||||
if( dataCollector.IsTemplate && dataCollector.IsSRP )
|
||||
{
|
||||
string instructions = string.Empty;
|
||||
if( m_inputPorts[ 1 ].IsConnected )
|
||||
{
|
||||
instructions = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dataCollector.TemplateDataCollectorInstance.IsHDRP )
|
||||
{
|
||||
for( int i = 0; i < DecodeInstructionsHDValueStr.Length; i++ )
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, DecodeInstructionsHDValueStr[ i ] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, DecodeInstructionsLWValueStr );
|
||||
}
|
||||
instructions = DecodeInstructionsNameStr;
|
||||
|
||||
}
|
||||
|
||||
finalResult = string.Format( m_funcSRP, value , instructions );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
finalResult = string.Format( m_funcStandard, value );
|
||||
}
|
||||
|
||||
RegisterLocalVariable( 0, finalResult, ref dataCollector, m_localVarName );
|
||||
return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3d1879d1e402b34f98b8e8cdf94d719
|
||||
timeCreated: 1481126958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Decode View Normal Stereo", "Miscellaneous", "Decodes view space normal from enc4.xy" )]
|
||||
public sealed class DecodeViewNormalStereoHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "DecodeViewNormalStereo";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
m_previewShaderGUID = "e996db1cc4510c84185cb9f933f916bb";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "decodeViewNormalStereo" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94df47461b7e6244eaf92b0dab7cc7ee
|
||||
timeCreated: 1481126957
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,168 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Depth Fade", "Surface Data", "Outputs a linear gradient representing the distance between the surface of this object and geometry behind" )]
|
||||
public sealed class DepthFade : ParentNode
|
||||
{
|
||||
private const string ConvertToLinearStr = "Convert To Linear";
|
||||
private const string SaturateStr = "Saturate";
|
||||
private const string MirrorStr = "Mirror";
|
||||
|
||||
[SerializeField]
|
||||
private bool m_convertToLinear = true;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_saturate = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_mirror = true;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Vertex Position", -1, MasterNodePortCategory.Fragment, 1 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Distance",-1,MasterNodePortCategory.Fragment,0 );
|
||||
GetInputPortByUniqueId(0).FloatInternalData = 1;
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Out" );
|
||||
m_useInternalPortData = true;
|
||||
m_autoWrapProperties = true;
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
|
||||
{
|
||||
UIUtils.ShowNoVertexModeNodeMessage( this );
|
||||
return "0";
|
||||
}
|
||||
|
||||
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
|
||||
return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
|
||||
|
||||
if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
|
||||
if( !dataCollector.IsTemplate || dataCollector.TemplateDataCollectorInstance.CurrentSRPType != TemplateSRPType.HD )
|
||||
{
|
||||
if( dataCollector.IsTemplate && dataCollector.CurrentSRPType == TemplateSRPType.Lightweight )
|
||||
{
|
||||
//dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPVar );
|
||||
//dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureSRPSampler );
|
||||
dataCollector.AddToDirectives( Constants.CameraDepthTextureLWEnabler, -1, AdditionalLineType.Define );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureValue );
|
||||
}
|
||||
|
||||
dataCollector.AddToUniforms( UniqueId, Constants.CameraDepthTextureTexelSize );
|
||||
}
|
||||
|
||||
string screenPosNorm = string.Empty;
|
||||
InputPort vertexPosPort = GetInputPortByUniqueId( 1 );
|
||||
if( vertexPosPort.IsConnected )
|
||||
{
|
||||
string vertexPosVar = "vertexPos" + OutputId;
|
||||
GenerateInputInVertex( ref dataCollector, 1, vertexPosVar, false );
|
||||
screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalizedForValue( vertexPosVar, OutputId, ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
string ppsScreenPos = string.Empty;
|
||||
if( !dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData( TemplateInfoOnSematics.SCREEN_POSITION_NORMALIZED, WirePortDataType.FLOAT4, PrecisionType.Float, ref ppsScreenPos, true, MasterNodePortCategory.Fragment ) )
|
||||
{
|
||||
screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
|
||||
}
|
||||
else
|
||||
{
|
||||
screenPosNorm = ppsScreenPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
screenPosNorm = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
|
||||
}
|
||||
}
|
||||
|
||||
string screenDepth = TemplateHelperFunctions.CreateDepthFetch( dataCollector, screenPosNorm );
|
||||
if( m_convertToLinear )
|
||||
{
|
||||
if( dataCollector.IsTemplate && dataCollector.IsSRP )
|
||||
screenDepth = string.Format( "LinearEyeDepth({0},_ZBufferParams)", screenDepth );
|
||||
else
|
||||
screenDepth = string.Format( "LinearEyeDepth({0})", screenDepth );
|
||||
}
|
||||
else
|
||||
{
|
||||
screenDepth = string.Format( "({0}*( _ProjectionParams.z - _ProjectionParams.y ))", screenDepth );
|
||||
}
|
||||
|
||||
string distance = GetInputPortByUniqueId( 0 ).GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, "float screenDepth" + OutputId + " = " + screenDepth + ";" );
|
||||
|
||||
string finalVarName = "distanceDepth" + OutputId;
|
||||
string finalVarValue = string.Empty;
|
||||
if( dataCollector.IsTemplate && dataCollector.IsSRP )
|
||||
finalVarValue = "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z,_ZBufferParams ) ) / ( " + distance + " )";
|
||||
else
|
||||
finalVarValue = "( screenDepth" + OutputId + " - LinearEyeDepth( " + screenPosNorm + ".z ) ) / ( " + distance + " )";
|
||||
|
||||
if( m_mirror )
|
||||
{
|
||||
finalVarValue = string.Format( "abs( {0} )", finalVarValue );
|
||||
}
|
||||
|
||||
if( m_saturate )
|
||||
{
|
||||
finalVarValue = string.Format( "saturate( {0} )", finalVarValue );
|
||||
}
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, finalVarName, finalVarValue );
|
||||
m_outputPorts[ 0 ].SetLocalValue( finalVarName, dataCollector.PortCategory );
|
||||
return GetOutputColorItem( 0, outputId, finalVarName );
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
m_convertToLinear = EditorGUILayoutToggle( ConvertToLinearStr, m_convertToLinear );
|
||||
m_mirror = EditorGUILayoutToggle( MirrorStr, m_mirror );
|
||||
m_saturate = EditorGUILayoutToggle( SaturateStr, m_saturate );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() >= 13901 )
|
||||
{
|
||||
m_convertToLinear = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
if( UIUtils.CurrentShaderVersion() > 15607 )
|
||||
{
|
||||
m_saturate = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
|
||||
if( UIUtils.CurrentShaderVersion() > 15700 )
|
||||
{
|
||||
m_mirror = 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_convertToLinear );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_saturate );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_mirror );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 279c74ce44e24204d803be6ec743c290
|
||||
timeCreated: 1491316341
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Diffuse And Specular From Metallic", "Miscellaneous", "Gets Diffuse and Specular values from Metallic. Uses DiffuseAndSpecularFromMetallic function from UnityStandardUtils." )]
|
||||
public class DiffuseAndSpecularFromMetallicNode : ParentNode
|
||||
{
|
||||
//half3 DiffuseAndSpecularFromMetallic (half3 albedo, half metallic, out half3 specColor, out half oneMinusReflectivity)
|
||||
private const string FuncFormat = "DiffuseAndSpecularFromMetallic({0},{1},{2},{3})";
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Albedo" );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Metallic" );
|
||||
AddOutputPort( WirePortDataType.FLOAT3, "Out" );
|
||||
AddOutputPort( WirePortDataType.FLOAT3, "Spec Color" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "One Minus Reflectivity" );
|
||||
m_previewShaderGUID = "c7c4485750948a045b5dab0985896e17";
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsSRP )
|
||||
{
|
||||
UIUtils.ShowMessage( UniqueId, "Diffuse And Specular From Metallic Node not compatible with SRP" );
|
||||
return m_outputPorts[0].ErrorValue;
|
||||
}
|
||||
|
||||
if( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) )
|
||||
{
|
||||
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs );
|
||||
|
||||
string albedo = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string metallic = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
string specColorVar = "specColor" + OutputId;
|
||||
string oneMinusReflectivityVar = "oneMinusReflectivity" + OutputId;
|
||||
string varName = "diffuseAndSpecularFromMetallic" + OutputId;
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, PrecisionType.Half, WirePortDataType.FLOAT3, specColorVar, "(0).xxx" );
|
||||
dataCollector.AddLocalVariable( UniqueId, PrecisionType.Half, WirePortDataType.FLOAT, oneMinusReflectivityVar, "0" );
|
||||
|
||||
|
||||
string varValue = string.Format( FuncFormat, albedo, metallic, specColorVar, oneMinusReflectivityVar );
|
||||
dataCollector.AddLocalVariable( UniqueId, PrecisionType.Half, WirePortDataType.FLOAT3, varName, varValue );
|
||||
m_outputPorts[ 0 ].SetLocalValue( varName, dataCollector.PortCategory );
|
||||
m_outputPorts[ 1 ].SetLocalValue( specColorVar, dataCollector.PortCategory );
|
||||
m_outputPorts[ 2 ].SetLocalValue( oneMinusReflectivityVar, dataCollector.PortCategory );
|
||||
|
||||
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a792f114a5433af499dce78ebe05a9e6
|
||||
timeCreated: 1534266498
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,311 @@
|
||||
// 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( "Dither", "Camera And Screen", "Generates a dithering pattern" )]
|
||||
public sealed class DitheringNode : ParentNode
|
||||
{
|
||||
private const string InputTypeStr = "Pattern";
|
||||
private const string CustomScreenPosStr = "screenPosition";
|
||||
|
||||
private string m_functionHeader = "Dither4x4Bayer( {0}, {1} )";
|
||||
private string m_functionBody = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
private int m_selectedPatternInt = 0;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_customScreenPos = false;
|
||||
|
||||
private readonly string[] PatternsFuncStr = { "4x4Bayer", "8x8Bayer", "NoiseTex" };
|
||||
private readonly string[] PatternsStr = { "4x4 Bayer", "8x8 Bayer", "Noise Texture" };
|
||||
|
||||
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
|
||||
|
||||
private InputPort m_texPort;
|
||||
private InputPort m_ssPort;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
|
||||
AddInputPort( WirePortDataType.SAMPLER2D, false, "Pattern");
|
||||
m_inputPorts[ 1 ].CreatePortRestrictions( WirePortDataType.SAMPLER2D );
|
||||
m_texPort = m_inputPorts[ 1 ];
|
||||
AddInputPort( WirePortDataType.FLOAT4, false, "Screen Position" );
|
||||
|
||||
AddInputPort( WirePortDataType.SAMPLERSTATE, false, "SS" );
|
||||
m_inputPorts[ 3 ].CreatePortRestrictions( WirePortDataType.SAMPLERSTATE );
|
||||
m_ssPort = m_inputPorts[ 3 ];
|
||||
|
||||
AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
|
||||
m_textLabelWidth = 110;
|
||||
m_autoWrapProperties = true;
|
||||
m_hasLeftDropdown = true;
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, PatternsStr[ m_selectedPatternInt ] ) );
|
||||
UpdatePorts();
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
m_upperLeftWidget = null;
|
||||
m_texPort = null;
|
||||
m_ssPort = null;
|
||||
}
|
||||
|
||||
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 OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
|
||||
{
|
||||
base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
|
||||
if( !m_texPort.CheckValidType( type ) )
|
||||
{
|
||||
m_texPort.FullDeleteConnections();
|
||||
UIUtils.ShowMessage( UniqueId, "Dithering node only accepts SAMPLER2D input type.\nTexture Object connected changed to " + type + ", connection was lost, please review and update accordingly.", MessageSeverity.Warning );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw( DrawInfo drawInfo )
|
||||
{
|
||||
base.Draw( drawInfo );
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_selectedPatternInt = m_upperLeftWidget.DrawWidget( this, m_selectedPatternInt, PatternsStr );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
UpdatePorts();
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_selectedPatternInt = EditorGUILayoutPopup( "Pattern", m_selectedPatternInt, PatternsStr );
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
UpdatePorts();
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_customScreenPos = EditorGUILayoutToggle( "Screen Position", m_customScreenPos );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
UpdatePorts();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePorts()
|
||||
{
|
||||
m_texPort.Visible = ( m_selectedPatternInt == 2 );
|
||||
m_ssPort.Visible = ( m_selectedPatternInt == 2 );
|
||||
m_inputPorts[ 2 ].Visible = m_customScreenPos;
|
||||
m_sizeIsDirty = true;
|
||||
}
|
||||
|
||||
private void GeneratePattern( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, PatternsStr[ m_selectedPatternInt ] ) );
|
||||
switch ( m_selectedPatternInt )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
{
|
||||
m_functionBody = string.Empty;
|
||||
m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( {0}, {1} )";
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( int x, int y )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "const float dither[ 16 ] = {" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 1, 9, 3, 11," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 13, 5, 15, 7," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 4, 12, 2, 10," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 16, 8, 14, 6 };" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int r = y * 4 + x;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "return dither[r] / 16; // same # of instructions as pre-dividing due to compiler magic" );
|
||||
IOUtils.CloseFunctionBody( ref m_functionBody );
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
m_functionBody = string.Empty;
|
||||
m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( {0}, {1} )";
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( int x, int y )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "const float dither[ 64 ] = {" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 1, 49, 13, 61, 4, 52, 16, 64," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 33, 17, 45, 29, 36, 20, 48, 32," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 9, 57, 5, 53, 12, 60, 8, 56," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 41, 25, 37, 21, 44, 28, 40, 24," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 3, 51, 15, 63, 2, 50, 14, 62," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 35, 19, 47, 31, 34, 18, 46, 30," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 11, 59, 7, 55, 10, 58, 6, 54," );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " 43, 27, 39, 23, 42, 26, 38, 22};" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int r = y * 8 + x;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "return dither[r] / 64; // same # of instructions as pre-dividing due to compiler magic" );
|
||||
IOUtils.CloseFunctionBody( ref m_functionBody );
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
|
||||
|
||||
m_functionBody = string.Empty;
|
||||
m_functionHeader = "Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "({0}, {1}, {2})";
|
||||
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float Dither" + PatternsFuncStr[ m_selectedPatternInt ] + "( float4 screenPos, " + GeneratorUtils.GetPropertyDeclaraction( "noiseTexture", TextureType.Texture2D, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplernoiseTexture", TextureType.Texture2D, ", " ) + "float4 noiseTexelSize )" );
|
||||
|
||||
string samplingCall = GeneratorUtils.GenerateSamplingCall( ref dataCollector, WirePortDataType.SAMPLER2D, "noiseTexture", "samplernoiseTexture", "screenPos.xy * _ScreenParams.xy * noiseTexelSize.xy", MipType.MipLevel, "0" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float dither = "+ samplingCall + ".g;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float ditherRate = noiseTexelSize.x * noiseTexelSize.y;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "dither = ( 1 - ditherRate ) * dither + ditherRate;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "return dither;" );
|
||||
IOUtils.CloseFunctionBody( ref m_functionBody );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
base.PropagateNodeData( nodeData, ref dataCollector );
|
||||
dataCollector.UsingCustomScreenPos = true;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
GeneratePattern( ref dataCollector );
|
||||
|
||||
if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables );
|
||||
string varName = string.Empty;
|
||||
bool isFragment = dataCollector.IsFragmentCategory;
|
||||
if( m_customScreenPos && m_inputPorts[ 2 ].IsConnected )
|
||||
{
|
||||
varName = "ditherCustomScreenPos" + OutputId;
|
||||
string customScreenPosVal = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, varName, customScreenPosVal );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dataCollector.TesselationActive && isFragment )
|
||||
{
|
||||
varName = GeneratorUtils.GenerateClipPositionOnFrag( ref dataCollector, UniqueId, CurrentPrecisionType );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
varName = dataCollector.TemplateDataCollectorInstance.GetScreenPosNormalized( CurrentPrecisionType );
|
||||
}
|
||||
else
|
||||
{
|
||||
varName = GeneratorUtils.GenerateScreenPositionNormalized( ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
|
||||
}
|
||||
}
|
||||
}
|
||||
string surfInstruction = varName + ".xy * _ScreenParams.xy";
|
||||
m_showErrorMessage = false;
|
||||
string functionResult = "";
|
||||
string noiseTex = string.Empty;
|
||||
switch ( m_selectedPatternInt )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction );
|
||||
functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 4)", "fmod(" + "clipScreen" + OutputId + ".y, 4)" );
|
||||
break;
|
||||
case 1:
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, "clipScreen" + OutputId, surfInstruction );
|
||||
functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, "fmod(" + "clipScreen" + OutputId + ".x, 8)", "fmod(" + "clipScreen" + OutputId + ".y, 8)" );
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if( !m_texPort.IsConnected )
|
||||
{
|
||||
m_showErrorMessage = true;
|
||||
m_errorMessageTypeIsError = NodeMessageType.Warning;
|
||||
m_errorMessageTooltip = "Please connect a texture object to the Pattern input port to generate a proper dithered pattern";
|
||||
return "0";
|
||||
} else
|
||||
{
|
||||
ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
|
||||
noiseTex = m_texPort.GeneratePortInstructions( ref dataCollector );
|
||||
//GeneratePattern( ref dataCollector );
|
||||
dataCollector.AddToUniforms( UniqueId, "float4 " + noiseTex + "_TexelSize;", dataCollector.IsSRP );
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
if( outsideGraph.SamplingMacros )
|
||||
#else
|
||||
if( outsideGraph.SamplingMacros && !outsideGraph.IsStandardSurface )
|
||||
#endif
|
||||
{
|
||||
string sampler = string.Empty;
|
||||
if( m_ssPort.IsConnected )
|
||||
{
|
||||
sampler = m_ssPort.GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
sampler = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, noiseTex );
|
||||
}
|
||||
//if( outsideGraph.IsSRP )
|
||||
// functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, varName, noiseTex + ", " + sampler, noiseTex + "_TexelSize" );
|
||||
//else
|
||||
functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, varName, noiseTex + ", " + sampler, noiseTex + "_TexelSize" );
|
||||
}
|
||||
else
|
||||
{
|
||||
functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, varName, noiseTex, noiseTex + "_TexelSize" );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, "dither" + OutputId, functionResult );
|
||||
|
||||
if( m_inputPorts[ 0 ].IsConnected )
|
||||
{
|
||||
string driver = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
dataCollector.AddLocalVariable( UniqueId, "dither" + OutputId+" = step( dither"+ OutputId + ", "+ driver + " );" );
|
||||
}
|
||||
|
||||
//RegisterLocalVariable( 0, functionResult, ref dataCollector, "dither" + OutputId );
|
||||
m_outputPorts[ 0 ].SetLocalValue( "dither" + OutputId, dataCollector.PortCategory );
|
||||
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
m_selectedPatternInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
if( UIUtils.CurrentShaderVersion() > 15404 )
|
||||
{
|
||||
m_customScreenPos = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
UpdatePorts();
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedPatternInt );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_customScreenPos );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 284ebed5f88c13e45bc331b2df93aa75
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Encode Depth Normal", "Miscellaneous", "Encodes both Depth and Normal values into a Float4 value" )]
|
||||
public sealed class EncodeDepthNormalNode : ParentNode
|
||||
{
|
||||
private const string EncodeDepthNormalFunc = "EncodeDepthNormal( {0}, {1} )";
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Depth" );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Normal" );
|
||||
AddOutputPort( WirePortDataType.FLOAT4, Constants.EmptyPortValue );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
string depthValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string normalValue = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
RegisterLocalVariable( 0, string.Format( EncodeDepthNormalFunc, depthValue, normalValue ), ref dataCollector, "encodedDepthNormal" + OutputId );
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cabbbe25e4b26b54c84e27007c08a7dd
|
||||
timeCreated: 1513695146
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Encode Float RGBA", "Miscellaneous", "Encodes [0..1] range float into RGBA color, for storage in low precision render target" )]
|
||||
public sealed class EncodeFloatRGBAHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "EncodeFloatRGBA";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].Name = "RGBA";
|
||||
m_previewShaderGUID = "c21569bf5b9371b4ca13c0c00abd5562";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "encodeFloatRGBA" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6532496dc1791d94cbb46004000bda61
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Encode Float RG ", "Miscellaneous", "Encodes [0..1] range float into a float2" )]
|
||||
public sealed class EncodeFloatRGHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "EncodeFloatRG ";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
|
||||
m_outputPorts[ 0 ].Name = "RG";
|
||||
m_previewShaderGUID = "a44b520baa5c39e41bc69a22ea46f24d";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "encodeFloatRG" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8bce5e7063ac6b4d93aaf15f7fd1b10
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Encode View Normal Stereo", "Miscellaneous", "Encodes view space normal into two numbers in [0..1] range" )]
|
||||
public sealed class EncodeViewNormalStereoHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "EncodeViewNormalStereo";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_inputPorts[ 0 ].Name = "XYZ";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
|
||||
m_previewShaderGUID = "3d0b3d482b7246c4cb60fa73e6ceac6c";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "encodeViewNormalStereo" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17511ec398441ac479a2dd77d2531837
|
||||
timeCreated: 1481126953
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,122 @@
|
||||
// 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( "Gamma To Linear", "Image Effects", "Converts color from gamma space to linear space" )]
|
||||
public sealed class GammaToLinearNode : HelperParentNode
|
||||
{
|
||||
public readonly static string[] ModeListStr = { "Fast sRGB to Linear", "Exact sRGB to Linear" };
|
||||
public readonly static int[] ModeListInt = { 0, 1 };
|
||||
|
||||
public readonly static string[] ModeListStrLW = { "Fast sRGB to Linear", "Exact sRGB to Linear", "Gamma 2.0 to Linear", "Gamma 2.2 to Linear" };
|
||||
public readonly static int[] ModeListIntLW = { 0, 1, 2, 3 };
|
||||
|
||||
[SerializeField]
|
||||
public int m_selectedMode = 0;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "GammaToLinearSpace";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_inputPorts[ 0 ].Name = "RGB";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_autoWrapProperties = true;
|
||||
m_previewShaderGUID = "e82a888a6ebdb1443823aafceaa051b9";
|
||||
m_textLabelWidth = 120;
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "gammaToLinear" + OutputId;
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
if( ContainerGraph.IsSRP )
|
||||
{
|
||||
m_selectedMode = EditorGUILayoutIntPopup( "Mode", m_selectedMode, ModeListStrLW, ModeListIntLW );
|
||||
EditorGUILayout.HelpBox( "Fast sRGB: fast approximation from sRGB to Linear\n\nExact sRGB: a more expensive but exact calculation from sRGB to Linear.\n\nGamma 2.0: crude approximation from Gamma to Linear using a power of 2.0 gamma value\n\nGamma 2.2: an approximation from Gamma to Linear using a power of 2.2 gamma value", MessageType.None );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selectedMode = EditorGUILayoutIntPopup( "Mode", m_selectedMode, ModeListStr, ModeListInt );
|
||||
EditorGUILayout.HelpBox( "Fast sRGB: fast approximation from sRGB to Linear\n\nExact sRGB: a more expensive but exact calculation from sRGB to Linear.", MessageType.None );
|
||||
}
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
if( !dataCollector.IsSRP )
|
||||
{
|
||||
m_selectedMode = Mathf.Min( m_selectedMode, 1 );
|
||||
|
||||
if( m_selectedMode == 1 )
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, "half3 " + m_localVarName + " = " + result + ";" );
|
||||
dataCollector.AddLocalVariable( UniqueId, m_localVarName + " = half3( GammaToLinearSpaceExact(" + m_localVarName + ".r), GammaToLinearSpaceExact(" + m_localVarName + ".g), GammaToLinearSpaceExact(" + m_localVarName + ".b) );" );
|
||||
return m_localVarName;
|
||||
}
|
||||
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToIncludes( UniqueId, TemplateHelperFunctions.CoreCommonLib );
|
||||
dataCollector.AddToIncludes( UniqueId, TemplateHelperFunctions.CoreColorLib );
|
||||
switch( m_selectedMode )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
m_funcLWFormatOverride = "FastSRGBToLinear( {0} )";
|
||||
m_funcHDFormatOverride = "FastSRGBToLinear( {0} )";
|
||||
break;
|
||||
case 1:
|
||||
m_funcLWFormatOverride = "SRGBToLinear( {0} )";
|
||||
m_funcHDFormatOverride = "SRGBToLinear( {0} )";
|
||||
break;
|
||||
case 2:
|
||||
m_funcLWFormatOverride = "Gamma20ToLinear( {0} )";
|
||||
m_funcHDFormatOverride = "Gamma20ToLinear( {0} )";
|
||||
break;
|
||||
case 3:
|
||||
m_funcLWFormatOverride = "Gamma22ToLinear( {0} )";
|
||||
m_funcHDFormatOverride = "Gamma22ToLinear( {0} )";
|
||||
break;
|
||||
}
|
||||
|
||||
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedMode );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() > 11003 && UIUtils.CurrentShaderVersion() <= 14503 )
|
||||
{
|
||||
bool fast = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
if( fast )
|
||||
m_selectedMode = 1;
|
||||
}
|
||||
|
||||
if( UIUtils.CurrentShaderVersion() > 14503 )
|
||||
{
|
||||
m_selectedMode = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb2775ac410d0134c85b7f1ac0a0399f
|
||||
timeCreated: 1481126960
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
//https://docs.unity3d.com/Manual/SL-BuiltinFunctions.html
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
public class HelperParentNode : ParentNode
|
||||
{
|
||||
[SerializeField]
|
||||
protected string m_funcType = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
protected string m_funcLWFormatOverride = string.Empty;
|
||||
|
||||
[SerializeField]
|
||||
protected string m_funcHDFormatOverride = string.Empty;
|
||||
|
||||
protected string m_localVarName = null;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
|
||||
AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
|
||||
m_useInternalPortData = true;
|
||||
}
|
||||
|
||||
public override string GetIncludes()
|
||||
{
|
||||
return Constants.UnityCgLibFuncs;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
|
||||
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
|
||||
if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) )
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
|
||||
string concatResults = string.Empty;
|
||||
bool first = true;
|
||||
for( int i = 0; i < m_inputPorts.Count; i++ )
|
||||
{
|
||||
if( m_inputPorts[ i ].Visible )
|
||||
{
|
||||
if( !first )
|
||||
{
|
||||
concatResults += " , ";
|
||||
}
|
||||
else
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
|
||||
string result = string.Empty;
|
||||
if( m_inputPorts[ i ].IsConnected )
|
||||
{
|
||||
result = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = m_inputPorts[ i ].WrappedInternalData;
|
||||
}
|
||||
|
||||
concatResults += result;
|
||||
}
|
||||
}
|
||||
string finalResult = m_funcType + "( " + concatResults + " )";
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.Lightweight && !string.IsNullOrEmpty( m_funcLWFormatOverride ) )
|
||||
{
|
||||
finalResult = string.Format( m_funcLWFormatOverride, concatResults );
|
||||
}
|
||||
else if( dataCollector.TemplateDataCollectorInstance.CurrentSRPType == TemplateSRPType.HD && !string.IsNullOrEmpty( m_funcHDFormatOverride ) )
|
||||
{
|
||||
finalResult = string.Format( m_funcHDFormatOverride, concatResults );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RegisterLocalVariable( 0, finalResult, ref dataCollector, m_localVarName );
|
||||
return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0eba64bdadd330743894a0623677cb83
|
||||
timeCreated: 1481126953
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
// 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( "Linear To Gamma", "Image Effects", "Converts color from linear space to gamma space" )]
|
||||
public sealed class LinearToGammaNode : HelperParentNode
|
||||
{
|
||||
//[SerializeField]
|
||||
//private bool m_exact = false;
|
||||
|
||||
//private readonly static GUIContent LGExactContent = new GUIContent( "Exact Conversion", "Uses a precise version of the conversion, it's more expensive and often not needed." );
|
||||
|
||||
public readonly static string[] ModeListStr = { "Fast Linear to sRGB", "Exact Linear to sRGB" };
|
||||
public readonly static int[] ModeListInt = { 0, 1 };
|
||||
|
||||
public readonly static string[] ModeListStrLW = { "Fast Linear to sRGB", "Exact Linear to sRGB", "Linear to Gamma 2.0", "Linear to Gamma 2.2" };
|
||||
public readonly static int[] ModeListIntLW = { 0, 1, 2, 3 };
|
||||
|
||||
[SerializeField]
|
||||
public int m_selectedMode = 0;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "LinearToGammaSpace";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_inputPorts[ 0 ].Name = "RGB";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_autoWrapProperties = true;
|
||||
m_previewShaderGUID = "9027c408b928c5c4d8b450712049d541";
|
||||
m_textLabelWidth = 120;
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "linearToGamma" + OutputId;
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
if( ContainerGraph.IsSRP )
|
||||
{
|
||||
m_selectedMode = EditorGUILayoutIntPopup( "Mode", m_selectedMode, ModeListStrLW, ModeListIntLW );
|
||||
EditorGUILayout.HelpBox( "Fast Linear: fast approximation from Linear to sRGB\n\nExact Linear: a more expensive but exact calculation from Linear to sRGB.\n\nLinear 2.0: crude approximation from Linear to Gamma using a power of 1/2.0 gamma value\n\nLinear 2.2: an approximation from Linear to Gamma using a power of 1/2.2 gamma value", MessageType.None );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selectedMode = EditorGUILayoutIntPopup( "Mode", m_selectedMode, ModeListStr, ModeListInt );
|
||||
EditorGUILayout.HelpBox( "Fast Linear: fast approximation from Linear to sRGB\n\nExact Linear: a more expensive but exact calculation from Linear to sRGB.", MessageType.None );
|
||||
}
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
if( !dataCollector.IsSRP )
|
||||
{
|
||||
m_selectedMode = Mathf.Min( m_selectedMode, 1 );
|
||||
|
||||
if( m_selectedMode == 1 )
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, "half3 " + m_localVarName + " = " + result + ";" );
|
||||
dataCollector.AddLocalVariable( UniqueId, m_localVarName + " = half3( LinearToGammaSpaceExact(" + m_localVarName + ".r), LinearToGammaSpaceExact(" + m_localVarName + ".g), LinearToGammaSpaceExact(" + m_localVarName + ".b) );" );
|
||||
return m_localVarName;
|
||||
}
|
||||
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToIncludes( UniqueId, TemplateHelperFunctions.CoreCommonLib );
|
||||
dataCollector.AddToIncludes( UniqueId, TemplateHelperFunctions.CoreColorLib );
|
||||
switch( m_selectedMode )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
m_funcLWFormatOverride = "FastLinearToSRGB( {0} )";
|
||||
m_funcHDFormatOverride = "FastLinearToSRGB( {0} )";
|
||||
break;
|
||||
case 1:
|
||||
m_funcLWFormatOverride = "LinearToSRGB( {0} )";
|
||||
m_funcHDFormatOverride = "LinearToSRGB( {0} )";
|
||||
break;
|
||||
case 2:
|
||||
m_funcLWFormatOverride = "LinearToGamma20( {0} )";
|
||||
m_funcHDFormatOverride = "LinearToGamma20( {0} )";
|
||||
break;
|
||||
case 3:
|
||||
m_funcLWFormatOverride = "LinearToGamma22( {0} )";
|
||||
m_funcHDFormatOverride = "LinearToGamma22( {0} )";
|
||||
break;
|
||||
}
|
||||
|
||||
return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedMode );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() > 11003 && UIUtils.CurrentShaderVersion() <= 14503 )
|
||||
{
|
||||
bool fast = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
if( fast )
|
||||
m_selectedMode = 1;
|
||||
}
|
||||
|
||||
if( UIUtils.CurrentShaderVersion() > 14503 )
|
||||
{
|
||||
m_selectedMode = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5b8a474628aeca4e86b1599f0b26ebc
|
||||
timeCreated: 1481126960
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Luminance", "Image Effects", "Converts color to luminance (grayscale)", Deprecated = true, DeprecatedAlternativeType = typeof( TFHCGrayscale ), DeprecatedAlternative = "Grayscale" )]
|
||||
public sealed class LuminanceHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "Luminance";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_inputPorts[ 0 ].Name = "RGB";
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false );
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "luminance" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8567c2e3eb634a428819fbdfbff110f
|
||||
timeCreated: 1481126960
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Object Space Light Dir", "Light", "Computes object space light direction (not normalized)" )]
|
||||
public sealed class ObjSpaceLightDirHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "ObjSpaceLightDir";
|
||||
m_inputPorts[ 0 ].Visible = false;
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
|
||||
m_useInternalPortData = false;
|
||||
m_previewShaderGUID = "c7852de24cec4a744b5358921e23feee";
|
||||
m_drawPreviewAsSphere = true;
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
//Template must have its Light Mode correctly configured on tags to work as intended
|
||||
return GetOutputVectorItem( 0, outputId, dataCollector.TemplateDataCollectorInstance.GetObjectSpaceLightDir( CurrentPrecisionType ) );
|
||||
}
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );
|
||||
|
||||
string vertexPos = GeneratorUtils.GenerateVertexPosition( ref dataCollector, UniqueId, WirePortDataType.FLOAT4 );
|
||||
return GetOutputVectorItem( 0, outputId, GeneratorUtils.GenerateObjectLightDirection( ref dataCollector, UniqueId, CurrentPrecisionType, vertexPos ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0da9baf35c74c7e468cbe50c3d23ccf0
|
||||
timeCreated: 1481126953
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Object Space View Dir", "Object Transform", "Object space direction (not normalized) from given object space vertex position towards the camera" )]
|
||||
public sealed class ObjSpaceViewDirHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "ObjSpaceViewDir";
|
||||
//TODO: revisit this later
|
||||
m_funcLWFormatOverride = "( mul(GetWorldToObjectMatrix(), float4(_WorldSpaceCameraPos.xyz, 1)).xyz - {0}.xyz )";
|
||||
m_funcHDFormatOverride = "( mul(GetWorldToObjectMatrix(), float4(_WorldSpaceCameraPos.xyz, 1)).xyz - {0}.xyz )";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_inputPorts[ 0 ].Vector4InternalData = new UnityEngine.Vector4( 0, 0, 0, 1 );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
m_previewShaderGUID = "c7852de24cec4a744b5358921e23feee";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "objectSpaceViewDir" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 590b8e54b63ad344f8d8c372e4fc5ed5
|
||||
timeCreated: 1481126955
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,148 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Parallax Mapping", "UV Coordinates", "Calculates offseted UVs for parallax mapping" )]
|
||||
public sealed class ParallaxMappingNode : ParentNode
|
||||
{
|
||||
private enum ParallaxType { Normal, Planar }
|
||||
|
||||
[SerializeField]
|
||||
private int m_selectedParallaxTypeInt = 0;
|
||||
|
||||
[SerializeField]
|
||||
private ParallaxType m_selectedParallaxType = ParallaxType.Normal;
|
||||
|
||||
private readonly string[] m_parallaxTypeStr = { "Normal", "Planar" };
|
||||
|
||||
private int m_cachedPropertyId = -1;
|
||||
|
||||
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT2, false, "UV" );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Height" );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Scale" );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "ViewDir (tan)" );
|
||||
AddOutputPort( WirePortDataType.FLOAT2, "Out" );
|
||||
m_useInternalPortData = true;
|
||||
m_autoDrawInternalPortData = true;
|
||||
m_autoWrapProperties = true;
|
||||
m_textLabelWidth = 105;
|
||||
UpdateTitle();
|
||||
m_forceDrawPreviewAsPlane = true;
|
||||
m_hasLeftDropdown = true;
|
||||
m_previewShaderGUID = "589f12f68e00ac74286815aa56053fcc";
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
m_upperLeftWidget = null;
|
||||
}
|
||||
|
||||
public override void SetPreviewInputs()
|
||||
{
|
||||
base.SetPreviewInputs();
|
||||
|
||||
if( m_cachedPropertyId == -1 )
|
||||
m_cachedPropertyId = Shader.PropertyToID( "_ParallaxType" );
|
||||
|
||||
PreviewMaterial.SetFloat( m_cachedPropertyId, ( m_selectedParallaxType == ParallaxType.Normal ? 0 : 1 ) );
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
|
||||
string textcoords = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string height = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
|
||||
string scale = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
|
||||
string viewDirTan = m_inputPorts[ 3 ].GeneratePortInstructions( ref dataCollector );
|
||||
string localVarName = "Offset" + OutputId;
|
||||
string calculation = "";
|
||||
|
||||
switch( m_selectedParallaxType )
|
||||
{
|
||||
default:
|
||||
case ParallaxType.Normal:
|
||||
calculation = "( ( " + height + " - 1 ) * " + viewDirTan + ".xy * " + scale + " ) + " + textcoords;
|
||||
break;
|
||||
case ParallaxType.Planar:
|
||||
calculation = "( ( " + height + " - 1 ) * ( " + viewDirTan + ".xy / " + viewDirTan + ".z ) * " + scale + " ) + " + textcoords;
|
||||
break;
|
||||
}
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, m_outputPorts[ 0 ].DataType, localVarName, calculation );
|
||||
//dataCollector.AddToLocalVariables( UniqueId, m_currentPrecisionType, m_outputPorts[ 0 ].DataType, localVarName, calculation );
|
||||
return GetOutputVectorItem( 0, outputId, localVarName );
|
||||
}
|
||||
|
||||
public override void Draw( DrawInfo drawInfo )
|
||||
{
|
||||
base.Draw( drawInfo );
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_selectedParallaxTypeInt = m_upperLeftWidget.DrawWidget( this, m_selectedParallaxTypeInt, m_parallaxTypeStr );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
switch( m_selectedParallaxTypeInt )
|
||||
{
|
||||
default:
|
||||
case 0: m_selectedParallaxType = ParallaxType.Normal; break;
|
||||
case 1: m_selectedParallaxType = ParallaxType.Planar; break;
|
||||
}
|
||||
UpdateTitle();
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_selectedParallaxTypeInt = EditorGUILayoutPopup( "Parallax Type", m_selectedParallaxTypeInt, m_parallaxTypeStr );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
switch( m_selectedParallaxTypeInt )
|
||||
{
|
||||
default:
|
||||
case 0: m_selectedParallaxType = ParallaxType.Normal; break;
|
||||
case 1: m_selectedParallaxType = ParallaxType.Planar; break;
|
||||
}
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox( "Normal type does a cheaper approximation thats view dependent while Planar is more accurate but generates higher aliasing artifacts at steep angles.", MessageType.None );
|
||||
}
|
||||
|
||||
|
||||
void UpdateTitle()
|
||||
{
|
||||
m_additionalContent.text = string.Format( Constants.SubTitleTypeFormatStr, m_parallaxTypeStr[ m_selectedParallaxTypeInt ] );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
m_selectedParallaxType = (ParallaxType)Enum.Parse( typeof( ParallaxType ), GetCurrentParam( ref nodeParams ) );
|
||||
switch( m_selectedParallaxType )
|
||||
{
|
||||
default:
|
||||
case ParallaxType.Normal: m_selectedParallaxTypeInt = 0; break;
|
||||
case ParallaxType.Planar: m_selectedParallaxTypeInt = 1; break;
|
||||
}
|
||||
UpdateTitle();
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedParallaxType );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96d8f50a7481d5247b16cb16c053d5f6
|
||||
timeCreated: 1481126957
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,650 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
enum POMTexTypes
|
||||
{
|
||||
Texture2D,
|
||||
Texture3D,
|
||||
TextureArray
|
||||
};
|
||||
|
||||
[Serializable]
|
||||
[NodeAttributes( "Parallax Occlusion Mapping", "UV Coordinates", "Calculates offseted UVs for parallax occlusion mapping" )]
|
||||
public sealed class ParallaxOcclusionMappingNode : ParentNode
|
||||
{
|
||||
private const string ArrayIndexStr = "Array Index";
|
||||
private const string Tex3DSliceStr = "Tex3D Slice";
|
||||
|
||||
private readonly string[] m_channelTypeStr = { "Red Channel", "Green Channel", "Blue Channel", "Alpha Channel" };
|
||||
private readonly string[] m_channelTypeVal = { "r", "g", "b", "a" };
|
||||
|
||||
[SerializeField]
|
||||
private int m_selectedChannelInt = 0;
|
||||
|
||||
//[SerializeField]
|
||||
//private int m_minSamples = 8;
|
||||
|
||||
//[SerializeField]
|
||||
//private int m_maxSamples = 16;
|
||||
[SerializeField]
|
||||
private InlineProperty m_inlineMinSamples = new InlineProperty( 8 );
|
||||
|
||||
[SerializeField]
|
||||
private InlineProperty m_inlineMaxSamples = new InlineProperty( 16 );
|
||||
|
||||
[ SerializeField]
|
||||
private int m_sidewallSteps = 2;
|
||||
|
||||
[SerializeField]
|
||||
private float m_defaultScale = 0.02f;
|
||||
|
||||
[SerializeField]
|
||||
private float m_defaultRefPlane = 0f;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_clipEnds = false;
|
||||
|
||||
[SerializeField]
|
||||
private Vector2 m_tilling = new Vector2( 1, 1 );
|
||||
|
||||
[SerializeField]
|
||||
private bool m_useCurvature = false;
|
||||
|
||||
[SerializeField]
|
||||
private Vector2 m_CurvatureVector = new Vector2( 0, 0 );
|
||||
|
||||
private string m_functionHeader = "POM( {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13} )";
|
||||
private string m_functionBody = string.Empty;
|
||||
|
||||
//private const string WorldDirVarStr = "worldViewDir";
|
||||
|
||||
private InputPort m_uvPort;
|
||||
private InputPort m_texPort;
|
||||
private InputPort m_ssPort;
|
||||
private InputPort m_scalePort;
|
||||
private InputPort m_viewdirTanPort;
|
||||
private InputPort m_refPlanePort;
|
||||
private InputPort m_curvaturePort;
|
||||
private InputPort m_arrayIndexPort;
|
||||
|
||||
private OutputPort m_pomUVPort;
|
||||
|
||||
private Vector4Node m_texCoordsHelper;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT2, false, "UV",-1,MasterNodePortCategory.Fragment,0);
|
||||
AddInputPort( WirePortDataType.SAMPLER2D, false, "Tex", -1, MasterNodePortCategory.Fragment, 1 );
|
||||
AddInputPort( WirePortDataType.SAMPLERSTATE, false, "SS", -1, MasterNodePortCategory.Fragment, 7 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Scale", -1, MasterNodePortCategory.Fragment, 2 );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "ViewDir (tan)", -1, MasterNodePortCategory.Fragment, 3 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Ref Plane", -1, MasterNodePortCategory.Fragment, 4 );
|
||||
AddInputPort( WirePortDataType.FLOAT2, false, "Curvature", -1, MasterNodePortCategory.Fragment, 5 );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, ArrayIndexStr, -1, MasterNodePortCategory.Fragment, 6 );
|
||||
|
||||
AddOutputPort( WirePortDataType.FLOAT2, "Out" );
|
||||
|
||||
m_uvPort = GetInputPortByUniqueId( 0 );
|
||||
m_texPort = GetInputPortByUniqueId( 1 );
|
||||
m_texPort.CreatePortRestrictions( WirePortDataType.SAMPLER2D, WirePortDataType.SAMPLER3D, WirePortDataType.SAMPLER2DARRAY );
|
||||
m_ssPort = GetInputPortByUniqueId( 7 );
|
||||
m_ssPort.CreatePortRestrictions( WirePortDataType.SAMPLERSTATE );
|
||||
m_scalePort = GetInputPortByUniqueId( 2 );
|
||||
m_viewdirTanPort = GetInputPortByUniqueId( 3 );
|
||||
m_refPlanePort = GetInputPortByUniqueId( 4 );
|
||||
m_pomUVPort = m_outputPorts[ 0 ];
|
||||
m_curvaturePort = GetInputPortByUniqueId( 5 );
|
||||
m_arrayIndexPort = GetInputPortByUniqueId( 6 );
|
||||
|
||||
m_scalePort.FloatInternalData = 0.02f;
|
||||
m_useInternalPortData = false;
|
||||
m_textLabelWidth = 130;
|
||||
m_autoWrapProperties = true;
|
||||
m_curvaturePort.Visible = false;
|
||||
m_arrayIndexPort.Visible = false;
|
||||
UpdateSampler();
|
||||
}
|
||||
|
||||
public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
|
||||
{
|
||||
base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
|
||||
m_texPort.MatchPortToConnection();
|
||||
UpdateIndexPort();
|
||||
}
|
||||
|
||||
public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
|
||||
{
|
||||
base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
|
||||
if( !m_texPort.CheckValidType( type ) )
|
||||
{
|
||||
m_texPort.FullDeleteConnections();
|
||||
UIUtils.ShowMessage( UniqueId, "Parallax Occlusion Mapping node only accepts SAMPLER2D, SAMPLER3D and SAMPLER2DARRAY input types.\nTexture Object connected changed to "+ type + ", connection was lost, please review and update accordingly.", MessageSeverity.Warning );
|
||||
} else
|
||||
{
|
||||
m_texPort.MatchPortToConnection();
|
||||
}
|
||||
UpdateIndexPort();
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_selectedChannelInt = EditorGUILayoutPopup( "Channel", m_selectedChannelInt, m_channelTypeStr );
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
UpdateSampler();
|
||||
}
|
||||
//EditorGUIUtility.labelWidth = 105;
|
||||
|
||||
//m_minSamples = EditorGUILayoutIntSlider( "Min Samples", m_minSamples, 1, 128 );
|
||||
UndoParentNode inst = this;
|
||||
m_inlineMinSamples.CustomDrawer( ref inst, ( x ) => { m_inlineMinSamples.IntValue = EditorGUILayoutIntSlider( "Min Samples", m_inlineMinSamples.IntValue, 1, 128 ); }, "Min Samples" );
|
||||
//m_maxSamples = EditorGUILayoutIntSlider( "Max Samples", m_maxSamples, 1, 128 );
|
||||
m_inlineMaxSamples.CustomDrawer( ref inst, ( x ) => { m_inlineMaxSamples.IntValue = EditorGUILayoutIntSlider( "Max Samples", m_inlineMaxSamples.IntValue, 1, 128 ); }, "Max Samples" );
|
||||
|
||||
m_sidewallSteps = EditorGUILayoutIntSlider( "Sidewall Steps", m_sidewallSteps, 0, 10 );
|
||||
|
||||
EditorGUI.BeginDisabledGroup(m_scalePort.IsConnected );
|
||||
m_defaultScale = EditorGUILayoutSlider( "Default Scale", m_defaultScale, 0, 1 );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUI.BeginDisabledGroup( m_refPlanePort.IsConnected );
|
||||
m_defaultRefPlane = EditorGUILayoutSlider( "Default Ref Plane", m_defaultRefPlane, 0, 1 );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
//EditorGUIUtility.labelWidth = m_textLabelWidth;
|
||||
|
||||
if( m_arrayIndexPort.Visible && !m_arrayIndexPort.IsConnected )
|
||||
{
|
||||
m_arrayIndexPort.FloatInternalData = EditorGUILayoutFloatField( "Array Index", m_arrayIndexPort.FloatInternalData );
|
||||
}
|
||||
|
||||
//float cached = EditorGUIUtility.labelWidth;
|
||||
//EditorGUIUtility.labelWidth = 70;
|
||||
m_clipEnds = EditorGUILayoutToggle( "Clip Edges", m_clipEnds );
|
||||
//EditorGUIUtility.labelWidth = -1;
|
||||
//EditorGUIUtility.labelWidth = 100;
|
||||
//EditorGUILayout.BeginHorizontal();
|
||||
//EditorGUI.BeginDisabledGroup( !m_clipEnds );
|
||||
//m_tilling = EditorGUILayout.Vector2Field( string.Empty, m_tilling );
|
||||
//EditorGUI.EndDisabledGroup();
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
//EditorGUIUtility.labelWidth = cached;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_useCurvature = EditorGUILayoutToggle( "Clip Silhouette", m_useCurvature );
|
||||
if ( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
UpdateCurvaturePort();
|
||||
}
|
||||
|
||||
EditorGUI.BeginDisabledGroup( !(m_useCurvature && !m_curvaturePort.IsConnected) );
|
||||
m_CurvatureVector = EditorGUILayoutVector2Field( string.Empty, m_CurvatureVector );
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.HelpBox( "WARNING:\nTex must be connected to a Texture Object for this node to work\n\nMin and Max samples:\nControl the minimum and maximum number of layers extruded\n\nSidewall Steps:\nThe number of interpolations done to smooth the extrusion result on the side of the layer extrusions, min is used at steep angles while max is used at orthogonal angles\n\n"+
|
||||
"Ref Plane:\nReference plane lets you adjust the starting reference height, 0 = deepen ground, 1 = raise ground, any value above 0 might cause distortions at higher angles\n\n"+
|
||||
"Clip Edges:\nThis will clip the ends of your uvs to give a more 3D look at the edges. It'll use the tilling given by your Heightmap input.\n\n"+
|
||||
"Clip Silhouette:\nTurning this on allows you to use the UV coordinates to clip the effect curvature in U or V axis, useful for cylinders, works best with 'Clip Edges' turned OFF", MessageType.None );
|
||||
}
|
||||
|
||||
private void UpdateIndexPort()
|
||||
{
|
||||
m_arrayIndexPort.Visible = m_texPort.DataType != WirePortDataType.SAMPLER2D;
|
||||
if( m_arrayIndexPort.Visible )
|
||||
{
|
||||
m_arrayIndexPort.Name = m_texPort.DataType == WirePortDataType.SAMPLER3D ? Tex3DSliceStr : ArrayIndexStr;
|
||||
}
|
||||
SizeIsDirty = true;
|
||||
}
|
||||
|
||||
private void UpdateSampler()
|
||||
{
|
||||
m_texPort.Name = "Tex (" + m_channelTypeVal[ m_selectedChannelInt ].ToUpper() + ")";
|
||||
}
|
||||
|
||||
private void UpdateCurvaturePort()
|
||||
{
|
||||
if ( m_useCurvature )
|
||||
m_curvaturePort.Visible = true;
|
||||
else
|
||||
m_curvaturePort.Visible = false;
|
||||
|
||||
m_sizeIsDirty = true;
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( !m_texPort.IsConnected )
|
||||
{
|
||||
UIUtils.ShowMessage( UniqueId, "Parallax Occlusion Mapping node only works if a Texture Object is connected to its Tex (R) port" );
|
||||
return "0";
|
||||
}
|
||||
base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
|
||||
ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
|
||||
|
||||
string arrayIndex = m_arrayIndexPort.Visible?m_arrayIndexPort.GeneratePortInstructions( ref dataCollector ):"0";
|
||||
string textcoords = m_uvPort.GeneratePortInstructions( ref dataCollector );
|
||||
if( m_texPort.DataType == WirePortDataType.SAMPLER3D )
|
||||
{
|
||||
string texName = "pomTexCoord" + OutputId;
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, texName, string.Format( "float3({0},{1})", textcoords, arrayIndex ) );
|
||||
textcoords = texName;
|
||||
}
|
||||
|
||||
string texture = m_texPort.GeneratePortInstructions( ref dataCollector );
|
||||
GeneratePOMfunction( ref dataCollector );
|
||||
string scale = m_defaultScale.ToString();
|
||||
if( m_scalePort.IsConnected )
|
||||
scale = m_scalePort.GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
string viewDirTan = "";
|
||||
if ( !m_viewdirTanPort.IsConnected )
|
||||
{
|
||||
if ( !dataCollector.DirtyNormal )
|
||||
dataCollector.ForceNormal = true;
|
||||
|
||||
|
||||
if ( dataCollector.IsTemplate )
|
||||
{
|
||||
viewDirTan = dataCollector.TemplateDataCollectorInstance.GetTangentViewDir( CurrentPrecisionType );
|
||||
}
|
||||
else
|
||||
{
|
||||
viewDirTan = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.Tangent );
|
||||
//dataCollector.AddToInput( UniqueId, SurfaceInputs.VIEW_DIR, m_currentPrecisionType );
|
||||
//viewDirTan = Constants.InputVarStr + "." + UIUtils.GetInputValueFromType( SurfaceInputs.VIEW_DIR );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
viewDirTan = m_viewdirTanPort.GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
|
||||
//generate world normal
|
||||
string normalWorld = string.Empty;
|
||||
if ( dataCollector.IsTemplate )
|
||||
{
|
||||
normalWorld = dataCollector.TemplateDataCollectorInstance.GetWorldNormal( CurrentPrecisionType );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType );
|
||||
dataCollector.AddToInput( UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false );
|
||||
normalWorld = GeneratorUtils.GenerateWorldNormal( ref dataCollector, UniqueId );
|
||||
}
|
||||
|
||||
string worldViewDir = GeneratorUtils.GenerateViewDirection( ref dataCollector, UniqueId, ViewSpace.World );
|
||||
|
||||
string dx = "ddx("+ textcoords + ")";
|
||||
string dy = "ddy(" + textcoords + ")";
|
||||
|
||||
string refPlane = m_defaultRefPlane.ToString();
|
||||
if ( m_refPlanePort.IsConnected )
|
||||
refPlane = m_refPlanePort.GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
|
||||
string curvature = "float2("+ m_CurvatureVector.x + "," + m_CurvatureVector.y + ")";
|
||||
if ( m_useCurvature )
|
||||
{
|
||||
dataCollector.AddToProperties( UniqueId, "[Header(Parallax Occlusion Mapping)]", 300 );
|
||||
dataCollector.AddToProperties( UniqueId, "_CurvFix(\"Curvature Bias\", Range( 0 , 1)) = 1", 301 );
|
||||
dataCollector.AddToUniforms( UniqueId, "uniform float _CurvFix;" );
|
||||
|
||||
if ( m_curvaturePort.IsConnected )
|
||||
curvature = m_curvaturePort.GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
|
||||
|
||||
string localVarName = "OffsetPOM" + OutputId;
|
||||
string textCoordsST = string.Empty;
|
||||
//string textureSTType = dataCollector.IsSRP ? "float4 " : "uniform float4 ";
|
||||
//dataCollector.AddToUniforms( UniqueId, textureSTType + texture +"_ST;");
|
||||
if( m_texCoordsHelper == null )
|
||||
{
|
||||
m_texCoordsHelper = CreateInstance<Vector4Node>();
|
||||
m_texCoordsHelper.ContainerGraph = ContainerGraph;
|
||||
m_texCoordsHelper.SetBaseUniqueId( UniqueId, true );
|
||||
m_texCoordsHelper.RegisterPropertyOnInstancing = false;
|
||||
m_texCoordsHelper.AddGlobalToSRPBatcher = true;
|
||||
}
|
||||
|
||||
if( outsideGraph.IsInstancedShader )
|
||||
{
|
||||
m_texCoordsHelper.CurrentParameterType = PropertyType.InstancedProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_texCoordsHelper.CurrentParameterType = PropertyType.Global;
|
||||
}
|
||||
m_texCoordsHelper.ResetOutputLocals();
|
||||
m_texCoordsHelper.SetRawPropertyName( texture + "_ST" );
|
||||
textCoordsST = m_texCoordsHelper.GenerateShaderForOutput( 0, ref dataCollector, false );
|
||||
//////
|
||||
|
||||
string textureArgs = string.Empty;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
if( outsideGraph.SamplingMacros || m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY )
|
||||
#else
|
||||
if( ( outsideGraph.SamplingMacros && !outsideGraph.IsStandardSurface ) || m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY )
|
||||
#endif
|
||||
{
|
||||
string sampler = string.Empty;
|
||||
if( m_ssPort.IsConnected )
|
||||
{
|
||||
sampler = m_ssPort.GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
sampler = GeneratorUtils.GenerateSamplerState( ref dataCollector, UniqueId, texture );
|
||||
}
|
||||
if( outsideGraph.IsSRP )
|
||||
{
|
||||
textureArgs = texture + ", " + sampler;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !UNITY_2018_1_OR_NEWER
|
||||
if( outsideGraph.IsStandardSurface )
|
||||
textureArgs = "UNITY_PASS_TEX2DARRAY(" + texture + ")";
|
||||
else
|
||||
#endif
|
||||
textureArgs = texture + ", " + sampler;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
textureArgs = texture;
|
||||
}
|
||||
//string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, ( (m_pomTexType == POMTexTypes.TextureArray) ? "UNITY_PASS_TEX2DARRAY(" + texture + ")": texture), textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_minSamples, m_maxSamples, scale, refPlane, texture+"_ST.xy", curvature, arrayIndex );
|
||||
string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, textureArgs, textcoords, dx, dy, normalWorld, worldViewDir, viewDirTan, m_inlineMinSamples.GetValueOrProperty(false), m_inlineMinSamples.GetValueOrProperty(false), scale, refPlane, textCoordsST + ".xy", curvature, arrayIndex );
|
||||
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, m_pomUVPort.DataType, localVarName, functionResult );
|
||||
|
||||
return GetOutputVectorItem( 0, outputId, localVarName );
|
||||
}
|
||||
|
||||
private void GeneratePOMfunction( ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
ParentGraph outsideGraph = UIUtils.CurrentWindow.OutsideGraph;
|
||||
m_functionBody = string.Empty;
|
||||
switch( m_texPort.DataType )
|
||||
{
|
||||
default:
|
||||
case WirePortDataType.SAMPLER2D:
|
||||
{
|
||||
string sampleParam = string.Empty;
|
||||
sampleParam = GeneratorUtils.GetPropertyDeclaraction( "heightMap", TextureType.Texture2D, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplerheightMap", TextureType.Texture2D, ", " );
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, string.Format("inline float2 POM( {0}float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )", sampleParam ));
|
||||
}
|
||||
break;
|
||||
case WirePortDataType.SAMPLER3D:
|
||||
{
|
||||
string sampleParam = string.Empty;
|
||||
sampleParam = GeneratorUtils.GetPropertyDeclaraction( "heightMap", TextureType.Texture3D, ", " ) + GeneratorUtils.GetSamplerDeclaraction( "samplerheightMap", TextureType.Texture3D, ", " );
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, string.Format("inline float2 POM( {0}float3 uvs, float3 dx, float3 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )", sampleParam ) );
|
||||
}
|
||||
break;
|
||||
case WirePortDataType.SAMPLER2DARRAY:
|
||||
if( outsideGraph.IsSRP )
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( TEXTURE2D_ARRAY(heightMap), SAMPLER(samplerheightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" );
|
||||
else
|
||||
#if !UNITY_2018_1_OR_NEWER
|
||||
if( outsideGraph.IsStandardSurface )
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( UNITY_ARGS_TEX2DARRAY(heightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" );
|
||||
else
|
||||
#endif
|
||||
IOUtils.AddFunctionHeader( ref m_functionBody, "inline float2 POM( UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(heightMap), SamplerState samplerheightMap, float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )" );
|
||||
break;
|
||||
}
|
||||
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float3 result = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int stepIndex = 0;" );
|
||||
//IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )( minSamples + dot( viewWorld, normalWorld ) * ( maxSamples - minSamples ) );" );
|
||||
//IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( maxSamples, minSamples, length( fwidth( uvs ) ) * 10 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( (float)maxSamples, (float)minSamples, saturate( dot( normalWorld, viewWorld ) ) );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float layerHeight = 1.0 / numSteps;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float2 plane = parallax * ( viewDirTan.xy / viewDirTan.z );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "uvs.xy += refPlane * plane;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float2 deltaTex = -plane * layerHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float2 prevTexOffset = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float prevRayZ = 1.0f;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float prevHeight = 0.0f;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float2 currTexOffset = deltaTex;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float currRayZ = 1.0f - layerHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float currHeight = 0.0f;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float intersection = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float2 finalTexOffset = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "while ( stepIndex < numSteps + 1 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "{" );
|
||||
|
||||
string textureProp = "heightMap";
|
||||
string sampleState = "samplerheightMap";
|
||||
|
||||
string uvs = "uvs + currTexOffset";
|
||||
if( m_texPort.DataType == WirePortDataType.SAMPLER3D )
|
||||
uvs = "float3(uvs.xy + currTexOffset, uvs.z)";
|
||||
else if( m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY )
|
||||
uvs = outsideGraph.IsSRP ? uvs + ", index" : "float3(" + uvs + ", index)";
|
||||
|
||||
string samplingCall = GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_texPort.DataType, textureProp, sampleState, uvs, MipType.Derivative, "dx", "dy" );
|
||||
if( m_useCurvature )
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tresult.z = dot( curv, currTexOffset * currTexOffset );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tcurrHeight = " + samplingCall + "." + m_channelTypeVal[ m_selectedChannelInt ] + " * ( 1 - result.z );" );
|
||||
}
|
||||
else
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tcurrHeight = " + samplingCall + "." + m_channelTypeVal[ m_selectedChannelInt ] + ";" );
|
||||
}
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( currHeight > currRayZ )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tstepIndex = numSteps + 1;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \telse" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tstepIndex++;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevTexOffset = currTexOffset;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevRayZ = currRayZ;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevHeight = currHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrTexOffset += deltaTex;" );
|
||||
if ( m_useCurvature )
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrRayZ -= layerHeight * ( 1 - result.z ) * (1+_CurvFix);" );
|
||||
else
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrRayZ -= layerHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "}" );
|
||||
|
||||
if ( m_sidewallSteps > 0 )
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int sectionSteps = " + m_sidewallSteps + ";" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "int sectionIndex = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float newZ = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "float newHeight = 0;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "while ( sectionIndex < sectionSteps )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tintersection = ( prevHeight - prevRayZ ) / ( prevHeight - currHeight + currRayZ - prevRayZ );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tfinalTexOffset = prevTexOffset + intersection * deltaTex;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tnewZ = prevRayZ - intersection * layerHeight;" );
|
||||
|
||||
string uvs2 = "uvs + finalTexOffset";
|
||||
if( m_texPort.DataType == WirePortDataType.SAMPLER3D )
|
||||
uvs2 = "float3(uvs.xy + finalTexOffset, uvs.z)";
|
||||
else if( m_texPort.DataType == WirePortDataType.SAMPLER2DARRAY )
|
||||
uvs2 = outsideGraph.IsSRP ? uvs2 + ", index" : "float3(" + uvs2 + ", index)";
|
||||
|
||||
string samplingCall2 = GeneratorUtils.GenerateSamplingCall( ref dataCollector, m_texPort.DataType, textureProp, sampleState, uvs2, MipType.Derivative, "dx", "dy" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tnewHeight = " + samplingCall2 + "." + m_channelTypeVal[ m_selectedChannelInt ] + ";" );
|
||||
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( newHeight > newZ )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrTexOffset = finalTexOffset;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrHeight = newHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tcurrRayZ = newZ;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tdeltaTex = intersection * deltaTex;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tlayerHeight = intersection * layerHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \telse" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevTexOffset = finalTexOffset;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevHeight = newHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tprevRayZ = newZ;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tdeltaTex = ( 1 - intersection ) * deltaTex;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tlayerHeight = ( 1 - intersection ) * layerHeight;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tsectionIndex++;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "}" );
|
||||
}
|
||||
else
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "finalTexOffset = currTexOffset;" );
|
||||
}
|
||||
|
||||
if ( m_useCurvature )
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#endif" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( result.z > 1 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tclip( -1 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#endif" );
|
||||
}
|
||||
|
||||
if ( m_clipEnds )
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "result.xy = uvs.xy + finalTexOffset;" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "{" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#endif" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( result.x < 0 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tclip( -1 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( result.x > tilling.x )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tclip( -1 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( result.y < 0 )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tclip( -1 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \tif ( result.y > tilling.y )" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, " \t \tclip( -1 );" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "}" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "#endif" );
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "return result.xy;" );
|
||||
}
|
||||
else
|
||||
{
|
||||
IOUtils.AddFunctionLine( ref m_functionBody, "return uvs.xy + finalTexOffset;" );
|
||||
}
|
||||
IOUtils.CloseFunctionBody( ref m_functionBody );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
m_selectedChannelInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
//m_minSamples = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
//m_maxSamples = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
if( UIUtils.CurrentShaderVersion() < 15406 )
|
||||
{
|
||||
m_inlineMinSamples.IntValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
m_inlineMaxSamples.IntValue = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_inlineMinSamples.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
|
||||
m_inlineMaxSamples.ReadFromString( ref m_currentReadParamIdx, ref nodeParams );
|
||||
}
|
||||
m_sidewallSteps = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
m_defaultScale = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
|
||||
m_defaultRefPlane = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
|
||||
if ( UIUtils.CurrentShaderVersion() > 3001 )
|
||||
{
|
||||
m_clipEnds = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
string[] vector2Component = GetCurrentParam( ref nodeParams ).Split( IOUtils.VECTOR_SEPARATOR );
|
||||
if ( vector2Component.Length == 2 )
|
||||
{
|
||||
m_tilling.x = Convert.ToSingle( vector2Component[ 0 ] );
|
||||
m_tilling.y = Convert.ToSingle( vector2Component[ 1 ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( UIUtils.CurrentShaderVersion() > 5005 )
|
||||
{
|
||||
m_useCurvature = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
m_CurvatureVector = IOUtils.StringToVector2( GetCurrentParam( ref nodeParams ) );
|
||||
}
|
||||
|
||||
if( UIUtils.CurrentShaderVersion() > 13103 )
|
||||
{
|
||||
//if( UIUtils.CurrentShaderVersion() < 15307 )
|
||||
//{
|
||||
// GetCurrentParam( ref nodeParams );
|
||||
// //bool arrayIndexVisible = false;
|
||||
// //arrayIndexVisible = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
||||
// //m_pomTexType = arrayIndexVisible ? POMTexTypes.TextureArray : POMTexTypes.Texture2D;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// GetCurrentParam( ref nodeParams );
|
||||
// //m_pomTexType = (POMTexTypes)Enum.Parse( typeof(POMTexTypes), GetCurrentParam( ref nodeParams ) );
|
||||
//}
|
||||
if( UIUtils.CurrentShaderVersion() <= 18201 )
|
||||
{
|
||||
GetCurrentParam( ref nodeParams );
|
||||
}
|
||||
UpdateIndexPort();
|
||||
}
|
||||
|
||||
UpdateSampler();
|
||||
//GeneratePOMfunction( string.Empty );
|
||||
UpdateCurvaturePort();
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedChannelInt );
|
||||
//IOUtils.AddFieldValueToString( ref nodeInfo, m_minSamples );
|
||||
//IOUtils.AddFieldValueToString( ref nodeInfo, m_maxSamples );
|
||||
m_inlineMinSamples.WriteToString( ref nodeInfo );
|
||||
m_inlineMaxSamples.WriteToString( ref nodeInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_sidewallSteps );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultScale );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_defaultRefPlane );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_clipEnds );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_tilling.x.ToString() + IOUtils.VECTOR_SEPARATOR + m_tilling.y.ToString() );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_useCurvature );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, IOUtils.Vector2ToString( m_CurvatureVector ) );
|
||||
//IOUtils.AddFieldValueToString( ref nodeInfo, m_useTextureArray );
|
||||
//IOUtils.AddFieldValueToString( ref nodeInfo, true );
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
//Not calling m_texCoordsHelper.Destroy() on purpose so UIUtils does not incorrectly unregister stuff
|
||||
if( m_texCoordsHelper != null )
|
||||
{
|
||||
DestroyImmediate( m_texCoordsHelper );
|
||||
m_texCoordsHelper = null;
|
||||
}
|
||||
|
||||
|
||||
m_uvPort = null;
|
||||
m_texPort = null;
|
||||
m_scalePort = null;
|
||||
m_viewdirTanPort = null;
|
||||
m_pomUVPort = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2350150f3f2a0443827ca8925d5e759
|
||||
timeCreated: 1481126958
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Parallax Offset", "UV Coordinates", "Calculates UV offset for parallax normal mapping" )]
|
||||
public sealed class ParallaxOffsetHlpNode : HelperParentNode
|
||||
{
|
||||
public readonly string[] ParallaxOffsetFunc =
|
||||
{
|
||||
"inline float2 ParallaxOffset( half h, half height, half3 viewDir )\n",
|
||||
"{\n",
|
||||
"\th = h * height - height/2.0;\n",
|
||||
"\tfloat3 v = normalize( viewDir );\n",
|
||||
"\tv.z += 0.42;\n",
|
||||
"\treturn h* (v.xy / v.z);\n",
|
||||
"}\n"
|
||||
};
|
||||
|
||||
void OnSRPActionEvent( int outputId, ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
dataCollector.AddFunction( ParallaxOffsetFunc[ 0 ], ParallaxOffsetFunc, false );
|
||||
}
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "ParallaxOffset";
|
||||
m_inputPorts[ 0 ].ChangeProperties( "H", WirePortDataType.FLOAT, false );
|
||||
AddInputPort( WirePortDataType.FLOAT, false, "Height" );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "ViewDir (tan)" );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT2, false );
|
||||
m_outputPorts[ 0 ].Name = "Out";
|
||||
OnHDAction = OnSRPActionEvent;
|
||||
OnLightweightAction = OnSRPActionEvent;
|
||||
m_previewShaderGUID = "6085f804c6fbf354eac039c11feaa7cc";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "paralaxOffset" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83b7d6fe57585b74d80c429aef719200
|
||||
timeCreated: 1481126957
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,105 @@
|
||||
// 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( "Shade Vertex Lights", "Light", "Computes illumination from four per-vertex lights and ambient, given object space position & normal" )]
|
||||
public sealed class ShadeVertexLightsHlpNode : ParentNode
|
||||
{
|
||||
private const string HelperMessage = "Shade Vertex Lights node only outputs correct results on\nTemplate Vertex/Frag shaders with their LightMode set to Vertex.";
|
||||
private const string ShadeVertexLightFunc = "ShadeVertexLightsFull({0},{1},{2},{3})";
|
||||
private const string LightCount = "Light Count";
|
||||
private const string IsSpotlight = "Is Spotlight";
|
||||
private const int MinLightCount = 0;
|
||||
private const int MaxLightCount = 8;
|
||||
[SerializeField]
|
||||
private int m_lightCount = 4;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_enableSpotlight = false;
|
||||
|
||||
private int _LightCountId;
|
||||
private int _IsSpotlightId;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT4, false, "Vertex Position" );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Vertex Normal" );
|
||||
AddOutputPort( WirePortDataType.FLOAT3, Constants.EmptyPortValue );
|
||||
m_useInternalPortData = true;
|
||||
//m_autoWrapProperties = true;
|
||||
m_textLabelWidth = 90;
|
||||
m_previewShaderGUID = "3b6075034a85ad047be2d31dd213fb4f";
|
||||
}
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
_LightCountId = Shader.PropertyToID( "_LightCount" );
|
||||
_IsSpotlightId = Shader.PropertyToID( "_IsSpotlight" );
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, DrawGeneralProperties );
|
||||
EditorGUILayout.HelpBox( HelperMessage, MessageType.Info );
|
||||
}
|
||||
|
||||
public override void SetPreviewInputs()
|
||||
{
|
||||
base.SetPreviewInputs();
|
||||
PreviewMaterial.SetInt( _LightCountId, m_lightCount );
|
||||
PreviewMaterial.SetInt( _IsSpotlightId, ( m_enableSpotlight ? 1 : 0 ) );
|
||||
|
||||
}
|
||||
|
||||
void DrawGeneralProperties()
|
||||
{
|
||||
m_lightCount = EditorGUILayoutIntSlider( LightCount, m_lightCount, MinLightCount, MaxLightCount );
|
||||
m_enableSpotlight = EditorGUILayoutToggle( IsSpotlight, m_enableSpotlight );
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.MasterNodeCategory == AvailableShaderTypes.SurfaceShader )
|
||||
UIUtils.ShowMessage( UniqueId, HelperMessage, MessageSeverity.Warning );
|
||||
|
||||
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
|
||||
string vertexPosition = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
string vertexNormal = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
|
||||
|
||||
string value = string.Format( ShadeVertexLightFunc, vertexPosition, vertexNormal, m_lightCount, m_enableSpotlight.ToString().ToLower() );
|
||||
|
||||
RegisterLocalVariable( 0, value, ref dataCollector, "shadeVertexLight" + OutputId );
|
||||
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() > 14301 )
|
||||
{
|
||||
m_lightCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
m_enableSpotlight = 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_lightCount );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_enableSpotlight );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74f44334b702bce4ba8e2681dc80fe3c
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,184 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Surface Depth", "Surface Data", "Returns the surface view depth" )]
|
||||
public sealed class SurfaceDepthNode : ParentNode
|
||||
{
|
||||
[SerializeField]
|
||||
private int m_viewSpaceInt = 0;
|
||||
|
||||
private readonly string[] m_viewSpaceStr = { "Eye Space", "0-1 Space" };
|
||||
private readonly string[] m_vertexNameStr = { "eyeDepth", "clampDepth" };
|
||||
|
||||
private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
AddInputPort( WirePortDataType.FLOAT3, false, "Vertex Position" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Depth" );
|
||||
m_autoWrapProperties = true;
|
||||
m_hasLeftDropdown = true;
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, m_viewSpaceStr[ m_viewSpaceInt ] ) );
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
m_upperLeftWidget = null;
|
||||
}
|
||||
|
||||
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 Draw( DrawInfo drawInfo )
|
||||
{
|
||||
base.Draw( drawInfo );
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_viewSpaceInt = m_upperLeftWidget.DrawWidget( this, m_viewSpaceInt, m_viewSpaceStr );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, m_viewSpaceStr[ m_viewSpaceInt ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_viewSpaceInt = EditorGUILayoutPopup( "View Space", m_viewSpaceInt, m_viewSpaceStr );
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, m_viewSpaceStr[ m_viewSpaceInt ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsTemplate )
|
||||
{
|
||||
if( m_inputPorts[ 0 ].IsConnected )
|
||||
{
|
||||
string space = string.Empty;
|
||||
if( m_viewSpaceInt == 1 )
|
||||
space = " * _ProjectionParams.w";
|
||||
|
||||
string varName = "customSurfaceDepth" + OutputId;
|
||||
GenerateInputInVertex( ref dataCollector, 0, varName, false );
|
||||
string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space;
|
||||
if( dataCollector.IsSRP )
|
||||
instruction = "-TransformWorldToView(TransformObjectToWorld( " + varName + " )).z" + space;
|
||||
string eyeVarName = "customEye" + OutputId;
|
||||
dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( eyeVarName, WirePortDataType.FLOAT, CurrentPrecisionType, instruction );
|
||||
return eyeVarName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataCollector.TemplateDataCollectorInstance.GetEyeDepth( CurrentPrecisionType, true, MasterNodePortCategory.Fragment, m_viewSpaceInt );
|
||||
}
|
||||
}
|
||||
|
||||
if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation )
|
||||
{
|
||||
string vertexVarName = string.Empty;
|
||||
if( m_inputPorts[ 0 ].IsConnected )
|
||||
{
|
||||
vertexVarName = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexVarName = Constants.VertexShaderInputStr + ".vertex.xyz";
|
||||
}
|
||||
|
||||
string vertexSpace = m_viewSpaceInt == 1 ? " * _ProjectionParams.w" : "";
|
||||
string vertexInstruction = "-UnityObjectToViewPos( " + vertexVarName + " ).z" + vertexSpace;
|
||||
dataCollector.AddVertexInstruction( "float " + m_vertexNameStr[ m_viewSpaceInt ] + " = " + vertexInstruction, UniqueId );
|
||||
|
||||
return m_vertexNameStr[ m_viewSpaceInt ];
|
||||
}
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables );
|
||||
|
||||
|
||||
if( dataCollector.TesselationActive )
|
||||
{
|
||||
if( m_inputPorts[ 0 ].IsConnected )
|
||||
{
|
||||
string space = string.Empty;
|
||||
if( m_viewSpaceInt == 1 )
|
||||
space = " * _ProjectionParams.w";
|
||||
|
||||
if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
|
||||
string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
|
||||
RegisterLocalVariable( 0, string.Format( "-UnityObjectToViewPos( {0} ).z", value ) + space, ref dataCollector, "customSurfaceDepth" + OutputId );
|
||||
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
|
||||
}
|
||||
else
|
||||
{
|
||||
string eyeDepth = GeneratorUtils.GenerateScreenDepthOnFrag( ref dataCollector, UniqueId, CurrentPrecisionType );
|
||||
if( m_viewSpaceInt == 1 )
|
||||
{
|
||||
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, m_vertexNameStr[ 1 ], eyeDepth + " * _ProjectionParams.w" );
|
||||
return m_vertexNameStr[ 1 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return eyeDepth;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
string space = string.Empty;
|
||||
if( m_viewSpaceInt == 1 )
|
||||
space = " * _ProjectionParams.w";
|
||||
|
||||
if( m_inputPorts[ 0 ].IsConnected )
|
||||
{
|
||||
string varName = "customSurfaceDepth" + OutputId;
|
||||
GenerateInputInVertex( ref dataCollector, 0, varName, false );
|
||||
dataCollector.AddToInput( UniqueId, varName, WirePortDataType.FLOAT );
|
||||
string instruction = "-UnityObjectToViewPos( " + varName + " ).z" + space;
|
||||
dataCollector.AddToVertexLocalVariables( UniqueId , Constants.VertexShaderOutputStr + "." + varName + " = " + instruction+";" );
|
||||
return Constants.InputVarStr + "." + varName;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataCollector.AddToInput( UniqueId, m_vertexNameStr[ m_viewSpaceInt ], WirePortDataType.FLOAT );
|
||||
string instruction = "-UnityObjectToViewPos( " + Constants.VertexShaderInputStr + ".vertex.xyz ).z" + space;
|
||||
dataCollector.AddToVertexLocalVariables( UniqueId , Constants.VertexShaderOutputStr + "." + m_vertexNameStr[ m_viewSpaceInt ] + " = " + instruction+";" );
|
||||
return Constants.InputVarStr + "." + m_vertexNameStr[ m_viewSpaceInt ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
m_viewSpaceInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
||||
SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, m_viewSpaceStr[ m_viewSpaceInt ] ) );
|
||||
}
|
||||
|
||||
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
||||
{
|
||||
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
||||
IOUtils.AddFieldValueToString( ref nodeInfo, m_viewSpaceInt );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3b0855152b8c5d478f236423cfb1959
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 396e5bf33f08d3a42a19d7b161f573f2
|
||||
timeCreated: 1490358806
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "Object To Clip Pos", "Object Transform", "Transforms a point from object space to the camera’s clip space in homogeneous coordinates" )]
|
||||
public sealed class UnityObjToClipPosHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "UnityObjectToClipPos";
|
||||
//TODO: revisit this later
|
||||
m_funcLWFormatOverride = "TransformWorldToHClip(TransformObjectToWorld({0}))";
|
||||
m_funcHDFormatOverride = "TransformWorldToHClip(TransformObjectToWorld({0}))";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZW";
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "W" );
|
||||
m_previewShaderGUID = "14ec765a147a53340877b489e73f1c9f";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "unityObjectToClipPos" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c01e190d996825f42bdc81e1fab5e897
|
||||
timeCreated: 1481126959
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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( "Object To View Pos", "Object Transform", "Transforms a point from object space to view space" )]
|
||||
public sealed class UnityObjToViewPosHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "UnityObjectToViewPos";
|
||||
//TODO: revisit this later
|
||||
m_funcLWFormatOverride = "TransformWorldToView( TransformObjectToWorld( {0}) )";
|
||||
m_funcHDFormatOverride = "TransformWorldToView( TransformObjectToWorld( {0}) )";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
m_previewShaderGUID = "b790bc1d468a51840a9facef372b4729";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "unityObjectToViewPos" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f35cf284cf7d2b47be5a32426fc7a77
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
// 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( "World Space Light Dir", "Light", "Computes normalized world space light direction" )]
|
||||
public sealed class WorldSpaceLightDirHlpNode : HelperParentNode
|
||||
{
|
||||
private const string NormalizeOptionStr = "Safe Normalize";
|
||||
|
||||
[SerializeField]
|
||||
private bool m_safeNormalize = false;
|
||||
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "UnityWorldSpaceLightDir";
|
||||
m_inputPorts[ 0 ].Visible = false;
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
|
||||
m_useInternalPortData = false;
|
||||
m_drawPreviewAsSphere = true;
|
||||
m_autoWrapProperties = true;
|
||||
m_textLabelWidth = 120;
|
||||
m_previewShaderGUID = "2e8dc46eb6fb2124d9f0007caf9567e3";
|
||||
}
|
||||
|
||||
public override void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
|
||||
{
|
||||
base.PropagateNodeData( nodeData, ref dataCollector );
|
||||
if( m_safeNormalize )
|
||||
dataCollector.SafeNormalizeLightDir = true;
|
||||
}
|
||||
|
||||
public override void DrawProperties()
|
||||
{
|
||||
base.DrawProperties();
|
||||
m_safeNormalize = EditorGUILayoutToggle( NormalizeOptionStr, m_safeNormalize );
|
||||
EditorGUILayout.HelpBox( "Having safe normalize ON makes sure your light vector is not zero even if there's no lights in your scene.", MessageType.None );
|
||||
}
|
||||
|
||||
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
||||
{
|
||||
if( dataCollector.IsTemplate )
|
||||
return GetOutputVectorItem( 0, outputId, dataCollector.TemplateDataCollectorInstance.GetWorldSpaceLightDir( CurrentPrecisionType ) ); ;
|
||||
|
||||
dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
|
||||
dataCollector.AddToInput( UniqueId, SurfaceInputs.WORLD_POS );
|
||||
|
||||
return GetOutputVectorItem( 0, outputId, GeneratorUtils.GenerateWorldLightDirection( ref dataCollector, UniqueId, CurrentPrecisionType ) );
|
||||
}
|
||||
|
||||
public override void ReadFromString( ref string[] nodeParams )
|
||||
{
|
||||
base.ReadFromString( ref nodeParams );
|
||||
if( UIUtils.CurrentShaderVersion() > 15201 )
|
||||
{
|
||||
m_safeNormalize = 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_safeNormalize );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2134a58fb8235524d84046a051bce6b5
|
||||
timeCreated: 1481126954
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
// Amplify Shader Editor - Visual Shader Editing Tool
|
||||
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
||||
|
||||
using System;
|
||||
namespace AmplifyShaderEditor
|
||||
{
|
||||
[Serializable]
|
||||
[NodeAttributes( "World Space View Dir", "Object Transform", "World space direction (not normalized) from given object space vertex position towards the camera" )]
|
||||
public sealed class WorldSpaceViewDirHlpNode : HelperParentNode
|
||||
{
|
||||
protected override void CommonInit( int uniqueId )
|
||||
{
|
||||
base.CommonInit( uniqueId );
|
||||
m_funcType = "WorldSpaceViewDir";
|
||||
//TODO: revisit this later
|
||||
m_funcLWFormatOverride = "( _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), {0} ).xyz )";
|
||||
m_funcHDFormatOverride = "( _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), {0} ).xyz )";
|
||||
m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
|
||||
m_inputPorts[ 0 ].Vector4InternalData = new UnityEngine.Vector4( 0, 0, 0, 1 );
|
||||
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT3, false );
|
||||
m_outputPorts[ 0 ].Name = "XYZ";
|
||||
AddOutputPort( WirePortDataType.FLOAT, "X" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Y" );
|
||||
AddOutputPort( WirePortDataType.FLOAT, "Z" );
|
||||
m_previewShaderGUID = "fe0e09756a8a0ba408015b43e66cb8a6";
|
||||
}
|
||||
|
||||
protected override void OnUniqueIDAssigned()
|
||||
{
|
||||
base.OnUniqueIDAssigned();
|
||||
m_localVarName = "worldSpaceViewDir" + OutputId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61d7064bd5523634496fa412627603d7
|
||||
timeCreated: 1481126956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user