
commit bb3be793ca5db3df43679f2d6c34c75f768047a1 Author: SAIPO <grasste0403@hotmail.com> Date: Wed Dec 22 07:46:07 2021 +0800 修改佛教Boss关卡和伊斯兰Boss关卡的粒子特效 commit 1987a63954402be8894f9cc9805545432afefa18 Author: SAIPO <grasste0403@hotmail.com> Date: Tue Dec 21 20:55:05 2021 +0800 任务:编写shader,完善数据库类 1.完善了PlayerInfo类,用以数据库功能 1) 编写GetSqlData()函数,使用多线程获取用户信息,使用前请先设置公关变量name。 2) 编写CreateUser(string username)函数,在用户表内创建一个用户。 3) 编写hasName(string _searchName)函数,判断是否存在这个用户。 4) 编写GetBoardInfo(int WorldId)函数,获取指定世界的留言板链表。 5) 编写GetDeadInfo(int WorldId)函数,获取指定世界的死亡信息链表。 6) 编写CreateDead(int WorldId, Vector2 postion)函数,创建一条死亡信息。 7) 编写CreateBoard(int WorldId, Vector2 postion,string text)函数,创建一条留言信息。 8) 编写UpdatePlayerInfo()函数,将类里储存的信息上传到数据库。 2.实装相关Shader 1)完善以撒关卡的屏幕后特效,使其可以在发怒场景发出红色辉光。 2)完善以撒鬼魂的粒子,并且颜色和发怒与否关联。 3)实装以撒关卡的窗户辉光效果。 4)实装伊斯兰Boss关卡炸弹弹反的粒子特效。 5)实装伊斯兰Boss关卡的尘土特效(需要重做) 6)实装佛教Boss关卡的敲钟声波特效。 7)实装佛教Boss关卡的钟声受击灰尘(需要重做) 3.目前发现的bug 1)当人物恰好调到角落里会卡动画。 2)伊斯兰Boss关卡,特洛伊木马吐出的炸弹落到特效小怪上会闪退。 commit c06b842382051bc260d9f509491c683a41ca2a4c Author: SAIPO <grasste0403@hotmail.com> Date: Tue Dec 21 14:08:06 2021 +0800 Squashed commit of the following: commit e7dcdec1d9913e283f42d42f72f1030f0c8b6fda Author: Roman <1325980292@qq.com> Date: Tue Dec 21 00:45:50 2021 +0800 任务:搭建前置关卡,编写演出逻辑 1.流程化游戏 (1.制作转移器,内含字典,根据玩家的静态属性“阶段”来决定到转移点后将会移动到哪一个场景 (2.制作转场器,水平方向从左到右 下班 commit 74f926815ec8d00fa051192eb3b978ff4b3c01a6 Author: Roman <1325980292@qq.com> Date: Mon Dec 20 23:33:14 2021 +0800 任务:搭建前置关卡,编写演出逻辑 1.编写基督前置关卡 (1.放置平台、怪物和男童 (2.修改男童类,外加OnSaveEvent,OnSave时若有事件则触发该Event (3.编写开幕演出,与yi前置类似 (4.编写男童解救演出 ((1.触发Fungus对话 ((2.对话结束后,开启通往上层的门 2.搭建村场景 (1.放置平台和元素 (2.为可动元素制作动画 3.为玩家添加static属性,进度。0:刚开,1进村,2通佛,3通伊,4.通基 4.制作死亡重开功能 (1.当玩家生命值降到0及以下,触发死亡事件 (2.死亡后reload当前场景,并设记录员,关闭某些事件和演出不再执行 *优化和修复 (1.尝试制作击中卡肉效果,目前打击感太弱。也可以尝试粒子效果 *至此,全部前置关卡搭建完毕,村场景搭建完毕。 *明天可以完成流程化,接下来就是填充剧情、UI、死亡标记和留言板等系统了 下班 commit f257b40d10373a13380e9c395fe94d6559a82a0f Author: Roman <1325980292@qq.com> Date: Sun Dec 19 23:57:44 2021 +0800 任务:搭建前置关卡,编写演出逻辑 1.编写佛教前置关开场演出 (*.休整地形,使得左边多出一块地面,方便演出正常运作 (*.项目后期再通过逻辑触发该演出,目前先用调试方式触发演出 (1.关闭空气墙 (2.修改玩家inputDir使玩家从屏幕外冲进到屏幕内部 (3.等待一段时间 (4.此时玩家应该走到某个合适的位置,停止玩家的inputDir (5.等待一小段时间给玩家反应 (6.修改相机offset,使其对准对话的两个小怪 (7.等待一小段时间给玩家反应 (8.触发Fungus对话 (9.Fungus对话结束后,返回标记命令演出Main继续执行 *.修改NormalEnemy,添加标识isInFoStage,在Update中判断,若是,使该怪物水平方向上追踪玩家,可以参考爱欲品的Seek (10.修改左边小怪的isInFoStage (11.开启右边小怪的Path动画,表现其慌忙逃跑 (12.Invoke一个延时,等右边小怪逃出视野后删除它 (13.触发善后和结束事件 (14.重写善后事件,重新开启空气墙 2.搭建伊斯兰前置关卡 3.创建伊斯兰前置关卡演出 (1.关闭空气墙 (2.修改玩家inputDir使玩家从屏幕外冲进到屏幕内部 (3.等待一段时间 (4.此时玩家应该走到某个合适的位置,停止玩家的inputDir (5.等待一小段时间给玩家反应 (6.触发善后与结束事件 4.创建玩家隔间触发事件 (1.是进入式触发器对象 (2.触发时Call隔间演出 5.编写隔间演出逻辑 (1.表现关门 (2.左右晃一下镜头,中心移动到左右门处,表示门被关闭 (3.镜头回到玩家处,同时压缩相机可移动范围更窄 (4.打开隔间墙壁的空气墙 (5.设置EndEvent为伊斯兰事件 6.编写召唤伊斯兰事件 (1.摘自木马的召唤攻击,稍作修改 (2.当召唤的伊斯兰全部挂了,触发隔间结束事件 7.编写隔间结束事件 (1.表现开门 (2.关闭隔间的空气墙 (3.重设相机移动范围 8.搭建基督前置关卡 *.至此,第一关、第二关前置关卡的逻辑基本开发完毕 *.明天能做完所有前置关,顺便应该能搭完村场景,后天可以开始搭建新系统,目前还差留言、死亡标记等系统等待编写 下班 commit cd22966ad7637a84c0f08c3a716d5ec549699749 Author: Roman <1325980292@qq.com> Date: Sun Dec 19 14:12:05 2021 +0800 Squashed commit of the following: commit 26aff356971bdc2c2a6a3bd444eeb50c4bf7ec14 Author: SAIPO <grasste0403@hotmail.com> Date: Sun Dec 19 02:20:44 2021 +0800 导入近期制作的一些Shader 1.合并分支 2.完成了人物描边的流动shader制作,并且可以对Bloom屏幕后处理产生反应。 3.完成了基督教boss关卡,彩色窗户辉光的shader制作,可以对Bloom产生反应。 4.完成了伊斯兰教弹反的炸弹拖尾粒子shader的制作。 5.完成了火焰粒子shader的制作(可以用在基督教的以撒鬼魂上)。 6.完成了灰尘粒子像素化的shader制作。 7.完成了边缘扭曲的shader制作,可以用在一些树木上,让画面产生动感。 明天制作敲钟的声波Shader # Conflicts: # UserSettings/EditorUserSettings.asset commit 26aff356971bdc2c2a6a3bd444eeb50c4bf7ec14 Author: SAIPO <grasste0403@hotmail.com> Date: Sun Dec 19 02:20:44 2021 +0800 导入近期制作的一些Shader 1.合并分支 2.完成了人物描边的流动shader制作,并且可以对Bloom屏幕后处理产生反应。 3.完成了基督教boss关卡,彩色窗户辉光的shader制作,可以对Bloom产生反应。 4.完成了伊斯兰教弹反的炸弹拖尾粒子shader的制作。 5.完成了火焰粒子shader的制作(可以用在基督教的以撒鬼魂上)。 6.完成了灰尘粒子像素化的shader制作。 7.完成了边缘扭曲的shader制作,可以用在一些树木上,让画面产生动感。 明天制作敲钟的声波Shader # Conflicts: # Assets/Scenes/TeLuoYiStageTest.unity # Assets/Shader/火焰粒子shader/particle.shadergraph # Assets/Shader/灰尘粒子用shader/Pixel_My.shader # Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My 1.mat # Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My 2.mat # Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My.mat # Logs/ApiUpdaterCheck.txt # UserSettings/EditorUserSettings.asset
1361 lines
44 KiB
C#
1361 lines
44 KiB
C#
// Amplify Shader Editor - Visual Shader Editing Tool
|
|
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
#if !UNITY_2018_1_OR_NEWER
|
|
namespace AmplifyShaderEditor
|
|
{
|
|
// Disabling Substance Deprecated warning
|
|
#pragma warning disable 0618
|
|
[Serializable]
|
|
[NodeAttributes( "Substance Sample", "Textures", "Samples a procedural material", KeyCode.None, true, 0, int.MaxValue, typeof( SubstanceArchive ), typeof( ProceduralMaterial ) )]
|
|
public sealed class SubstanceSamplerNode : PropertyNode
|
|
{
|
|
private const string GlobalVarDecStr = "uniform sampler2D {0};";
|
|
private const string PropertyDecStr = "{0}(\"{0}\", 2D) = \"white\"";
|
|
|
|
private const string AutoNormalStr = "Auto-Normal";
|
|
private const string SubstanceStr = "Substance";
|
|
|
|
private float TexturePreviewSizeX = 128;
|
|
private float TexturePreviewSizeY = 128;
|
|
|
|
private float PickerPreviewWidthAdjust = 18;
|
|
|
|
private bool m_editing;
|
|
|
|
private CacheNodeConnections m_cacheNodeConnections;
|
|
|
|
[SerializeField]
|
|
private int m_firstOutputConnected = 0;
|
|
|
|
[SerializeField]
|
|
private ProceduralMaterial m_proceduralMaterial;
|
|
|
|
[SerializeField]
|
|
private int m_textureCoordSet = 0;
|
|
|
|
[SerializeField]
|
|
private ProceduralOutputType[] m_textureTypes;
|
|
|
|
[SerializeField]
|
|
private bool m_autoNormal = true;
|
|
|
|
private System.Type m_type;
|
|
|
|
private Texture[] m_textures = new Texture[] { };
|
|
|
|
private List<int> m_outputConns = new List<int>();
|
|
|
|
private Rect m_previewArea;
|
|
|
|
private Rect m_pickerArea;
|
|
|
|
protected override void CommonInit( int uniqueId )
|
|
{
|
|
base.CommonInit( uniqueId );
|
|
AddInputPort( WirePortDataType.FLOAT2, false, "UV" );
|
|
AddOutputPort( WirePortDataType.COLOR, Constants.EmptyPortValue );
|
|
m_insideSize.Set( TexturePreviewSizeX + PickerPreviewWidthAdjust, TexturePreviewSizeY + 10 );
|
|
m_type = typeof( ProceduralMaterial );
|
|
m_currentParameterType = PropertyType.Property;
|
|
m_freeType = false;
|
|
m_freeName = false;
|
|
m_autoWrapProperties = true;
|
|
m_customPrefix = "Substance Sample ";
|
|
m_drawPrecisionUI = false;
|
|
m_showPreview = true;
|
|
m_drawPreviewExpander = false;
|
|
m_selectedLocation = PreviewLocation.TopCenter;
|
|
m_cacheNodeConnections = new CacheNodeConnections();
|
|
m_previewShaderGUID = "6f322c1da33f1e744941aafcb0ad1a2d";
|
|
m_showAutoRegisterUI = false;
|
|
}
|
|
|
|
public override void RenderNodePreview()
|
|
{
|
|
//Runs at least one time
|
|
if( !m_initialized )
|
|
{
|
|
// nodes with no preview don't update at all
|
|
PreviewIsDirty = false;
|
|
return;
|
|
}
|
|
|
|
if( !PreviewIsDirty )
|
|
return;
|
|
|
|
SetPreviewInputs();
|
|
|
|
PreviewMaterial.SetInt( "_CustomUVs", m_inputPorts[ 0 ].IsConnected ? 1 : 0 );
|
|
|
|
if( m_proceduralMaterial == null )
|
|
return;
|
|
|
|
if( !Preferences.GlobalDisablePreviews )
|
|
{
|
|
Texture[] texs = m_proceduralMaterial.GetGeneratedTextures();
|
|
int count = m_outputPorts.Count;
|
|
for( int i = 0 ; i < count ; i++ )
|
|
{
|
|
RenderTexture temp = RenderTexture.active;
|
|
RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture;
|
|
|
|
PreviewMaterial.SetTexture( "_GenTex" , texs[ i ] );
|
|
|
|
if( m_autoNormal && m_textureTypes[ i ] == ProceduralOutputType.Normal )
|
|
Graphics.Blit( null , m_outputPorts[ i ].OutputPreviewTexture , PreviewMaterial , 1 );
|
|
else
|
|
Graphics.Blit( null , m_outputPorts[ i ].OutputPreviewTexture , PreviewMaterial , 0 );
|
|
RenderTexture.active = temp;
|
|
}
|
|
}
|
|
|
|
PreviewIsDirty = m_continuousPreviewRefresh;
|
|
}
|
|
|
|
public override void OnOutputPortConnected( int portId, int otherNodeId, int otherPortId )
|
|
{
|
|
base.OnOutputPortConnected( portId, otherNodeId, otherPortId );
|
|
m_firstOutputConnected = -1;
|
|
}
|
|
|
|
public override void OnOutputPortDisconnected( int portId )
|
|
{
|
|
base.OnOutputPortDisconnected( portId );
|
|
m_firstOutputConnected = -1;
|
|
}
|
|
|
|
void CalculateFirstOutputConnected()
|
|
{
|
|
m_outputConns.Clear();
|
|
int count = m_outputPorts.Count;
|
|
bool connectionsAvailable = false;
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
if( m_outputPorts[ i ].IsConnected )
|
|
{
|
|
connectionsAvailable = true;
|
|
}
|
|
}
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
if( connectionsAvailable )
|
|
{
|
|
if( m_outputPorts[ i ].IsConnected )
|
|
{
|
|
if( m_firstOutputConnected < 0 )
|
|
m_firstOutputConnected = i;
|
|
|
|
m_outputConns.Add( i );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_outputConns.Add( i );
|
|
}
|
|
}
|
|
|
|
if( m_firstOutputConnected < 0 )
|
|
m_firstOutputConnected = 0;
|
|
}
|
|
|
|
public override void OnNodeLayout( DrawInfo drawInfo )
|
|
{
|
|
base.OnNodeLayout( drawInfo );
|
|
|
|
m_previewArea = m_remainingBox;
|
|
m_previewArea.width = TexturePreviewSizeX * drawInfo.InvertedZoom;
|
|
m_previewArea.height = TexturePreviewSizeY * drawInfo.InvertedZoom;
|
|
m_previewArea.x += 0.5f * m_remainingBox.width - 0.5f * m_previewArea.width;
|
|
m_pickerArea = m_previewArea;
|
|
m_pickerArea.width = 40 * drawInfo.InvertedZoom;
|
|
m_pickerArea.x = m_previewArea.xMax - m_pickerArea.width - 2;
|
|
m_pickerArea.height = 14 * drawInfo.InvertedZoom;
|
|
m_pickerArea.y = m_previewArea.yMax - m_pickerArea.height - 2;
|
|
}
|
|
|
|
public override void DrawGUIControls( DrawInfo drawInfo )
|
|
{
|
|
base.DrawGUIControls( drawInfo );
|
|
|
|
if( !( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp || drawInfo.CurrentEventType == EventType.ExecuteCommand || drawInfo.CurrentEventType == EventType.DragPerform ) )
|
|
return;
|
|
|
|
bool insideBox = m_previewArea.Contains( drawInfo.MousePosition );
|
|
|
|
if( insideBox )
|
|
{
|
|
m_editing = true;
|
|
}
|
|
else if( m_editing && !insideBox && drawInfo.CurrentEventType != EventType.ExecuteCommand )
|
|
{
|
|
GUI.FocusControl( null );
|
|
m_editing = false;
|
|
}
|
|
}
|
|
|
|
public override void Draw( DrawInfo drawInfo )
|
|
{
|
|
base.Draw( drawInfo );
|
|
|
|
if( m_editing )
|
|
{
|
|
m_textures = m_proceduralMaterial != null ? m_proceduralMaterial.GetGeneratedTextures() : null;
|
|
if( GUI.Button( m_pickerArea, string.Empty, GUIStyle.none ) )
|
|
{
|
|
int controlID = EditorGUIUtility.GetControlID( FocusType.Passive );
|
|
EditorGUIUtility.ShowObjectPicker<ProceduralMaterial>( m_proceduralMaterial, false, "", controlID );
|
|
}
|
|
|
|
string commandName = Event.current.commandName;
|
|
UnityEngine.Object newValue = null;
|
|
if( commandName == "ObjectSelectorUpdated" )
|
|
{
|
|
newValue = EditorGUIUtility.GetObjectPickerObject();
|
|
if( newValue != (UnityEngine.Object)m_proceduralMaterial )
|
|
{
|
|
PreviewIsDirty = true;
|
|
UndoRecordObject( "Changing value EditorGUIObjectField on node Substance Sample" );
|
|
|
|
m_proceduralMaterial = newValue != null ? (ProceduralMaterial)newValue : null;
|
|
m_textures = m_proceduralMaterial != null ? m_proceduralMaterial.GetGeneratedTextures() : null;
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
}
|
|
else if( commandName == "ObjectSelectorClosed" )
|
|
{
|
|
newValue = EditorGUIUtility.GetObjectPickerObject();
|
|
if( newValue != (UnityEngine.Object)m_proceduralMaterial )
|
|
{
|
|
PreviewIsDirty = true;
|
|
UndoRecordObject( "Changing value EditorGUIObjectField on node Substance Sample" );
|
|
|
|
m_proceduralMaterial = newValue != null ? (ProceduralMaterial)newValue : null;
|
|
m_textures = m_proceduralMaterial != null ? m_proceduralMaterial.GetGeneratedTextures() : null;
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
m_editing = false;
|
|
}
|
|
|
|
if( GUI.Button( m_previewArea, string.Empty, GUIStyle.none ) )
|
|
{
|
|
if( m_proceduralMaterial != null )
|
|
{
|
|
Selection.activeObject = m_proceduralMaterial;
|
|
EditorGUIUtility.PingObject( Selection.activeObject );
|
|
}
|
|
m_editing = false;
|
|
}
|
|
}
|
|
|
|
if( drawInfo.CurrentEventType == EventType.Repaint )
|
|
{
|
|
if( !m_editing )
|
|
m_textures = m_proceduralMaterial != null ? m_proceduralMaterial.GetGeneratedTextures() : null;
|
|
|
|
if( m_textures != null )
|
|
{
|
|
if( m_firstOutputConnected < 0 )
|
|
{
|
|
CalculateFirstOutputConnected();
|
|
}
|
|
else if( m_textures.Length != m_textureTypes.Length )
|
|
{
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
|
|
int texCount = m_outputConns.Count;
|
|
Rect individuals = m_previewArea;
|
|
individuals.height /= texCount;
|
|
|
|
for( int i = 0; i < texCount; i++ )
|
|
{
|
|
EditorGUI.DrawPreviewTexture( individuals, m_textures[ m_outputConns[ i ] ], null, ScaleMode.ScaleAndCrop );
|
|
individuals.y += individuals.height;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GUI.Label( m_previewArea, string.Empty, UIUtils.ObjectFieldThumb );
|
|
}
|
|
|
|
if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
|
|
{
|
|
Rect smallButton = m_previewArea;
|
|
smallButton.height = 14 * drawInfo.InvertedZoom;
|
|
smallButton.y = m_previewArea.yMax - smallButton.height - 2;
|
|
smallButton.width = 40 * drawInfo.InvertedZoom;
|
|
smallButton.x = m_previewArea.xMax - smallButton.width - 2;
|
|
if( m_textures == null )
|
|
{
|
|
GUI.Label( m_previewArea, "None (Procedural Material)", UIUtils.ObjectFieldThumbOverlay );
|
|
}
|
|
GUI.Label( m_pickerArea, "Select", UIUtils.GetCustomStyle( CustomStyle.SamplerButton ) );
|
|
}
|
|
|
|
GUI.Label( m_previewArea, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
|
|
}
|
|
}
|
|
|
|
void OnNewSubstanceSelected( Texture[] textures )
|
|
{
|
|
CacheCurrentSettings();
|
|
ConfigPortsFromMaterial( true, textures );
|
|
ConnectFromCache();
|
|
m_requireMaterialUpdate = true;
|
|
CalculateFirstOutputConnected();
|
|
ContainerGraph.ParentWindow.RequestRepaint();
|
|
}
|
|
|
|
public override void DrawProperties()
|
|
{
|
|
base.DrawProperties();
|
|
EditorGUI.BeginChangeCheck();
|
|
m_proceduralMaterial = EditorGUILayoutObjectField( SubstanceStr, m_proceduralMaterial, m_type, false ) as ProceduralMaterial;
|
|
if( EditorGUI.EndChangeCheck() )
|
|
{
|
|
Texture[] textures = m_proceduralMaterial != null ? m_proceduralMaterial.GetGeneratedTextures() : null;
|
|
if( textures != null )
|
|
{
|
|
OnNewSubstanceSelected( textures );
|
|
}
|
|
}
|
|
|
|
m_textureCoordSet = EditorGUILayoutIntPopup( Constants.AvailableUVSetsLabel, m_textureCoordSet, Constants.AvailableUVSetsStr, Constants.AvailableUVSets );
|
|
EditorGUI.BeginChangeCheck();
|
|
m_autoNormal = EditorGUILayoutToggle( AutoNormalStr, m_autoNormal );
|
|
if( EditorGUI.EndChangeCheck() )
|
|
{
|
|
for( int i = 0; i < m_textureTypes.Length; i++ )
|
|
{
|
|
WirePortDataType portType = ( m_autoNormal && m_textureTypes[ i ] == ProceduralOutputType.Normal ) ? WirePortDataType.FLOAT3 : WirePortDataType.COLOR;
|
|
if( m_outputPorts[ i ].DataType != portType )
|
|
{
|
|
m_outputPorts[ i ].ChangeType( portType, false );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CacheCurrentSettings()
|
|
{
|
|
m_cacheNodeConnections.Clear();
|
|
for( int portId = 0; portId < m_outputPorts.Count; portId++ )
|
|
{
|
|
if( m_outputPorts[ portId ].IsConnected )
|
|
{
|
|
int connCount = m_outputPorts[ portId ].ConnectionCount;
|
|
for( int connIdx = 0; connIdx < connCount; connIdx++ )
|
|
{
|
|
WireReference connection = m_outputPorts[ portId ].GetConnection( connIdx );
|
|
m_cacheNodeConnections.Add( m_outputPorts[ portId ].Name, new NodeCache( connection.NodeId, connection.PortId ) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ConnectFromCache()
|
|
{
|
|
for( int i = 0; i < m_outputPorts.Count; i++ )
|
|
{
|
|
List<NodeCache> connections = m_cacheNodeConnections.GetList( m_outputPorts[ i ].Name );
|
|
if( connections != null )
|
|
{
|
|
int count = connections.Count;
|
|
for( int connIdx = 0; connIdx < count; connIdx++ )
|
|
{
|
|
UIUtils.SetConnection( connections[ connIdx ].TargetNodeId, connections[ connIdx ].TargetPortId, UniqueId, i );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void ConfigPortsFromMaterial( bool invalidateConnections = false, Texture[] newTextures = null )
|
|
{
|
|
SetAdditonalTitleText( ( m_proceduralMaterial != null ) ? string.Format( Constants.PropertyValueLabel, m_proceduralMaterial.name ) : "Value( <None> )" );
|
|
|
|
Texture[] textures = newTextures != null ? newTextures : ( ( m_proceduralMaterial != null ) ? m_proceduralMaterial.GetGeneratedTextures() : null );
|
|
if( textures != null )
|
|
{
|
|
m_firstOutputConnected = -1;
|
|
string nameToRemove = m_proceduralMaterial.name + "_";
|
|
m_textureTypes = new ProceduralOutputType[ textures.Length ];
|
|
for( int i = 0; i < textures.Length; i++ )
|
|
{
|
|
ProceduralTexture procTex = textures[ i ] as ProceduralTexture;
|
|
m_textureTypes[ i ] = procTex.GetProceduralOutputType();
|
|
|
|
WirePortDataType portType = ( m_autoNormal && m_textureTypes[ i ] == ProceduralOutputType.Normal ) ? WirePortDataType.FLOAT3 : WirePortDataType.COLOR;
|
|
string newName = textures[ i ].name.Replace( nameToRemove, string.Empty );
|
|
char firstLetter = Char.ToUpper( newName[ 0 ] );
|
|
newName = firstLetter.ToString() + newName.Substring( 1 );
|
|
if( i < m_outputPorts.Count )
|
|
{
|
|
m_outputPorts[ i ].ChangeProperties( newName, portType, false );
|
|
if( invalidateConnections )
|
|
{
|
|
m_outputPorts[ i ].FullDeleteConnections();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddOutputPort( portType, newName );
|
|
}
|
|
}
|
|
|
|
if( textures.Length < m_outputPorts.Count )
|
|
{
|
|
int itemsToRemove = m_outputPorts.Count - textures.Length;
|
|
for( int i = 0; i < itemsToRemove; i++ )
|
|
{
|
|
int idx = m_outputPorts.Count - 1;
|
|
if( m_outputPorts[ idx ].IsConnected )
|
|
{
|
|
m_outputPorts[ idx ].ForceClearConnection();
|
|
}
|
|
RemoveOutputPort( idx );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int itemsToRemove = m_outputPorts.Count - 1;
|
|
m_outputPorts[ 0 ].ChangeProperties( Constants.EmptyPortValue, WirePortDataType.COLOR, false );
|
|
m_outputPorts[ 0 ].ForceClearConnection();
|
|
|
|
for( int i = 0; i < itemsToRemove; i++ )
|
|
{
|
|
int idx = m_outputPorts.Count - 1;
|
|
if( m_outputPorts[ idx ].IsConnected )
|
|
{
|
|
m_outputPorts[ idx ].ForceClearConnection();
|
|
}
|
|
RemoveOutputPort( idx );
|
|
}
|
|
}
|
|
|
|
m_sizeIsDirty = true;
|
|
m_isDirty = true;
|
|
}
|
|
|
|
private void ConfigFromObject( UnityEngine.Object obj )
|
|
{
|
|
ProceduralMaterial newMat = AssetDatabase.LoadAssetAtPath<ProceduralMaterial>( AssetDatabase.GetAssetPath( obj ) );
|
|
if( newMat != null )
|
|
{
|
|
m_proceduralMaterial = newMat;
|
|
ConfigPortsFromMaterial();
|
|
}
|
|
}
|
|
|
|
public override void OnObjectDropped( UnityEngine.Object obj )
|
|
{
|
|
ConfigFromObject( obj );
|
|
}
|
|
|
|
public override void SetupFromCastObject( UnityEngine.Object obj )
|
|
{
|
|
ConfigFromObject( obj );
|
|
}
|
|
|
|
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
|
{
|
|
if( m_proceduralMaterial == null )
|
|
{
|
|
return "(0).xxxx";
|
|
}
|
|
|
|
if( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) )
|
|
{
|
|
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
|
}
|
|
|
|
Texture[] textures = m_proceduralMaterial.GetGeneratedTextures();
|
|
|
|
string uvPropertyName = string.Empty;
|
|
for( int i = 0; i < m_outputPorts.Count; i++ )
|
|
{
|
|
if( m_outputPorts[ i ].HasConnectedNode )
|
|
{
|
|
uvPropertyName = textures[ i ].name;
|
|
break;
|
|
}
|
|
}
|
|
|
|
string name = textures[ outputId ].name + OutputId;
|
|
dataCollector.AddToUniforms( UniqueId, string.Format( GlobalVarDecStr, textures[ outputId ].name ) );
|
|
dataCollector.AddToProperties( UniqueId, string.Format( PropertyDecStr, textures[ outputId ].name ) + "{}", -1 );
|
|
bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation );
|
|
string value = string.Format( "tex2D{0}({1}, {2})", ( isVertex ? "lod" : string.Empty ), textures[ outputId ].name, GetUVCoords( ref dataCollector, ignoreLocalvar, uvPropertyName ) );
|
|
if( m_autoNormal && m_textureTypes[ outputId ] == ProceduralOutputType.Normal )
|
|
{
|
|
value = GeneratorUtils.GenerateUnpackNormalStr( ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, value, false, "1.0" );
|
|
}
|
|
|
|
dataCollector.AddPropertyNode( this );
|
|
RegisterLocalVariable( outputId, value, ref dataCollector, name );
|
|
|
|
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
|
}
|
|
|
|
public string GetUVCoords( ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar, string propertyName )
|
|
{
|
|
bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation );
|
|
if( m_inputPorts[ 0 ].IsConnected )
|
|
{
|
|
return m_inputPorts[ 0 ].GenerateShaderForOutput( ref dataCollector, isVertex ? WirePortDataType.FLOAT4 : WirePortDataType.FLOAT2, ignoreLocalVar, true );
|
|
}
|
|
else
|
|
{
|
|
string uvChannelName = IOUtils.GetUVChannelName( propertyName, m_textureCoordSet );
|
|
|
|
if( dataCollector.IsTemplate )
|
|
{
|
|
string propertyHelperVar = propertyName + "_ST";
|
|
dataCollector.AddToUniforms( UniqueId, "float4", propertyHelperVar, dataCollector.IsSRP );
|
|
string uvName = string.Empty;
|
|
if( dataCollector.TemplateDataCollectorInstance.HasUV( m_textureCoordSet ) )
|
|
{
|
|
uvName = dataCollector.TemplateDataCollectorInstance.GetUVName( m_textureCoordSet );
|
|
}
|
|
else
|
|
{
|
|
uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV( m_textureCoordSet );
|
|
}
|
|
|
|
uvChannelName = "uv" + propertyName;
|
|
if( isVertex )
|
|
{
|
|
string value = string.Format( Constants.TilingOffsetFormat, uvName, propertyHelperVar + ".xy", propertyHelperVar + ".zw" );
|
|
string lodLevel = "0";
|
|
|
|
value = "float4( " + value + ", 0 , " + lodLevel + " )";
|
|
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT4, uvChannelName, value );
|
|
}
|
|
else
|
|
{
|
|
dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT2, uvChannelName, string.Format( Constants.TilingOffsetFormat, uvName, propertyHelperVar + ".xy", propertyHelperVar + ".zw" ) );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string vertexCoords = Constants.VertexShaderInputStr + ".texcoord";
|
|
if( m_textureCoordSet > 0 )
|
|
{
|
|
vertexCoords += m_textureCoordSet.ToString();
|
|
}
|
|
|
|
|
|
string dummyPropUV = "_texcoord" + ( m_textureCoordSet > 0 ? ( m_textureCoordSet + 1 ).ToString() : "" );
|
|
string dummyUV = "uv" + ( m_textureCoordSet > 0 ? ( m_textureCoordSet + 1 ).ToString() : "" ) + dummyPropUV;
|
|
|
|
dataCollector.AddToUniforms( UniqueId, "uniform float4 " + propertyName + "_ST;" );
|
|
dataCollector.AddToProperties( UniqueId, "[HideInInspector] " + dummyPropUV + "( \"\", 2D ) = \"white\" {}", 100 );
|
|
dataCollector.AddToInput( UniqueId, dummyUV, WirePortDataType.FLOAT2 );
|
|
|
|
if( isVertex )
|
|
{
|
|
dataCollector.AddToVertexLocalVariables( UniqueId, "float4 " + uvChannelName + " = float4(" + vertexCoords + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw, 0 ,0);" );
|
|
return uvChannelName;
|
|
}
|
|
else
|
|
dataCollector.AddToLocalVariables( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT2, uvChannelName, Constants.InputVarStr + "." + dummyUV + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw" );
|
|
|
|
}
|
|
|
|
return uvChannelName;
|
|
}
|
|
}
|
|
|
|
public override void UpdateMaterial( Material mat )
|
|
{
|
|
base.UpdateMaterial( mat );
|
|
if( m_proceduralMaterial != null )
|
|
{
|
|
Texture[] textures = m_proceduralMaterial.GetGeneratedTextures();
|
|
for( int i = 0; i < textures.Length; i++ )
|
|
{
|
|
if( mat.HasProperty( textures[ i ].name ) && !InsideShaderFunction )
|
|
{
|
|
mat.SetTexture( textures[ i ].name, textures[ i ] );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool UpdateShaderDefaults( ref Shader shader, ref TextureDefaultsDataColector defaultCol )
|
|
{
|
|
if( m_proceduralMaterial != null )
|
|
{
|
|
Texture[] textures = m_proceduralMaterial.GetGeneratedTextures();
|
|
for( int i = 0; i < textures.Length; i++ )
|
|
{
|
|
defaultCol.AddValue( textures[ i ].name, textures[ i ] );
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void Destroy()
|
|
{
|
|
base.Destroy();
|
|
m_textures = null;
|
|
m_proceduralMaterial = null;
|
|
m_cacheNodeConnections.Clear();
|
|
m_cacheNodeConnections = null;
|
|
m_outputConns.Clear();
|
|
m_outputConns = null;
|
|
}
|
|
|
|
public override string GetPropertyValStr()
|
|
{
|
|
return m_proceduralMaterial ? m_proceduralMaterial.name : string.Empty;
|
|
}
|
|
|
|
public override void ReadFromString( ref string[] nodeParams )
|
|
{
|
|
base.ReadFromString( ref nodeParams );
|
|
string guid = GetCurrentParam( ref nodeParams );
|
|
m_textureCoordSet = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
|
m_autoNormal = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
|
if( guid.Length > 1 )
|
|
{
|
|
m_proceduralMaterial = AssetDatabase.LoadAssetAtPath<ProceduralMaterial>( AssetDatabase.GUIDToAssetPath( guid ) );
|
|
if( m_proceduralMaterial != null )
|
|
{
|
|
ConfigPortsFromMaterial();
|
|
}
|
|
else
|
|
{
|
|
UIUtils.ShowMessage( UniqueId, "Substance not found ", MessageSeverity.Error );
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
|
{
|
|
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
|
string guid = ( m_proceduralMaterial != null ) ? AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_proceduralMaterial ) ) : "0";
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, guid );
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, m_textureCoordSet );
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, m_autoNormal );
|
|
}
|
|
|
|
}
|
|
#pragma warning restore 0618
|
|
}
|
|
#elif SUBSTANCE_PLUGIN_ENABLED
|
|
|
|
using Substance.Game;
|
|
|
|
namespace AmplifyShaderEditor
|
|
{
|
|
public enum ASEProceduralOutputType
|
|
{
|
|
Color,
|
|
Normal,
|
|
}
|
|
// Disabling Substance Deprecated warning
|
|
#pragma warning disable 0618
|
|
[Serializable]
|
|
[NodeAttributes( "Substance Sample", "Textures", "Samples a procedural material", KeyCode.None, true, 0, int.MaxValue, typeof( SubstanceGraph ), typeof( Substance.Game.Substance ) )]
|
|
public sealed class SubstanceSamplerNode : PropertyNode
|
|
{
|
|
private const string NormalMapCheck = "normal";
|
|
private const string GlobalVarDecStr = "uniform sampler2D {0};";
|
|
private const string PropertyDecStr = "{0}(\"{1}\", 2D) = \"white\"";
|
|
|
|
private const string AutoNormalStr = "Auto-Normal";
|
|
private const string SubstanceStr = "Substance";
|
|
|
|
private float TexturePreviewSizeX = 128;
|
|
private float TexturePreviewSizeY = 128;
|
|
|
|
private float PickerPreviewWidthAdjust = 18;
|
|
|
|
private bool m_editing;
|
|
|
|
private CacheNodeConnections m_cacheNodeConnections;
|
|
|
|
[SerializeField]
|
|
private int m_firstOutputConnected = 0;
|
|
|
|
[SerializeField]
|
|
private Substance.Game.SubstanceGraph m_substanceGraph;
|
|
[SerializeField]
|
|
private string m_substanceGUID = string.Empty;
|
|
|
|
[SerializeField]
|
|
private int m_textureCoordSet = 0;
|
|
|
|
[SerializeField]
|
|
private ASEProceduralOutputType[] m_textureTypes;
|
|
|
|
[SerializeField]
|
|
private bool m_autoNormal = true;
|
|
|
|
private System.Type m_type;
|
|
|
|
private List<Texture2D> m_textures = new List<Texture2D>();
|
|
|
|
private List<int> m_outputConns = new List<int>();
|
|
|
|
private Rect m_previewArea;
|
|
|
|
private Rect m_pickerArea;
|
|
|
|
protected override void CommonInit( int uniqueId )
|
|
{
|
|
base.CommonInit( uniqueId );
|
|
AddInputPort( WirePortDataType.FLOAT2, false, "UV" );
|
|
AddOutputPort( WirePortDataType.COLOR, Constants.EmptyPortValue );
|
|
m_insideSize.Set( TexturePreviewSizeX + PickerPreviewWidthAdjust, TexturePreviewSizeY + 10 );
|
|
m_type = typeof( Substance.Game.Substance );
|
|
m_currentParameterType = PropertyType.Property;
|
|
m_freeType = false;
|
|
m_freeName = false;
|
|
m_autoWrapProperties = true;
|
|
m_customPrefix = "Substance Sample ";
|
|
m_drawPrecisionUI = false;
|
|
m_showPreview = true;
|
|
m_drawPreviewExpander = false;
|
|
m_selectedLocation = PreviewLocation.TopCenter;
|
|
m_cacheNodeConnections = new CacheNodeConnections();
|
|
m_previewShaderGUID = "6f322c1da33f1e744941aafcb0ad1a2d";
|
|
m_showAutoRegisterUI = false;
|
|
}
|
|
|
|
public override void RenderNodePreview()
|
|
{
|
|
if( !m_initialized )
|
|
return;
|
|
|
|
SetPreviewInputs();
|
|
PreviewMaterial.SetInt( "_CustomUVs", m_inputPorts[ 0 ].IsConnected ? 1 : 0 );
|
|
|
|
if( m_substanceGraph == null )
|
|
return;
|
|
|
|
List<Texture2D> texs = m_substanceGraph.generatedTextures;
|
|
int count = m_outputPorts.Count;
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
RenderTexture temp = RenderTexture.active;
|
|
RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture;
|
|
|
|
PreviewMaterial.SetTexture( "_GenTex", texs[ i ] );
|
|
|
|
if( m_autoNormal && m_textureTypes[ i ] == ASEProceduralOutputType.Normal )
|
|
Graphics.Blit( null, m_outputPorts[ i ].OutputPreviewTexture, PreviewMaterial, 1 );
|
|
else
|
|
Graphics.Blit( null, m_outputPorts[ i ].OutputPreviewTexture, PreviewMaterial, 0 );
|
|
RenderTexture.active = temp;
|
|
}
|
|
}
|
|
|
|
public override void OnOutputPortConnected( int portId, int otherNodeId, int otherPortId )
|
|
{
|
|
base.OnOutputPortConnected( portId, otherNodeId, otherPortId );
|
|
m_firstOutputConnected = -1;
|
|
}
|
|
|
|
public override void OnOutputPortDisconnected( int portId )
|
|
{
|
|
base.OnOutputPortDisconnected( portId );
|
|
m_firstOutputConnected = -1;
|
|
}
|
|
|
|
void CalculateFirstOutputConnected()
|
|
{
|
|
m_outputConns.Clear();
|
|
int count = m_outputPorts.Count;
|
|
bool connectionsAvailable = false;
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
if( m_outputPorts[ i ].IsConnected )
|
|
{
|
|
connectionsAvailable = true;
|
|
}
|
|
}
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
if( connectionsAvailable )
|
|
{
|
|
if( m_outputPorts[ i ].IsConnected )
|
|
{
|
|
if( m_firstOutputConnected < 0 )
|
|
m_firstOutputConnected = i;
|
|
|
|
m_outputConns.Add( i );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_outputConns.Add( i );
|
|
}
|
|
}
|
|
|
|
if( m_firstOutputConnected < 0 )
|
|
m_firstOutputConnected = 0;
|
|
}
|
|
|
|
public override void OnNodeLayout( DrawInfo drawInfo )
|
|
{
|
|
base.OnNodeLayout( drawInfo );
|
|
|
|
m_previewArea = m_remainingBox;
|
|
m_previewArea.width = TexturePreviewSizeX * drawInfo.InvertedZoom;
|
|
m_previewArea.height = TexturePreviewSizeY * drawInfo.InvertedZoom;
|
|
m_previewArea.x += 0.5f * m_remainingBox.width - 0.5f * m_previewArea.width;
|
|
m_pickerArea = m_previewArea;
|
|
m_pickerArea.width = 40 * drawInfo.InvertedZoom;
|
|
m_pickerArea.x = m_previewArea.xMax - m_pickerArea.width - 2;
|
|
m_pickerArea.height = 14 * drawInfo.InvertedZoom;
|
|
m_pickerArea.y = m_previewArea.yMax - m_pickerArea.height - 2;
|
|
}
|
|
|
|
public override void DrawGUIControls( DrawInfo drawInfo )
|
|
{
|
|
base.DrawGUIControls( drawInfo );
|
|
|
|
if( !( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp || drawInfo.CurrentEventType == EventType.ExecuteCommand || drawInfo.CurrentEventType == EventType.DragPerform ) )
|
|
return;
|
|
|
|
bool insideBox = m_previewArea.Contains( drawInfo.MousePosition );
|
|
|
|
if( insideBox )
|
|
{
|
|
m_editing = true;
|
|
}
|
|
else if( m_editing && !insideBox && drawInfo.CurrentEventType != EventType.ExecuteCommand )
|
|
{
|
|
GUI.FocusControl( null );
|
|
m_editing = false;
|
|
}
|
|
}
|
|
|
|
|
|
public override void Draw( DrawInfo drawInfo )
|
|
{
|
|
base.Draw( drawInfo );
|
|
|
|
if( m_editing )
|
|
{
|
|
m_textures = m_substanceGraph != null ? m_substanceGraph.generatedTextures : null;
|
|
if( GUI.Button( m_pickerArea, string.Empty, GUIStyle.none ) )
|
|
{
|
|
int controlID = EditorGUIUtility.GetControlID( FocusType.Passive );
|
|
EditorGUIUtility.ShowObjectPicker<SubstanceGraph>( m_substanceGraph, false, "", controlID );
|
|
}
|
|
|
|
string commandName = Event.current.commandName;
|
|
UnityEngine.Object newValue = null;
|
|
if( commandName == "ObjectSelectorUpdated" )
|
|
{
|
|
newValue = EditorGUIUtility.GetObjectPickerObject();
|
|
if( newValue != (UnityEngine.Object)m_substanceGraph )
|
|
{
|
|
UndoRecordObject( "Changing value EditorGUIObjectField on node Substance Sample" );
|
|
|
|
SubstanceGraph = newValue != null ? (SubstanceGraph)newValue : null;
|
|
m_textures = m_substanceGraph != null ? m_substanceGraph.generatedTextures : null;
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
}
|
|
else if( commandName == "ObjectSelectorClosed" )
|
|
{
|
|
newValue = EditorGUIUtility.GetObjectPickerObject();
|
|
if( newValue != (UnityEngine.Object)m_substanceGraph )
|
|
{
|
|
UndoRecordObject( "Changing value EditorGUIObjectField on node Substance Sample" );
|
|
|
|
SubstanceGraph = newValue != null ? (SubstanceGraph)newValue : null;
|
|
m_textures = m_substanceGraph != null ? m_substanceGraph.generatedTextures : null;
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
m_editing = false;
|
|
}
|
|
|
|
if( GUI.Button( m_previewArea, string.Empty, GUIStyle.none ) )
|
|
{
|
|
if( m_substanceGraph != null )
|
|
{
|
|
Selection.activeObject = m_substanceGraph;
|
|
EditorGUIUtility.PingObject( Selection.activeObject );
|
|
}
|
|
m_editing = false;
|
|
}
|
|
}
|
|
|
|
if( drawInfo.CurrentEventType == EventType.Repaint )
|
|
{
|
|
if( !m_editing )
|
|
m_textures = m_substanceGraph != null ? m_substanceGraph.generatedTextures : null;
|
|
|
|
if( m_textures != null )
|
|
{
|
|
if( m_firstOutputConnected < 0 )
|
|
{
|
|
CalculateFirstOutputConnected();
|
|
}
|
|
else if( m_textures.Count != m_textureTypes.Length )
|
|
{
|
|
OnNewSubstanceSelected( m_textures );
|
|
}
|
|
|
|
int texCount = m_outputConns.Count;
|
|
Rect individuals = m_previewArea;
|
|
individuals.height /= texCount;
|
|
|
|
for( int i = 0; i < texCount; i++ )
|
|
{
|
|
|
|
//EditorGUI.DrawPreviewTexture( individuals, m_textures[ m_outputConns[ i ] ], null, ScaleMode.ScaleAndCrop );
|
|
EditorGUI.DrawPreviewTexture( individuals, m_outputPorts[ m_outputConns[ i ] ].OutputPreviewTexture, null, ScaleMode.ScaleAndCrop );
|
|
individuals.y += individuals.height;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GUI.Label( m_previewArea, string.Empty, UIUtils.ObjectFieldThumb );
|
|
}
|
|
|
|
if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
|
|
{
|
|
Rect smallButton = m_previewArea;
|
|
smallButton.height = 14 * drawInfo.InvertedZoom;
|
|
smallButton.y = m_previewArea.yMax - smallButton.height - 2;
|
|
smallButton.width = 40 * drawInfo.InvertedZoom;
|
|
smallButton.x = m_previewArea.xMax - smallButton.width - 2;
|
|
if( m_textures == null )
|
|
{
|
|
GUI.Label( m_previewArea, "None (Procedural Material)", UIUtils.ObjectFieldThumbOverlay );
|
|
}
|
|
GUI.Label( m_pickerArea, "Select", UIUtils.GetCustomStyle( CustomStyle.SamplerButton ) );
|
|
}
|
|
|
|
GUI.Label( m_previewArea, string.Empty, UIUtils.GetCustomStyle( CustomStyle.SamplerFrame ) );
|
|
}
|
|
}
|
|
|
|
void OnNewSubstanceSelected( List<Texture2D> textures )
|
|
{
|
|
CacheCurrentSettings();
|
|
ConfigPortsFromMaterial( true, textures );
|
|
ConnectFromCache();
|
|
m_requireMaterialUpdate = true;
|
|
CalculateFirstOutputConnected();
|
|
ContainerGraph.ParentWindow.RequestRepaint();
|
|
}
|
|
|
|
public override void DrawProperties()
|
|
{
|
|
base.DrawProperties();
|
|
EditorGUI.BeginChangeCheck();
|
|
SubstanceGraph = EditorGUILayoutObjectField( SubstanceStr, m_substanceGraph, m_type, false ) as SubstanceGraph;
|
|
if( EditorGUI.EndChangeCheck() )
|
|
{
|
|
List<Texture2D> textures = m_substanceGraph != null ? m_substanceGraph.generatedTextures : null;
|
|
if( textures != null )
|
|
{
|
|
OnNewSubstanceSelected( textures );
|
|
}
|
|
}
|
|
|
|
m_textureCoordSet = EditorGUILayoutIntPopup( Constants.AvailableUVSetsLabel, m_textureCoordSet, Constants.AvailableUVSetsStr, Constants.AvailableUVSets );
|
|
EditorGUI.BeginChangeCheck();
|
|
m_autoNormal = EditorGUILayoutToggle( AutoNormalStr, m_autoNormal );
|
|
if( EditorGUI.EndChangeCheck() )
|
|
{
|
|
for( int i = 0; i < m_textureTypes.Length; i++ )
|
|
{
|
|
WirePortDataType portType = ( m_autoNormal && m_textureTypes[ i ] == ASEProceduralOutputType.Normal ) ? WirePortDataType.FLOAT3 : WirePortDataType.COLOR;
|
|
if( m_outputPorts[ i ].DataType != portType )
|
|
{
|
|
m_outputPorts[ i ].ChangeType( portType, false );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CacheCurrentSettings()
|
|
{
|
|
m_cacheNodeConnections.Clear();
|
|
for( int portId = 0; portId < m_outputPorts.Count; portId++ )
|
|
{
|
|
if( m_outputPorts[ portId ].IsConnected )
|
|
{
|
|
int connCount = m_outputPorts[ portId ].ConnectionCount;
|
|
for( int connIdx = 0; connIdx < connCount; connIdx++ )
|
|
{
|
|
WireReference connection = m_outputPorts[ portId ].GetConnection( connIdx );
|
|
m_cacheNodeConnections.Add( m_outputPorts[ portId ].Name, new NodeCache( connection.NodeId, connection.PortId ) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ConnectFromCache()
|
|
{
|
|
for( int i = 0; i < m_outputPorts.Count; i++ )
|
|
{
|
|
List<NodeCache> connections = m_cacheNodeConnections.GetList( m_outputPorts[ i ].Name );
|
|
if( connections != null )
|
|
{
|
|
int count = connections.Count;
|
|
for( int connIdx = 0; connIdx < count; connIdx++ )
|
|
{
|
|
UIUtils.SetConnection( connections[ connIdx ].TargetNodeId, connections[ connIdx ].TargetPortId, UniqueId, i );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void ConfigPortsFromMaterial( bool invalidateConnections = false, List<Texture2D> newTextures = null )
|
|
{
|
|
SetAdditonalTitleText( ( m_substanceGraph != null ) ? string.Format( Constants.PropertyValueLabel, m_substanceGraph.name ) : "Value( <None> )" );
|
|
|
|
List<Texture2D> textures = newTextures != null ? newTextures : ( ( m_substanceGraph != null ) ? m_substanceGraph.generatedTextures : null );
|
|
if( textures != null )
|
|
{
|
|
m_firstOutputConnected = -1;
|
|
string nameToRemove = m_substanceGraph.graphLabel + "_";
|
|
m_textureTypes = new ASEProceduralOutputType[ textures.Count ];
|
|
for( int i = 0; i < textures.Count; i++ )
|
|
{
|
|
//TODO: Replace for a more efficient test as soon as Laurent gives more infos
|
|
bool isNormal = textures[ i ].format == TextureFormat.BC5 || textures[ i ].name.EndsWith( NormalMapCheck );
|
|
m_textureTypes[ i ] = isNormal?ASEProceduralOutputType.Normal:ASEProceduralOutputType.Color;
|
|
|
|
WirePortDataType portType = ( m_autoNormal && m_textureTypes[ i ] == ASEProceduralOutputType.Normal ) ? WirePortDataType.FLOAT3 : WirePortDataType.COLOR;
|
|
string newName = textures[ i ].name.Replace( nameToRemove, string.Empty );
|
|
char firstLetter = Char.ToUpper( newName[ 0 ] );
|
|
newName = firstLetter.ToString() + newName.Substring( 1 );
|
|
if( i < m_outputPorts.Count )
|
|
{
|
|
m_outputPorts[ i ].ChangeProperties( newName, portType, false );
|
|
if( invalidateConnections )
|
|
{
|
|
m_outputPorts[ i ].FullDeleteConnections();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddOutputPort( portType, newName );
|
|
}
|
|
}
|
|
|
|
if( textures.Count < m_outputPorts.Count )
|
|
{
|
|
int itemsToRemove = m_outputPorts.Count - textures.Count;
|
|
for( int i = 0; i < itemsToRemove; i++ )
|
|
{
|
|
int idx = m_outputPorts.Count - 1;
|
|
if( m_outputPorts[ idx ].IsConnected )
|
|
{
|
|
m_outputPorts[ idx ].ForceClearConnection();
|
|
}
|
|
RemoveOutputPort( idx );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int itemsToRemove = m_outputPorts.Count - 1;
|
|
m_outputPorts[ 0 ].ChangeProperties( Constants.EmptyPortValue, WirePortDataType.COLOR, false );
|
|
m_outputPorts[ 0 ].ForceClearConnection();
|
|
|
|
for( int i = 0; i < itemsToRemove; i++ )
|
|
{
|
|
int idx = m_outputPorts.Count - 1;
|
|
if( m_outputPorts[ idx ].IsConnected )
|
|
{
|
|
m_outputPorts[ idx ].ForceClearConnection();
|
|
}
|
|
RemoveOutputPort( idx );
|
|
}
|
|
}
|
|
|
|
m_sizeIsDirty = true;
|
|
m_isDirty = true;
|
|
}
|
|
|
|
private void ConfigFromObject( UnityEngine.Object obj )
|
|
{
|
|
SubstanceGraph newGraph = obj as SubstanceGraph;// AssetDatabase.LoadAssetAtPath<SubstanceGraph>( AssetDatabase.GetAssetPath( obj ) );
|
|
if( newGraph != null )
|
|
{
|
|
SubstanceGraph = newGraph;
|
|
ConfigPortsFromMaterial();
|
|
}
|
|
|
|
Substance.Game.Substance newSubstance = obj as Substance.Game.Substance;// AssetDatabase.LoadAssetAtPath<SubstanceGraph>( AssetDatabase.GetAssetPath( obj ) );
|
|
if( newSubstance != null && newSubstance.graphs.Count > 0 )
|
|
{
|
|
SubstanceGraph = newSubstance.graphs[0];
|
|
ConfigPortsFromMaterial();
|
|
}
|
|
|
|
}
|
|
|
|
public override void OnObjectDropped( UnityEngine.Object obj )
|
|
{
|
|
ConfigFromObject( obj );
|
|
}
|
|
|
|
public override void SetupFromCastObject( UnityEngine.Object obj )
|
|
{
|
|
ConfigFromObject( obj );
|
|
}
|
|
|
|
public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
|
|
{
|
|
if( m_substanceGraph == null )
|
|
{
|
|
return "(0).xxxx";
|
|
}
|
|
|
|
if( m_outputPorts[ outputId ].IsLocalValue( dataCollector.PortCategory ) )
|
|
{
|
|
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
|
}
|
|
|
|
List<Texture2D> textures = m_substanceGraph.generatedTextures;
|
|
|
|
string uvPropertyName = string.Empty;
|
|
for( int i = 0; i < m_outputPorts.Count; i++ )
|
|
{
|
|
if( m_outputPorts[ i ].HasConnectedNode )
|
|
{
|
|
uvPropertyName = UIUtils.GeneratePropertyName( textures[ i ].name , PropertyType.Property );
|
|
break;
|
|
}
|
|
}
|
|
|
|
string propertyName = UIUtils.GeneratePropertyName( textures[ outputId ].name, PropertyType.Property );
|
|
string name = propertyName + OutputId;
|
|
dataCollector.AddToUniforms( UniqueId, string.Format( GlobalVarDecStr, propertyName ) );
|
|
dataCollector.AddToProperties( UniqueId, string.Format( PropertyDecStr, propertyName, textures[ outputId ].name ) + "{}", -1 );
|
|
bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation );
|
|
string value = string.Format( "tex2D{0}({1}, {2})", ( isVertex ? "lod" : string.Empty ), propertyName, GetUVCoords( ref dataCollector, ignoreLocalvar, uvPropertyName ) );
|
|
if( m_autoNormal && m_textureTypes[ outputId ] == ASEProceduralOutputType.Normal )
|
|
{
|
|
value = GeneratorUtils.GenerateUnpackNormalStr( ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, value, false, "1.0" );
|
|
}
|
|
|
|
dataCollector.AddPropertyNode( this );
|
|
RegisterLocalVariable( outputId, value, ref dataCollector, name );
|
|
|
|
return m_outputPorts[ outputId ].LocalValue( dataCollector.PortCategory );
|
|
}
|
|
|
|
public string GetUVCoords( ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar, string propertyName )
|
|
{
|
|
bool isVertex = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation );
|
|
if( m_inputPorts[ 0 ].IsConnected )
|
|
{
|
|
return m_inputPorts[ 0 ].GenerateShaderForOutput( ref dataCollector, isVertex ? WirePortDataType.FLOAT4 : WirePortDataType.FLOAT2, ignoreLocalVar, true );
|
|
}
|
|
else
|
|
{
|
|
string uvChannelName = IOUtils.GetUVChannelName( propertyName, m_textureCoordSet );
|
|
|
|
if( dataCollector.IsTemplate )
|
|
{
|
|
string propertyHelperVar = propertyName + "_ST";
|
|
dataCollector.AddToUniforms( UniqueId, "float4", propertyHelperVar, dataCollector.IsSRP );
|
|
string uvName = string.Empty;
|
|
string result = string.Empty;
|
|
if( dataCollector.TemplateDataCollectorInstance.GetCustomInterpolatedData( TemplateHelperFunctions.IntToUVChannelInfo[ m_textureCoordSet ], WirePortDataType.FLOAT4, PrecisionType.Float, ref result, false, dataCollector.PortCategory ) )
|
|
{
|
|
if( m_inputPorts[ 0 ].DataType != WirePortDataType.FLOAT4 )
|
|
result += UIUtils.GetAutoSwizzle( m_inputPorts[ 0 ].DataType );
|
|
uvName = result;
|
|
}
|
|
else
|
|
if( dataCollector.TemplateDataCollectorInstance.HasUV( m_textureCoordSet ) )
|
|
{
|
|
uvName = dataCollector.TemplateDataCollectorInstance.GetUVName( m_textureCoordSet );
|
|
}
|
|
else
|
|
{
|
|
uvName = dataCollector.TemplateDataCollectorInstance.RegisterUV( m_textureCoordSet );
|
|
}
|
|
|
|
uvChannelName = "uv" + propertyName;
|
|
if( isVertex )
|
|
{
|
|
string value = string.Format( Constants.TilingOffsetFormat, uvName, propertyHelperVar + ".xy", propertyHelperVar + ".zw" );
|
|
string lodLevel = "0";
|
|
|
|
value = "float4( " + value + ", 0 , " + lodLevel + " )";
|
|
dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT4, uvChannelName, value );
|
|
}
|
|
else
|
|
{
|
|
dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT2, uvChannelName, string.Format( Constants.TilingOffsetFormat, uvName, propertyHelperVar + ".xy", propertyHelperVar + ".zw" ) );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string vertexCoords = Constants.VertexShaderInputStr + ".texcoord";
|
|
if( m_textureCoordSet > 0 )
|
|
{
|
|
vertexCoords += m_textureCoordSet.ToString();
|
|
}
|
|
|
|
|
|
string dummyPropUV = "_texcoord" + ( m_textureCoordSet > 0 ? ( m_textureCoordSet + 1 ).ToString() : "" );
|
|
string dummyUV = "uv" + ( m_textureCoordSet > 0 ? ( m_textureCoordSet + 1 ).ToString() : "" ) + dummyPropUV;
|
|
|
|
dataCollector.AddToUniforms( UniqueId, "uniform float4 " + propertyName + "_ST;" );
|
|
dataCollector.AddToProperties( UniqueId, "[HideInInspector] " + dummyPropUV + "( \"\", 2D ) = \"white\" {}", 100 );
|
|
dataCollector.AddToInput( UniqueId, dummyUV, WirePortDataType.FLOAT2 );
|
|
|
|
if( isVertex )
|
|
{
|
|
dataCollector.AddToVertexLocalVariables( UniqueId, "float4 " + uvChannelName + " = float4(" + vertexCoords + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw, 0 ,0);" );
|
|
return uvChannelName;
|
|
}
|
|
else
|
|
dataCollector.AddToLocalVariables( UniqueId, PrecisionType.Float, WirePortDataType.FLOAT2, uvChannelName, Constants.InputVarStr + "." + dummyUV + " * " + propertyName + "_ST.xy + " + propertyName + "_ST.zw" );
|
|
|
|
}
|
|
|
|
return uvChannelName;
|
|
}
|
|
}
|
|
|
|
public override void UpdateMaterial( Material mat )
|
|
{
|
|
base.UpdateMaterial( mat );
|
|
if( m_substanceGraph != null )
|
|
{
|
|
List<Texture2D> textures = m_substanceGraph.generatedTextures;
|
|
for( int i = 0; i < textures.Count; i++ )
|
|
{
|
|
string textureName = UIUtils.GeneratePropertyName( textures[ i ].name, PropertyType.Property );
|
|
if( mat.HasProperty( textureName ) && !InsideShaderFunction )
|
|
{
|
|
mat.SetTexture( textureName, textures[ i ] );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool UpdateShaderDefaults( ref Shader shader, ref TextureDefaultsDataColector defaultCol )
|
|
{
|
|
if( m_substanceGraph != null )
|
|
{
|
|
List<Texture2D> textures = m_substanceGraph.generatedTextures;
|
|
for( int i = 0; i < textures.Count; i++ )
|
|
{
|
|
defaultCol.AddValue( UIUtils.GeneratePropertyName( textures[ i ].name, PropertyType.Property ), textures[ i ] );
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void OnNodeLogicUpdate( DrawInfo drawInfo )
|
|
{
|
|
base.OnNodeLogicUpdate( drawInfo );
|
|
if( m_substanceGraph == null && !string.IsNullOrEmpty( m_substanceGUID ) )
|
|
{
|
|
SubstanceGraph = AssetDatabase.LoadAssetAtPath<SubstanceGraph>( AssetDatabase.GUIDToAssetPath( m_substanceGUID ) );
|
|
if( m_substanceGraph == null )
|
|
{
|
|
m_substanceGUID = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Destroy()
|
|
{
|
|
base.Destroy();
|
|
m_textures = null;
|
|
m_substanceGraph = null;
|
|
m_substanceGUID = string.Empty;
|
|
m_cacheNodeConnections.Clear();
|
|
m_cacheNodeConnections = null;
|
|
m_outputConns.Clear();
|
|
m_outputConns = null;
|
|
}
|
|
|
|
public override string GetPropertyValStr()
|
|
{
|
|
return m_substanceGraph ? m_substanceGraph.name : string.Empty;
|
|
}
|
|
|
|
public override void ReadFromString( ref string[] nodeParams )
|
|
{
|
|
base.ReadFromString( ref nodeParams );
|
|
string guid = GetCurrentParam( ref nodeParams );
|
|
m_textureCoordSet = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
|
|
m_autoNormal = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
|
|
if( guid.Length > 1 )
|
|
{
|
|
SubstanceGraph = AssetDatabase.LoadAssetAtPath<SubstanceGraph>( AssetDatabase.GUIDToAssetPath( guid ) );
|
|
if( m_substanceGraph != null )
|
|
{
|
|
ConfigPortsFromMaterial();
|
|
}
|
|
else
|
|
{
|
|
UIUtils.ShowMessage( "Substance not found ", MessageSeverity.Error );
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
|
|
{
|
|
base.WriteToString( ref nodeInfo, ref connectionsInfo );
|
|
string guid = ( m_substanceGraph != null ) ? AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_substanceGraph ) ) : "0";
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, guid );
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, m_textureCoordSet );
|
|
IOUtils.AddFieldValueToString( ref nodeInfo, m_autoNormal );
|
|
}
|
|
|
|
public override void RefreshExternalReferences()
|
|
{
|
|
base.RefreshExternalReferences();
|
|
if( m_substanceGraph != null )
|
|
{
|
|
int count = m_outputPorts.Count;
|
|
for( int i = 0; i < count; i++ )
|
|
{
|
|
if( m_autoNormal && m_textureTypes[ i ] == ASEProceduralOutputType.Normal )
|
|
m_outputPorts[ i ].ChangeType( WirePortDataType.FLOAT3, false );
|
|
else
|
|
m_outputPorts[ i ].ChangeType( WirePortDataType.FLOAT4, false );
|
|
}
|
|
}
|
|
}
|
|
|
|
public SubstanceGraph SubstanceGraph
|
|
{
|
|
set
|
|
{
|
|
m_substanceGraph = value;
|
|
if( value != null )
|
|
{
|
|
m_substanceGUID = AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( value ) );
|
|
}
|
|
else
|
|
{
|
|
m_substanceGUID = string.Empty;
|
|
}
|
|
}
|
|
get { return m_substanceGraph; }
|
|
}
|
|
}
|
|
#pragma warning restore 0618
|
|
}
|
|
#endif
|