浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Eduardo Chaves
8 年前
当前提交
0abd0951
共有 25 个文件被更改,包括 1181 次插入 和 1 次删除
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
9MaterialGraphProject/Assets/Brandon.meta
-
1MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
-
9MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta
-
328MaterialGraphProject/Assets/TestAssets/Swirl.tga
-
75MaterialGraphProject/Assets/TestAssets/Swirl.tga.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureLODNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureLODNodePresenter.cs.meta
-
9MaterialGraphProject/Assets/Vlad.meta
-
184MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs
-
12MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs.meta
-
42MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs
-
12MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs.meta
-
9MaterialGraphProject/Assets/Rinaldo/Editor.meta
-
44MaterialGraphProject/Assets/Rinaldo/Editor/BlendModeNodePresenter.cs
-
12MaterialGraphProject/Assets/Rinaldo/Editor/BlendModeNodePresenter.cs.meta
-
13MaterialGraphProject/Assets/Vlad/SaturateNode.cs
-
12MaterialGraphProject/Assets/Vlad/SaturateNode.cs.meta
-
251MaterialGraphProject/Assets/Vlad/TextureLODNode.cs
-
12MaterialGraphProject/Assets/Vlad/TextureLODNode.cs.meta
-
69MaterialGraphProject/Assets/Vlad/UVRotatorNode.cs
-
12MaterialGraphProject/Assets/Vlad/UVRotatorNode.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: fa558cffd4da3284094239ece7c77127 |
|||
folderAsset: yes |
|||
timeCreated: 1495479460 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
{"m_SerializableNodes":[],"m_SerializableEdges":[],"m_ActiveMasterNodeGUIDSerialized":"49382d1d-b29d-4bfa-ab55-3526be874cd8"} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0e5edf7e3bc2bbc47bdb6b74107cc104 |
|||
timeCreated: 1495479560 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
328
MaterialGraphProject/Assets/TestAssets/Swirl.tga
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 0da4510083767274585ac7a4e01401dc |
|||
timeCreated: 1495479493 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
class TextureLODContolPresenter : GraphControlPresenter |
|||
{ |
|||
private string[] m_TextureTypeNames; |
|||
private string[] textureTypeNames |
|||
{ |
|||
get |
|||
{ |
|||
if (m_TextureTypeNames == null) |
|||
m_TextureTypeNames = Enum.GetNames(typeof(TextureType)); |
|||
return m_TextureTypeNames; |
|||
} |
|||
} |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var tNode = node as UnityEngine.MaterialGraph.TextureLODNode; |
|||
if (tNode == null) |
|||
return; |
|||
|
|||
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState); |
|||
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D; |
|||
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup); |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class TextureLODNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<TextureLODContolPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b88516d1f6b67f04a829309466d6aa50 |
|||
timeCreated: 1495479478 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ea5b5394ff8b04146abae74a39fd167a |
|||
folderAsset: yes |
|||
timeCreated: 1495479460 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Art/BlendMode")] |
|||
public class BlendModeNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
public BlendModeNode() |
|||
{ |
|||
name = "BlendMode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_blendmode_" + precision; |
|||
} |
|||
|
|||
[SerializeField] |
|||
private BlendModesEnum m_BlendMode; |
|||
public BlendModesEnum blendMode |
|||
{ |
|||
get { return m_BlendMode; } |
|||
set |
|||
{ |
|||
if (m_BlendMode == value) |
|||
return; |
|||
|
|||
m_BlendMode = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
// var vector3one = precision+ "3(1.0, 1.0, 1.0);
|
|||
switch (m_BlendMode) |
|||
{ |
|||
case BlendModesEnum.Burn: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
// outputString.AddShaderChunk("return "+precision+ "3(1.0,1.0,1.0) - (" + precision + "3(1.0,1.0,1.0) - arg2)/arg1;", false);
|
|||
outputString.AddShaderChunk("return 1.0 - (1.0 - arg2)/arg1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Darken: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return min(arg2,arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Difference: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return abs(arg2-arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Dodge: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg2 / (" + precision + "3(1.0,1.0,1.0) - arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Exclusion: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg2 + arg1 - (" + precision + "3(2.0,2.0,2.0)*arg2*arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.HardLight: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result1 = 1.0 - 2.0 * (1.0 - arg1) * (1.0 - arg2);", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result2 = 2.0 * arg1 * arg2;", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg1, 0.5);", false); |
|||
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Lighten: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return max(arg2,arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Multiply: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return arg1 * arg2;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Negation: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("return 1.0 - abs(1.0 - arg2 - arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.Overlay: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result1 = 1.0 - 2.0 * (1.0 - arg1) * (1.0 - arg2);", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result2 = 2.0 * arg1 * arg2;", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg2, 0.5);", false); |
|||
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
/* case BlendModesEnum.Overlay: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result1 = 2.0 * arg1 * arg2;", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result2 = 1.0 - 2.0 * (1.0 - arg1) * (1.0 - arg2);", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg2, 0.5);", false); |
|||
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
*/ |
|||
case BlendModesEnum.Screen: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
// outputString.AddShaderChunk("return " + precision + "3(1.0, 1.0, 1.0) - ((" + precision + "3(1.0, 1.0, 1.0)-arg2) * (" + precision + "3(1.0, 1.0, 1.0) - arg1));", false);
|
|||
outputString.AddShaderChunk("return 1.0 - (1.0-arg2) * (1.0 - arg1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
case BlendModesEnum.SoftLight: |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result2= 2.0 * arg2 * arg1 + arg2*arg2 - 2.0 * arg2*arg2*arg1;", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " result1= 2.0* sqrt(arg2) * arg1 - sqrt(arg2) + 2.0 * arg2 - 2.0 * arg2*arg1;", false); |
|||
outputString.AddShaderChunk(precision + outputDimension + " zeroOrOne = step(arg2, 0.5);", false); |
|||
outputString.AddShaderChunk("return result2 * zeroOrOne + (1 - zeroOrOne) * result1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
break; |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 1aa4fa75c826d8d409b5033a6ef686eb |
|||
timeCreated: 1495456651 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public enum BlendModesEnum |
|||
{ |
|||
Burn, |
|||
Dodge, |
|||
Darken, |
|||
Difference, |
|||
// Divide,
|
|||
Exclusion, |
|||
HardLight, |
|||
// HardMix,
|
|||
Lighten, |
|||
// LinearDodge,
|
|||
// LinearLight,
|
|||
// LinearBurn,
|
|||
Multiply, |
|||
Negation, |
|||
Overlay, |
|||
// PinLight,
|
|||
Screen, |
|||
SoftLight, |
|||
// Substract,
|
|||
// VividLight
|
|||
|
|||
|
|||
/* Old Order |
|||
Multiply |
|||
Screen |
|||
Darken |
|||
Lighten |
|||
Difference |
|||
Negation |
|||
Exclusion |
|||
Overlay |
|||
HardLight |
|||
SoftLight |
|||
Dodge (ColorDodge) |
|||
Burn (ColorBurn) |
|||
*/ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e377212826a27da4f9cbf888b0c39bc9 |
|||
timeCreated: 1495455807 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c0e473d1ac839c408f697d31a4e1c14 |
|||
folderAsset: yes |
|||
timeCreated: 1495456613 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
[Serializable] |
|||
class BlendModeNodeControlPresenter : GraphControlPresenter |
|||
{ |
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var cNode = node as BlendModeNode; |
|||
if (cNode == null) |
|||
return; |
|||
|
|||
cNode.blendMode = (BlendModesEnum)EditorGUILayout.EnumPopup("Mode", cNode.blendMode); |
|||
} |
|||
|
|||
/* public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
*/ |
|||
public override float GetHeight() |
|||
{ |
|||
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class BlendModeNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<BlendModeNodeControlPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cebc29fc489af774fbf2b756ba815122 |
|||
timeCreated: 1495456482 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Saturate")] |
|||
class SaturateNode : Function1Input |
|||
{ |
|||
public SaturateNode() |
|||
{ |
|||
name = "SaturateNode"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() { return "saturate"; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fb36f8243cc0c1b4b862405cc67fa2d1 |
|||
timeCreated: 1495454549 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/TextureLOD")] |
|||
public class TextureLODNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
protected const string kUVSlotName = "UV"; |
|||
protected const string kLODSlotName = "MipMap Level"; |
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
protected const string kOutputSlotRName = "R"; |
|||
protected const string kOutputSlotGName = "G"; |
|||
protected const string kOutputSlotBName = "B"; |
|||
protected const string kOutputSlotAName = "A"; |
|||
|
|||
public const int UvSlotId = 0; |
|||
public const int LODSlotId = 1; |
|||
public const int OutputSlotRgbaId = 2; |
|||
public const int OutputSlotRId = 3; |
|||
public const int OutputSlotGId = 4; |
|||
public const int OutputSlotBId = 5; |
|||
public const int OutputSlotAId = 6; |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture2D texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture2D defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture2D defaultTexture { get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
|
|||
|
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public TextureLODNode() |
|||
{ |
|||
name = "TextureLOD"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(LODSlotId, kLODSlotName, kLODSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, false)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId, LODSlotId }; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
var lodSlot = FindInputSlot<MaterialSlot>(LODSlotId); |
|||
|
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
if (lodSlot == null) |
|||
return; |
|||
|
|||
var uvName = string.Format("{0}", UVChannel.uv0.GetUVName()); |
|||
var lodName = ""; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
var edgesLOD = owner.GetEdges(lodSlot.slotReference).ToList(); |
|||
|
|||
if (edges.Count > 0) |
|||
{ |
|||
var edge = edges[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
if (edgesLOD.Count > 0) |
|||
{ |
|||
var edge = edgesLOD[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
lodName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector1, true); |
|||
} |
|||
|
|||
//if no input is specified, default to mipmap 0
|
|||
else |
|||
lodName = "0"; |
|||
|
|||
string body = "tex2Dlod (" + propertyName + ", " + precision + "4(" + uvName + ".x," + uvName + ".y, 0," + lodName + "));"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true); |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
string slotOutput; |
|||
switch (slotId) |
|||
{ |
|||
case OutputSlotRId: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case OutputSlotGId: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case OutputSlotBId: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case OutputSlotAId: |
|||
slotOutput = ".a"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return GetVariableNameForNode() + slotOutput; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true); |
|||
} |
|||
|
|||
/* |
|||
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot != inputSlot) |
|||
return base.DrawSlotDefaultInput(rect, inputSlot); |
|||
|
|||
|
|||
var rectXmax = rect.xMax; |
|||
rect.x = rectXmax - 70; |
|||
rect.width = 70; |
|||
|
|||
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
|||
GUI.Label(rect, "From Mesh"); |
|||
|
|||
return false; |
|||
} |
|||
*/ |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture2D, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture2D; } } |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: de67f89f61845a24ba6f9a8ef1cd280c |
|||
timeCreated: 1495461822 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/UVOperations/Rotator")] |
|||
public class UVRotatorNode : Function2Input, IGeneratesFunction |
|||
{ |
|||
private const string kUVSlotName = "UV"; |
|||
private const string kRotationSlotName = "Rotation"; |
|||
|
|||
public UVRotatorNode() |
|||
{ |
|||
name = "UVRotator"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_uvrotator_" + precision; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(InputSlot1Id, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector4, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(InputSlot2Id, kRotationSlotName, kRotationSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, kUVSlotName, kUVSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero); |
|||
} |
|||
|
|||
//TODO:Externalize
|
|||
//Reference code from:http://www.chilliant.com/rgb2hsv.html
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
//center texture's pivot
|
|||
outputString.AddShaderChunk("arg1.xy -= 0.5;", false); |
|||
|
|||
//rotation matrix
|
|||
outputString.AddShaderChunk(precision + " s = sin(arg2);", false); |
|||
outputString.AddShaderChunk(precision + " c = cos(arg2);", false); |
|||
outputString.AddShaderChunk(precision + "2x2 rMatrix = float2x2(c, -s, s, c);", false); |
|||
|
|||
//center rotation matrix
|
|||
outputString.AddShaderChunk("rMatrix *= 0.5;", false); |
|||
outputString.AddShaderChunk("rMatrix += 0.5;", false); |
|||
outputString.AddShaderChunk("rMatrix = rMatrix*2 - 1;", false); |
|||
|
|||
//multiply the UVs by the rotation matrix
|
|||
outputString.AddShaderChunk("arg1.xy = mul(arg1.xy, rMatrix);", false); |
|||
outputString.AddShaderChunk("arg1.xy += 0.5;", false); |
|||
|
|||
outputString.AddShaderChunk("return " + "arg1;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e3897f68a598da34aa8bd55a3a3236ab |
|||
timeCreated: 1495456132 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue