Tim Cooper
7 年前
当前提交
54ac74c0
共有 148 个文件被更改,包括 3237 次插入 和 883 次删除
-
1.gitignore
-
50MaterialGraphProject/Assets/Beachball.ShaderGraph
-
6MaterialGraphProject/Assets/Beachball.mat
-
21MaterialGraphProject/Assets/NewNodes/Editor/Keep/HeightToNormalNode.cs
-
2MaterialGraphProject/Assets/NewNodes/Editor/Kill/CheckerboardNode.cs
-
332MaterialGraphProject/Assets/PartyPreview.ShaderGraph
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs
-
83MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/FloatShaderProperty.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialGraph.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2ShaderProperty.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3ShaderProperty.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4ShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ContrastNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SplitNode.cs
-
254MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SwizzleNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/IMasterNode.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DAssetNode.cs
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/MasterNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LengthNode.cs
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Procedural/CheckerboardNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/LayeredShaderGraph.cs
-
48MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/SurfaceMaterialOptions.cs
-
27MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs
-
51MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs
-
42MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/GraphDropTarget.cs
-
80MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
193MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
66MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/PortInputView.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs
-
22MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporterEditor.cs
-
126MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
-
108MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightUnlitPass.template
-
8MaterialGraphProject/Assets/graphs_PartyPreview.mat
-
15MaterialGraphProject/ProjectSettings/EditorSettings.asset
-
2MaterialGraphProject/ProjectSettings/GraphicsSettings.asset
-
2MaterialGraphProject/ProjectSettings/ProjectVersion.txt
-
5MaterialGraphProject/UnityPackageManager/manifest.json
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/LightWeightShaderPaths.cs.meta
-
46MaterialGraphProject/Assets/UnityShaderEditor/Editor/SerializableGraph/Implementation/NodeUtils.cs
-
33MaterialGraphProject/Assets/LightweightAsset.asset
-
8MaterialGraphProject/Assets/LightweightAsset.asset.meta
-
4MaterialGraphProject/Assets/UnityShaderEditor/.npmignore
-
79MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapInputMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapInputMaterialSlot.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapMaterialSlot.cs.meta
-
66MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs.meta
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs.meta
-
282MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs.meta
-
208MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs.meta
-
165MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs.meta
-
79MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/UnlitMasterNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/UnlitMasterNode.cs.meta
-
166MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ChannelMixerNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ChannelMixerNode.cs.meta
-
38MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ReplaceColorNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ReplaceColorNode.cs.meta
-
71MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/WhiteBalanceNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/WhiteBalanceNode.cs.meta
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask.meta
-
188MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/FlipNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/FlipNode.cs.meta
-
78MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs.meta
-
81MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs.meta
-
79MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelEnumControl.cs.meta
-
141MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelMixerControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelMixerControl.cs.meta
-
55MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/CubemapControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/CubemapControl.cs.meta
-
86MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ToggleControl.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ToggleControl.cs.meta
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/CubemapSlotControlView.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/CubemapSlotControlView.cs.meta
50
MaterialGraphProject/Assets/Beachball.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
332
MaterialGraphProject/Assets/PartyPreview.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEditor.Graphing; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
/* [Title("Channel/Swizzle")] |
|||
public class SwizzleNode : Function1Input |
|||
{ |
|||
public enum SwizzleChannel |
|||
{ |
|||
R = 0, |
|||
G = 1, |
|||
B = 2, |
|||
A = 3, |
|||
} |
|||
[Title("Channel/Swizzle")] |
|||
public class SwizzleNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
public SwizzleNode() |
|||
{ |
|||
name = "Swizzle"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
[SerializeField] |
|||
private SwizzleChannel[] m_SwizzleChannels = new SwizzleChannel[4] { SwizzleChannel.R, SwizzleChannel.G, SwizzleChannel.B, SwizzleChannel.A }; |
|||
const int InputSlotId = 0; |
|||
const int OutputSlotId = 1; |
|||
const string kInputSlotName = "In"; |
|||
const string kOutputSlotName = "Out"; |
|||
public SwizzleChannel[] swizzleChannels |
|||
{ |
|||
get { return m_SwizzleChannels; } |
|||
set |
|||
{ |
|||
if (m_SwizzleChannels == value) |
|||
return; |
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
m_SwizzleChannels = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
string GetFunctionName() |
|||
{ |
|||
return "Unity_Swizzle_" + precision + "_" + GuidEncoder.Encode(guid); |
|||
} |
|||
public SwizzleNode() |
|||
{ |
|||
name = "Swizzle"; |
|||
} |
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId }); |
|||
} |
|||
protected override string GetFunctionName() |
|||
{ |
|||
return ""; |
|||
} |
|||
static Dictionary<TextureChannel, string> m_ComponentList = new Dictionary<TextureChannel, string> |
|||
{ |
|||
{TextureChannel.Red, ".r" }, |
|||
{TextureChannel.Green, ".g" }, |
|||
{TextureChannel.Blue, ".b" }, |
|||
{TextureChannel.Alpha, ".a" }, |
|||
}; |
|||
protected override string GetFunctionCallBody(string inputValue) |
|||
{ |
|||
string[] channelNames = { "r", "g", "b", "a" }; |
|||
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId); |
|||
var outputSlot = FindOutputSlot<MaterialSlot>(OutputSlotId); |
|||
[SerializeField] |
|||
private TextureChannel m_RedChannel; |
|||
if (inputSlot == null) |
|||
return "1.0"; |
|||
if (outputSlot == null) |
|||
return "1.0"; |
|||
[ChannelEnumControl("Red Out")] |
|||
public TextureChannel redChannel |
|||
{ |
|||
get { return m_RedChannel; } |
|||
set |
|||
{ |
|||
if (m_RedChannel == value) |
|||
return; |
|||
int numInputChannels = (int)SlotValueHelper.GetChannelCount(inputSlot.concreteValueType); |
|||
int numOutputChannels = (int)SlotValueHelper.GetChannelCount(outputSlot.concreteValueType); |
|||
m_RedChannel = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
//int numInputChannels = (int)inputSlot.concreteValueType;
|
|||
int numOutputChannels = (int)outputSlot.concreteValueType; |
|||
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0) |
|||
numInputChannels = 0; |
|||
if (owner.GetEdges(outputSlot.slotReference).ToList().Count() == 0) |
|||
numOutputChannels = 0; |
|||
[SerializeField] |
|||
private TextureChannel m_GreenChannel; |
|||
if (numOutputChannels == 0) |
|||
{ |
|||
return "1.0"; |
|||
} |
|||
[ChannelEnumControl("Green Out")] |
|||
public TextureChannel greenChannel |
|||
{ |
|||
get { return m_GreenChannel; } |
|||
set |
|||
{ |
|||
if (m_GreenChannel == value) |
|||
return; |
|||
string outputString = precision + "4("; |
|||
//float4(1.0,1.0,1.0,1.0)
|
|||
if (numInputChannels == 0) |
|||
{ |
|||
outputString += "1.0, 1.0, 1.0, 1.0)."; |
|||
} |
|||
else |
|||
{ |
|||
//float4(arg1.
|
|||
outputString += inputValue + "."; |
|||
m_GreenChannel = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private TextureChannel m_BlueChannel; |
|||
|
|||
[ChannelEnumControl("Blue Out")] |
|||
public TextureChannel blueChannel |
|||
{ |
|||
get { return m_BlueChannel; } |
|||
set |
|||
{ |
|||
if (m_BlueChannel == value) |
|||
return; |
|||
|
|||
m_BlueChannel = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private TextureChannel m_AlphaChannel; |
|||
|
|||
[ChannelEnumControl("Alpha Out")] |
|||
public TextureChannel alphaChannel |
|||
{ |
|||
get { return m_AlphaChannel; } |
|||
set |
|||
{ |
|||
if (m_AlphaChannel == value) |
|||
return; |
|||
|
|||
m_AlphaChannel = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ValidateChannelCount() |
|||
{ |
|||
int channelCount = (int)SlotValueHelper.GetChannelCount(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); |
|||
if ((int)redChannel >= channelCount) |
|||
redChannel = TextureChannel.Red; |
|||
if ((int)greenChannel >= channelCount) |
|||
greenChannel = TextureChannel.Red; |
|||
if ((int)blueChannel >= channelCount) |
|||
blueChannel = TextureChannel.Red; |
|||
if ((int)alphaChannel >= channelCount) |
|||
alphaChannel = TextureChannel.Red; |
|||
} |
|||
|
|||
string GetFunctionPrototype(string inArg, string outArg) |
|||
{ |
|||
return string.Format("void {0} ({1} {2}, out {3} {4})", GetFunctionName(), |
|||
ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), inArg, |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), outArg); |
|||
} |
|||
//float4(arg1.xy
|
|||
int i = 0; |
|||
for (; i < numInputChannels; ++i) |
|||
{ |
|||
int channel = (int)m_SwizzleChannels[i]; |
|||
outputString += channelNames[channel]; |
|||
} |
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
ValidateChannelCount(); |
|||
string inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
string outputValue = GetSlotValue(OutputSlotId, generationMode); |
|||
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true); |
|||
visitor.AddShaderChunk(GetFunctionCallBody(inputValue, outputValue), true); |
|||
} |
|||
|
|||
string GetFunctionCallBody(string inputValue, string outputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ", " + outputValue + ");"; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
ValidateChannelCount(); |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("In", "Out"), true); |
|||
outputString.AddShaderChunk("{", true); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk(string.Format("Out = {0} ({1}, {2}, {3}, {4});", |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), |
|||
kInputSlotName + m_ComponentList[m_RedChannel], |
|||
kInputSlotName + m_ComponentList[m_GreenChannel], |
|||
kInputSlotName + m_ComponentList[m_BlueChannel], |
|||
kInputSlotName + m_ComponentList[m_AlphaChannel]), true); |
|||
//float4(arg1.xy, 1.0, 1.0)
|
|||
for (; i < 4; i++) |
|||
{ |
|||
outputString += ", 1.0"; |
|||
} |
|||
outputString += ")."; |
|||
} |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", true); |
|||
//float4(arg1.xy, 1.0, 1.0).rg
|
|||
for (int j = 0; j < numOutputChannels; ++j) |
|||
{ |
|||
outputString += channelNames[j]; |
|||
} |
|||
return outputString; |
|||
} |
|||
}*/ |
|||
} |
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
SubShader |
|||
Pass |
|||
Tags{"RenderType" = "Opaque" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipeline"} |
|||
LOD ${LOD} |
|||
Tags{"LightMode" = "LightweightForward"} |
|||
${Tags} |
|||
${Blending} |
|||
${Culling} |
|||
${ZTest} |
|||
${ZWrite} |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#pragma multi_compile_fog |
|||
#pragma multi_compile_instancing |
|||
Pass |
|||
{ |
|||
Tags{"LightMode" = "LightweightForward"} |
|||
${Tags} |
|||
${Blending} |
|||
${Culling} |
|||
${ZTest} |
|||
${ZWrite} |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#pragma multi_compile_fog |
|||
#pragma multi_compile_instancing |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma glsl |
|||
#pragma debug |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma glsl |
|||
#pragma debug |
|||
#include "UnityCG.cginc" |
|||
#include "UnityCG.cginc" |
|||
${Defines} |
|||
${Defines} |
|||
${Graph} |
|||
struct GraphVertexOutput |
|||
{ |
|||
float4 position : POSITION; |
|||
${Interpolators} |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
struct GraphVertexOutput |
|||
{ |
|||
float4 position : POSITION; |
|||
${Interpolators} |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
GraphVertexOutput vert (GraphVertexInput v) |
|||
{ |
|||
v = PopulateVertexData(v); |
|||
|
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
GraphVertexOutput vert (GraphVertexInput v) |
|||
{ |
|||
v = PopulateVertexData(v); |
|||
|
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
GraphVertexOutput o; |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.position = UnityObjectToClipPos(v.vertex); |
|||
${VertexShader} |
|||
return o; |
|||
} |
|||
GraphVertexOutput o; |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.position = UnityObjectToClipPos(v.vertex); |
|||
${VertexShader} |
|||
return o; |
|||
} |
|||
fixed4 frag (GraphVertexOutput IN) : SV_Target |
|||
{ |
|||
${LocalPixelShader} |
|||
|
|||
SurfaceInputs surfaceInput; |
|||
${SurfaceInputs} |
|||
fixed4 frag (GraphVertexOutput IN) : SV_Target |
|||
{ |
|||
${LocalPixelShader} |
|||
|
|||
SurfaceInputs surfaceInput; |
|||
${SurfaceInputs} |
|||
SurfaceDescription surf = PopulateSurfaceData(surfaceInput); |
|||
float3 Color = 0; |
|||
float3 Alpha = 0; |
|||
${SurfaceOutputRemap} |
|||
|
|||
#ifdef _ALPHABLEND_ON |
|||
return fixed4(Color, Alpha); |
|||
#else |
|||
return fixed4(Color, 1.0); |
|||
#endif |
|||
} |
|||
ENDCG |
|||
SurfaceDescription surf = PopulateSurfaceData(surfaceInput); |
|||
float3 Color = 0; |
|||
float Alpha = 0; |
|||
${SurfaceOutputRemap} |
|||
|
|||
return fixed4(Color, Alpha); |
|||
ENDCG |
|||
} |
|
|||
m_EditorVersion: 2018.1.0a6 |
|||
m_EditorVersion: 2018.1.0a7 |
|
|||
{ |
|||
"registry": "https://staging-packages.unity.com", |
|||
"com.unity.render-pipelines.core" : "0.1.11", |
|||
"com.unity.render-pipelines.lightweight" : "0.1.11" |
|||
} |
|||
} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3} |
|||
m_Name: LightweightAsset |
|||
m_EditorClassIdentifier: |
|||
m_MaxPixelLights: 4 |
|||
m_SupportsVertexLight: 0 |
|||
m_SupportSoftParticles: 0 |
|||
m_MSAA: 4 |
|||
m_RenderScale: 1 |
|||
m_ShadowType: 1 |
|||
m_ShadowAtlasResolution: 1024 |
|||
m_ShadowNearPlaneOffset: 2 |
|||
m_ShadowDistance: 50 |
|||
m_ShadowCascades: 1 |
|||
m_Cascade2Split: 0.25 |
|||
m_Cascade4Split: {x: 0.067, y: 0.2, z: 0.467} |
|||
m_DefaultShader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} |
|||
m_BlitShader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3} |
|||
m_CopyDepthShader: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3} |
|||
m_DefaultMaterial: {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} |
|||
m_DefaultParticleMaterial: {fileID: 2100000, guid: e823cd5b5d27c0f4b8256e7c12ee3e6d, |
|||
type: 2} |
|||
m_DefaultTerrainMaterial: {fileID: 2100000, guid: 594ea882c5a793440b60ff72d896021e, |
|||
type: 2} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9c068d834ef325345b87395bd103e074 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 11400000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
/Editor/Testing* |
|||
/.collabignore |
|||
/.gitignore |
|||
/.gitmodules |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapInputMaterialSlot : CubemapMaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private SerializableCubemap m_Cubemap = new SerializableCubemap(); |
|||
|
|||
public Cubemap cubemap |
|||
{ |
|||
get { return m_Cubemap.cubemap; } |
|||
set { m_Cubemap.cubemap = value; } |
|||
} |
|||
|
|||
public CubemapInputMaterialSlot() |
|||
{} |
|||
|
|||
public CubemapInputMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override VisualElement InstantiateControl() |
|||
{ |
|||
return new CubemapSlotControlView(this); |
|||
} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
return matOwner.GetVariableNameForSlot(id); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
var prop = new CubemapShaderProperty(); |
|||
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
prop.modifiable = false; |
|||
prop.generatePropertyBlock = true; |
|||
prop.value.cubemap = cubemap; |
|||
properties.AddShaderProperty(prop); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = cubemap |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as CubemapInputMaterialSlot; |
|||
if (slot != null) |
|||
m_Cubemap = slot.m_Cubemap; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7b961f6f7e2617446afb6a8e329d84d4 |
|||
timeCreated: 1509276977 |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapMaterialSlot : MaterialSlot |
|||
{ |
|||
public CubemapMaterialSlot() |
|||
{} |
|||
|
|||
public CubemapMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Cubemap; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Cubemap; } } |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ada5a840e90db5e4d901c686dca382ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapShaderProperty : AbstractShaderProperty<SerializableCubemap> |
|||
{ |
|||
[SerializeField] |
|||
private bool m_Modifiable = true; |
|||
|
|||
public CubemapShaderProperty() |
|||
{ |
|||
value = new SerializableCubemap(); |
|||
displayName = "Cubemap"; |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Cubemap; } |
|||
} |
|||
|
|||
public bool modifiable |
|||
{ |
|||
get { return m_Modifiable; } |
|||
set { m_Modifiable = value; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
if (!m_Modifiable) |
|||
{ |
|||
result.Append("[NonModifiableTextureData] "); |
|||
} |
|||
result.Append("[NoScaleOffset] "); |
|||
|
|||
result.Append(referenceName); |
|||
result.Append("(\""); |
|||
result.Append(displayName); |
|||
result.Append("\", CUBE) = \"\" {}"); |
|||
return result.ToString(); |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString() |
|||
{ |
|||
return "samplerCUBE " + referenceName + ";"; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return new PreviewProperty() |
|||
{ |
|||
m_Name = referenceName, |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = value.cubemap |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ca5ddce766d5ae24f8be282b4f7a21bd |
|||
timeCreated: 1505346949 |
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class SerializableCubemap |
|||
{ |
|||
[SerializeField] |
|||
private string m_SerializedCubemap; |
|||
|
|||
[Serializable] |
|||
private class CubemapHelper |
|||
{ |
|||
public Cubemap cubemap; |
|||
} |
|||
|
|||
public Cubemap cubemap |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedCubemap)) |
|||
return null; |
|||
|
|||
var cube = new CubemapHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube); |
|||
return cube.cubemap; |
|||
} |
|||
set |
|||
{ |
|||
if (cubemap == value) |
|||
return; |
|||
|
|||
var cube = new CubemapHelper(); |
|||
cube.cubemap = value; |
|||
m_SerializedCubemap = EditorJsonUtility.ToJson(cube, true); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 01e80e004e94f5e48ad1cb83d5701300 |
|||
timeCreated: 1505346945 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class LightWeightPBRSubShader |
|||
{ |
|||
Pass m_ForwardPassMetallic = new Pass() |
|||
{ |
|||
Name = "LightweightForward", |
|||
PixelShaderSlots = new List<int>() |
|||
{ |
|||
PBRMasterNode.AlbedoSlotId, |
|||
PBRMasterNode.NormalSlotId, |
|||
PBRMasterNode.EmissionSlotId, |
|||
PBRMasterNode.MetallicSlotId, |
|||
PBRMasterNode.SmoothnessSlotId, |
|||
PBRMasterNode.OcclusionSlotId, |
|||
PBRMasterNode.AlphaSlotId |
|||
} |
|||
}; |
|||
|
|||
struct Pass |
|||
{ |
|||
public string Name; |
|||
public List<int> VertexShaderSlots; |
|||
public List<int> PixelShaderSlots; |
|||
} |
|||
|
|||
Pass m_ForwardPassSpecular = new Pass() |
|||
{ |
|||
Name = "LightweightForward", |
|||
PixelShaderSlots = new List<int>() |
|||
{ |
|||
PBRMasterNode.AlbedoSlotId, |
|||
PBRMasterNode.NormalSlotId, |
|||
PBRMasterNode.EmissionSlotId, |
|||
PBRMasterNode.SpecularSlotId, |
|||
PBRMasterNode.SmoothnessSlotId, |
|||
PBRMasterNode.OcclusionSlotId, |
|||
PBRMasterNode.AlphaSlotId |
|||
} |
|||
}; |
|||
|
|||
private static string GetShaderPassFromTemplate(string template, PBRMasterNode masterNode, Pass pass, GenerationMode mode, SurfaceMaterialOptions materialOptions) |
|||
{ |
|||
var surfaceVertexShader = new ShaderGenerator(); |
|||
var surfaceDescriptionFunction = new ShaderGenerator(); |
|||
var surfaceDescriptionStruct = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var surfaceInputs = new ShaderGenerator(); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
var graphVertexInput = @"
|
|||
struct GraphVertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
float4 color : COLOR; |
|||
float4 texcoord0 : TEXCOORD0; |
|||
float4 lightmapUV : TEXCOORD1; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
};";
|
|||
|
|||
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false); |
|||
surfaceInputs.Indent(); |
|||
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, masterNode, NodeUtils.IncludeSelf.Include, pass.PixelShaderSlots); |
|||
|
|||
var requirements = AbstractMaterialGraph.GetRequirements(activeNodeList); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, InterpolatorType.ViewDirection, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, InterpolatorType.Position, surfaceInputs); |
|||
|
|||
if (requirements.requiresVertexColor) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false); |
|||
|
|||
if (requirements.requiresScreenPosition) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false); |
|||
|
|||
foreach (var channel in requirements.requiresMeshUVs.Distinct()) |
|||
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false); |
|||
|
|||
surfaceInputs.Deindent(); |
|||
surfaceInputs.AddShaderChunk("};", false); |
|||
|
|||
surfaceVertexShader.AddShaderChunk("GraphVertexInput PopulateVertexData(GraphVertexInput v){", false); |
|||
surfaceVertexShader.Indent(); |
|||
surfaceVertexShader.AddShaderChunk("return v;", false); |
|||
surfaceVertexShader.Deindent(); |
|||
surfaceVertexShader.AddShaderChunk("}", false); |
|||
|
|||
var slots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
slots.Add(masterNode.FindSlot<MaterialSlot>(id)); |
|||
AbstractMaterialGraph.GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, slots, true); |
|||
|
|||
var usedSlots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
usedSlots.Add(masterNode.FindSlot<MaterialSlot>(id)); |
|||
|
|||
AbstractMaterialGraph.GenerateSurfaceDescription( |
|||
activeNodeList, |
|||
masterNode, |
|||
masterNode.owner as AbstractMaterialGraph, |
|||
surfaceDescriptionFunction, |
|||
shaderFunctionVisitor, |
|||
shaderProperties, |
|||
requirements, |
|||
mode, |
|||
"PopulateSurfaceData", |
|||
"SurfaceDescription", |
|||
null, |
|||
null, |
|||
usedSlots); |
|||
|
|||
var graph = new ShaderGenerator(); |
|||
graph.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false); |
|||
graph.AddShaderChunk(graphVertexInput, false); |
|||
graph.AddShaderChunk(surfaceInputs.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false); |
|||
graph.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false); |
|||
graph.AddShaderChunk(surfaceVertexShader.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false); |
|||
|
|||
var blendingVisitor = new ShaderGenerator(); |
|||
var cullingVisitor = new ShaderGenerator(); |
|||
var zTestVisitor = new ShaderGenerator(); |
|||
var zWriteVisitor = new ShaderGenerator(); |
|||
|
|||
|
|||
materialOptions.GetBlend(blendingVisitor); |
|||
materialOptions.GetCull(cullingVisitor); |
|||
materialOptions.GetDepthTest(zTestVisitor); |
|||
materialOptions.GetDepthWrite(zWriteVisitor); |
|||
|
|||
var interpolators = new ShaderGenerator(); |
|||
var localVertexShader = new ShaderGenerator(); |
|||
var localPixelShader = new ShaderGenerator(); |
|||
var localSurfaceInputs = new ShaderGenerator(); |
|||
var surfaceOutputRemap = new ShaderGenerator(); |
|||
|
|||
var reqs = ShaderGraphRequirements.none; |
|||
reqs.requiresNormal |= NeededCoordinateSpace.World; |
|||
reqs.requiresTangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresBitangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresPosition |= NeededCoordinateSpace.World; |
|||
reqs.requiresViewDir |= NeededCoordinateSpace.World; |
|||
|
|||
ShaderGenerator.GenerateStandardTransforms( |
|||
3, |
|||
10, |
|||
interpolators, |
|||
localVertexShader, |
|||
localPixelShader, |
|||
localSurfaceInputs, |
|||
requirements, |
|||
reqs, |
|||
CoordinateSpace.World); |
|||
|
|||
ShaderGenerator defines = new ShaderGenerator(); |
|||
|
|||
if (masterNode.IsSlotConnected(PBRMasterNode.NormalSlotId)) |
|||
defines.AddShaderChunk("#define _NORMALMAP 1", true); |
|||
|
|||
if (masterNode.model == PBRMasterNode.Model.Specular) |
|||
defines.AddShaderChunk("#define _SPECULAR_SETUP 1", true); |
|||
|
|||
switch (masterNode.alphaMode) |
|||
{ |
|||
case PBRMasterNode.AlphaMode.AlphaBlend: |
|||
case PBRMasterNode.AlphaMode.AdditiveBlend: |
|||
defines.AddShaderChunk("#define _AlphaOut 1", true); |
|||
break; |
|||
case PBRMasterNode.AlphaMode.Clip: |
|||
defines.AddShaderChunk("#define _AlphaClip 1", true); |
|||
break; |
|||
} |
|||
|
|||
var templateLocation = ShaderGenerator.GetTemplatePath(template); |
|||
|
|||
foreach (var slot in usedSlots) |
|||
{ |
|||
surfaceOutputRemap.AddShaderChunk(slot.shaderOutputName |
|||
+ " = surf." |
|||
+ slot.shaderOutputName + ";", true); |
|||
} |
|||
|
|||
if (!File.Exists(templateLocation)) |
|||
return string.Empty; |
|||
|
|||
var subShaderTemplate = File.ReadAllText(templateLocation); |
|||
var resultPass = subShaderTemplate.Replace("${Defines}", defines.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${Graph}", graph.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${Interpolators}", interpolators.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${VertexShader}", localVertexShader.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${LocalPixelShader}", localPixelShader.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceInputs}", localSurfaceInputs.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceOutputRemap}", surfaceOutputRemap.GetShaderString(3)); |
|||
|
|||
|
|||
resultPass = resultPass.Replace("${Tags}", string.Empty); |
|||
resultPass = resultPass.Replace("${Blending}", blendingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${Culling}", cullingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZTest}", zTestVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2)); |
|||
return resultPass; |
|||
} |
|||
|
|||
public IEnumerable<string> GetSubshader(PBRMasterNode masterNode, GenerationMode mode) |
|||
{ |
|||
var subShader = new ShaderGenerator(); |
|||
subShader.AddShaderChunk("SubShader", true); |
|||
subShader.AddShaderChunk("{", true); |
|||
subShader.Indent(); |
|||
subShader.AddShaderChunk("Tags{ \"RenderPipeline\" = \"LightweightPipeline\"}", true); |
|||
|
|||
var materialOptions = new SurfaceMaterialOptions(); |
|||
switch (masterNode.alphaMode) |
|||
{ |
|||
case PBRMasterNode.AlphaMode.Overwrite: |
|||
case PBRMasterNode.AlphaMode.Clip: |
|||
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One; |
|||
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero; |
|||
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back; |
|||
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual; |
|||
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.On; |
|||
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Geometry; |
|||
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Opaque; |
|||
break; |
|||
case PBRMasterNode.AlphaMode.AlphaBlend: |
|||
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha; |
|||
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha; |
|||
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back; |
|||
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual; |
|||
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off; |
|||
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent; |
|||
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent; |
|||
break; |
|||
case PBRMasterNode.AlphaMode.AdditiveBlend: |
|||
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One; |
|||
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One; |
|||
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back; |
|||
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual; |
|||
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off; |
|||
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent; |
|||
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent; |
|||
break; |
|||
} |
|||
|
|||
var tagsVisitor = new ShaderGenerator(); |
|||
materialOptions.GetTags(tagsVisitor); |
|||
subShader.AddShaderChunk(tagsVisitor.GetShaderString(0), true); |
|||
|
|||
subShader.AddShaderChunk( |
|||
GetShaderPassFromTemplate( |
|||
"lightweightPBRForwardPass.template", |
|||
masterNode, |
|||
masterNode.model == PBRMasterNode.Model.Metallic ? m_ForwardPassMetallic : m_ForwardPassSpecular, |
|||
mode, |
|||
materialOptions), |
|||
true); |
|||
|
|||
var extraPassesTemplateLocation = ShaderGenerator.GetTemplatePath("lightweightPBRExtraPasses.template"); |
|||
if (File.Exists(extraPassesTemplateLocation)) |
|||
subShader.AddShaderChunk(File.ReadAllText(extraPassesTemplateLocation), true); |
|||
|
|||
subShader.Deindent(); |
|||
subShader.AddShaderChunk("}", true); |
|||
|
|||
return new[] { subShader.GetShaderString(0) }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ca91dbeb78daa054c9bbe15fef76361c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class LightWeightUnlitSubShader |
|||
{ |
|||
Pass m_UnlitPass = new Pass() |
|||
{ |
|||
Name = "Unlit", |
|||
PixelShaderSlots = new List<int>() |
|||
{ |
|||
UnlitMasterNode.ColorSlotId, |
|||
UnlitMasterNode.AlphaSlotId |
|||
} |
|||
}; |
|||
|
|||
struct Pass |
|||
{ |
|||
public string Name; |
|||
public List<int> VertexShaderSlots; |
|||
public List<int> PixelShaderSlots; |
|||
} |
|||
|
|||
private static string GetShaderPassFromTemplate(string template, UnlitMasterNode masterNode, Pass pass, GenerationMode mode) |
|||
{ |
|||
var surfaceVertexShader = new ShaderGenerator(); |
|||
var surfaceDescriptionFunction = new ShaderGenerator(); |
|||
var surfaceDescriptionStruct = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var surfaceInputs = new ShaderGenerator(); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
var graphVertexInput = @"
|
|||
struct GraphVertexInput |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
float4 tangent : TANGENT; |
|||
float4 color : COLOR; |
|||
float4 texcoord0 : TEXCOORD0; |
|||
float4 lightmapUV : TEXCOORD1; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
};";
|
|||
|
|||
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false); |
|||
surfaceInputs.Indent(); |
|||
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, masterNode, NodeUtils.IncludeSelf.Include, pass.PixelShaderSlots); |
|||
|
|||
var requirements = AbstractMaterialGraph.GetRequirements(activeNodeList); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, InterpolatorType.ViewDirection, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, InterpolatorType.Position, surfaceInputs); |
|||
|
|||
if (requirements.requiresVertexColor) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false); |
|||
|
|||
if (requirements.requiresScreenPosition) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false); |
|||
|
|||
foreach (var channel in requirements.requiresMeshUVs.Distinct()) |
|||
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false); |
|||
|
|||
surfaceInputs.Deindent(); |
|||
surfaceInputs.AddShaderChunk("};", false); |
|||
|
|||
surfaceVertexShader.AddShaderChunk("GraphVertexInput PopulateVertexData(GraphVertexInput v){", false); |
|||
surfaceVertexShader.Indent(); |
|||
surfaceVertexShader.AddShaderChunk("return v;", false); |
|||
surfaceVertexShader.Deindent(); |
|||
surfaceVertexShader.AddShaderChunk("}", false); |
|||
|
|||
var slots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
{ |
|||
var slot = masterNode.FindSlot<MaterialSlot>(id); |
|||
if (slot != null) |
|||
slots.Add(slot); |
|||
} |
|||
AbstractMaterialGraph.GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, slots, true); |
|||
|
|||
var usedSlots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
usedSlots.Add(masterNode.FindSlot<MaterialSlot>(id)); |
|||
|
|||
AbstractMaterialGraph.GenerateSurfaceDescription( |
|||
activeNodeList, |
|||
masterNode, |
|||
masterNode.owner as AbstractMaterialGraph, |
|||
surfaceDescriptionFunction, |
|||
shaderFunctionVisitor, |
|||
shaderProperties, |
|||
requirements, |
|||
mode, |
|||
"PopulateSurfaceData", |
|||
"SurfaceDescription", |
|||
null, |
|||
null, |
|||
usedSlots); |
|||
|
|||
var graph = new ShaderGenerator(); |
|||
graph.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false); |
|||
graph.AddShaderChunk(graphVertexInput, false); |
|||
graph.AddShaderChunk(surfaceInputs.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false); |
|||
graph.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false); |
|||
graph.AddShaderChunk(surfaceVertexShader.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false); |
|||
|
|||
var tagsVisitor = new ShaderGenerator(); |
|||
var blendingVisitor = new ShaderGenerator(); |
|||
var cullingVisitor = new ShaderGenerator(); |
|||
var zTestVisitor = new ShaderGenerator(); |
|||
var zWriteVisitor = new ShaderGenerator(); |
|||
|
|||
var materialOptions = new SurfaceMaterialOptions(); |
|||
materialOptions.GetTags(tagsVisitor); |
|||
materialOptions.GetBlend(blendingVisitor); |
|||
materialOptions.GetCull(cullingVisitor); |
|||
materialOptions.GetDepthTest(zTestVisitor); |
|||
materialOptions.GetDepthWrite(zWriteVisitor); |
|||
|
|||
var interpolators = new ShaderGenerator(); |
|||
var localVertexShader = new ShaderGenerator(); |
|||
var localPixelShader = new ShaderGenerator(); |
|||
var localSurfaceInputs = new ShaderGenerator(); |
|||
var surfaceOutputRemap = new ShaderGenerator(); |
|||
|
|||
var reqs = ShaderGraphRequirements.none; |
|||
reqs.requiresNormal |= NeededCoordinateSpace.World; |
|||
reqs.requiresTangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresBitangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresPosition |= NeededCoordinateSpace.World; |
|||
reqs.requiresViewDir |= NeededCoordinateSpace.World; |
|||
|
|||
ShaderGenerator.GenerateStandardTransforms( |
|||
3, |
|||
10, |
|||
interpolators, |
|||
localVertexShader, |
|||
localPixelShader, |
|||
localSurfaceInputs, |
|||
requirements, |
|||
reqs, |
|||
CoordinateSpace.World); |
|||
|
|||
ShaderGenerator defines = new ShaderGenerator(); |
|||
var templateLocation = ShaderGenerator.GetTemplatePath(template); |
|||
|
|||
foreach (var slot in usedSlots) |
|||
{ |
|||
surfaceOutputRemap.AddShaderChunk(slot.shaderOutputName |
|||
+ " = surf." |
|||
+ slot.shaderOutputName + ";", true); |
|||
} |
|||
|
|||
if (!File.Exists(templateLocation)) |
|||
return string.Empty; |
|||
|
|||
var subShaderTemplate = File.ReadAllText(templateLocation); |
|||
var resultPass = subShaderTemplate.Replace("${Defines}", defines.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${Graph}", graph.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${Interpolators}", interpolators.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${VertexShader}", localVertexShader.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${LocalPixelShader}", localPixelShader.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceInputs}", localSurfaceInputs.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceOutputRemap}", surfaceOutputRemap.GetShaderString(3)); |
|||
|
|||
|
|||
resultPass = resultPass.Replace("${Tags}", tagsVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${Blending}", blendingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${Culling}", cullingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZTest}", zTestVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${LOD}", "" + materialOptions.lod); |
|||
return resultPass; |
|||
} |
|||
|
|||
public IEnumerable<string> GetSubshader(UnlitMasterNode masterNode, GenerationMode mode) |
|||
{ |
|||
var subShader = new ShaderGenerator(); |
|||
subShader.AddShaderChunk("SubShader", true); |
|||
subShader.AddShaderChunk("{", true); |
|||
subShader.Indent(); |
|||
subShader.AddShaderChunk("Tags{ \"RenderType\" = \"Opaque\" \"RenderPipeline\" = \"LightweightPipeline\"}", true); |
|||
|
|||
subShader.AddShaderChunk( |
|||
GetShaderPassFromTemplate( |
|||
"lightweightUnlitPass.template", |
|||
masterNode, |
|||
m_UnlitPass, |
|||
mode), |
|||
true); |
|||
|
|||
subShader.Deindent(); |
|||
subShader.AddShaderChunk("}", true); |
|||
|
|||
return new[] { subShader.GetShaderString(0) }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3ef30c5c1d5fc412f88511ef5818b654 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/PBR")] |
|||
public class PBRMasterNode : MasterNode |
|||
{ |
|||
public const string AlbedoSlotName = "Albedo"; |
|||
public const string NormalSlotName = "Normal"; |
|||
public const string EmissionSlotName = "Emission"; |
|||
public const string MetallicSlotName = "Metallic"; |
|||
public const string SpecularSlotName = "Specular"; |
|||
public const string SmoothnessSlotName = "Smoothness"; |
|||
public const string OcclusionSlotName = "Occlusion"; |
|||
public const string AlphaSlotName = "Alpha"; |
|||
public const string VertexOffsetName = "VertexPosition"; |
|||
|
|||
public const int AlbedoSlotId = 0; |
|||
public const int NormalSlotId = 1; |
|||
public const int MetallicSlotId = 2; |
|||
public const int SpecularSlotId = 3; |
|||
public const int EmissionSlotId = 4; |
|||
public const int SmoothnessSlotId = 5; |
|||
public const int OcclusionSlotId = 6; |
|||
public const int AlphaSlotId = 7; |
|||
|
|||
public enum Model |
|||
{ |
|||
Specular, |
|||
Metallic |
|||
} |
|||
|
|||
public enum AlphaMode |
|||
{ |
|||
Overwrite, |
|||
AlphaBlend, |
|||
AdditiveBlend, |
|||
Clip |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Model m_Model = Model.Metallic; |
|||
|
|||
[EnumControl("")] |
|||
public Model model |
|||
{ |
|||
get { return m_Model; } |
|||
set |
|||
{ |
|||
if (m_Model == value) |
|||
return; |
|||
|
|||
m_Model = value; |
|||
UpdateNodeAfterDeserialization(); |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Topological); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private AlphaMode m_AlphaMode; |
|||
|
|||
[EnumControl("")] |
|||
public AlphaMode alphaMode |
|||
{ |
|||
get { return m_AlphaMode; } |
|||
set |
|||
{ |
|||
if (m_AlphaMode == value) |
|||
return; |
|||
|
|||
m_AlphaMode = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public PBRMasterNode() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public bool IsSlotConnected(int slotId) |
|||
{ |
|||
var slot = FindSlot<MaterialSlot>(slotId); |
|||
return slot != null && owner.GetEdges(slot.slotReference).Any(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
name = "PBR Master"; |
|||
AddSlot(new Vector3MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, new Vector4(0.5f, 0.5f, 0.5f), ShaderStage.Fragment)); |
|||
AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0, 0, 1), ShaderStage.Fragment)); |
|||
AddSlot(new Vector3MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment)); |
|||
if (model == Model.Metallic) |
|||
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStage.Fragment)); |
|||
else |
|||
AddSlot(new Vector3MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment)); |
|||
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStage.Fragment)); |
|||
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 1f, ShaderStage.Fragment)); |
|||
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1f, ShaderStage.Fragment)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
model == Model.Metallic ? MetallicSlotId : SpecularSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetShader(GenerationMode mode, string outputName, out List<PropertyCollector.TextureInfo> configuredTextures) |
|||
{ |
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
var abstractMaterialGraph = owner as AbstractMaterialGraph; |
|||
if (abstractMaterialGraph != null) |
|||
abstractMaterialGraph.CollectShaderProperties(shaderProperties, mode); |
|||
|
|||
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
activeNode.CollectShaderProperties(shaderProperties, mode); |
|||
|
|||
var finalShader = new ShaderGenerator(); |
|||
finalShader.AddShaderChunk(string.Format(@"Shader ""{0}""", outputName), false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
|
|||
finalShader.AddShaderChunk("Properties", false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
finalShader.AddShaderChunk(shaderProperties.GetPropertiesBlock(2), false); |
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
|
|||
var lwSub = new LightWeightPBRSubShader(); |
|||
foreach (var subshader in lwSub.GetSubshader(this, mode)) |
|||
finalShader.AddShaderChunk(subshader, true); |
|||
|
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
|
|||
configuredTextures = shaderProperties.GetConfiguredTexutres(); |
|||
return finalShader.GetShaderString(0); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ea7519738e2a9b4469abbff8d5c4d657 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/Unlit")] |
|||
public class UnlitMasterNode : MasterNode |
|||
{ |
|||
public const string ColorSlotName = "Color"; |
|||
public const string AlphaSlotName = "Alpha"; |
|||
public const string VertexOffsetName = "VertexPosition"; |
|||
|
|||
public const int ColorSlotId = 0; |
|||
public const int AlphaSlotId = 7; |
|||
|
|||
public UnlitMasterNode() |
|||
{ |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
name = "Unlit Master"; |
|||
AddSlot(new Vector3MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, new Vector3(0.5f, 0.5f, 0.5f), ShaderStage.Fragment)); |
|||
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStage.Fragment)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
ColorSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetShader(GenerationMode mode, string outputName, out List<PropertyCollector.TextureInfo> configuredTextures) |
|||
{ |
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
var abstractMaterialGraph = owner as AbstractMaterialGraph; |
|||
if (abstractMaterialGraph != null) |
|||
abstractMaterialGraph.CollectShaderProperties(shaderProperties, mode); |
|||
|
|||
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
activeNode.CollectShaderProperties(shaderProperties, mode); |
|||
|
|||
var finalShader = new ShaderGenerator(); |
|||
finalShader.AddShaderChunk(string.Format(@"Shader ""{0}""", outputName), false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
|
|||
finalShader.AddShaderChunk("Properties", false); |
|||
finalShader.AddShaderChunk("{", false); |
|||
finalShader.Indent(); |
|||
finalShader.AddShaderChunk(shaderProperties.GetPropertiesBlock(2), false); |
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
|
|||
var lwSub = new LightWeightUnlitSubShader(); |
|||
foreach (var subshader in lwSub.GetSubshader(this, mode)) |
|||
finalShader.AddShaderChunk(subshader, true); |
|||
|
|||
finalShader.Deindent(); |
|||
finalShader.AddShaderChunk("}", false); |
|||
|
|||
configuredTextures = shaderProperties.GetConfiguredTexutres(); |
|||
return finalShader.GetShaderString(0); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 50acf8d45249d486e9e5ee72178100f4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Artistic/Adjustment/Channel Mixer")] |
|||
public class ChannelMixerNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
public ChannelMixerNode() |
|||
{ |
|||
name = "Channel Mixer"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
const int InputSlotId = 0; |
|||
const int OutputSlotId = 1; |
|||
const string kInputSlotName = "In"; |
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
string GetFunctionName() |
|||
{ |
|||
return "Unity_ChannelMixer_" + precision; |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero)); |
|||
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId }); |
|||
} |
|||
|
|||
[SerializeField] |
|||
ChannelMixer m_ChannelMixer = new ChannelMixer( new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1)); |
|||
|
|||
[Serializable] |
|||
public struct ChannelMixer |
|||
{ |
|||
public Vector3 outRed; |
|||
public Vector3 outGreen; |
|||
public Vector3 outBlue; |
|||
|
|||
public ChannelMixer(Vector3 red, Vector3 green, Vector3 blue) |
|||
{ |
|||
outRed = red; |
|||
outGreen = green; |
|||
outBlue = blue; |
|||
} |
|||
} |
|||
|
|||
[ChannelMixerControl("")] |
|||
public ChannelMixer channelMixer |
|||
{ |
|||
get { return m_ChannelMixer; } |
|||
set |
|||
{ |
|||
if ((value.outRed == m_ChannelMixer.outRed) && (value.outGreen == m_ChannelMixer.outGreen) && (value.outBlue == m_ChannelMixer.outBlue)) |
|||
return; |
|||
m_ChannelMixer = value; |
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
|
|||
string GetFunctionPrototype(string argIn, string argRed, string argGreen, string argBlue, string argOut) |
|||
{ |
|||
return string.Format("void {0} ({1} {2}, {3} {4}, {3} {5}, {3} {6}, out {7} {8})", GetFunctionName(), |
|||
ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), argIn, |
|||
precision+"3", argRed, argGreen, argBlue, |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), argOut); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
string outputValue = GetSlotValue(OutputSlotId, generationMode); |
|||
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true); |
|||
|
|||
if(!generationMode.IsPreview()) |
|||
{ |
|||
visitor.AddShaderChunk(string.Format("{0}3 _{1}_Red = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outRed[0], channelMixer.outRed[1], channelMixer.outRed[2]), true); |
|||
visitor.AddShaderChunk(string.Format("{0}3 _{1}_Green = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outGreen[0], channelMixer.outGreen[1], channelMixer.outGreen[2]), true); |
|||
visitor.AddShaderChunk(string.Format("{0}3 _{1}_Blue = {0}3 ({2}, {3}, {4});", precision, GetVariableNameForNode(), channelMixer.outBlue[0], channelMixer.outBlue[1], channelMixer.outBlue[2]), true); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(GetFunctionCallBody(inputValue, string.Format("_{0}_Red", GetVariableNameForNode()), string.Format("_{0}_Green", GetVariableNameForNode()), string.Format("_{0}_Blue", GetVariableNameForNode()), outputValue), true); |
|||
} |
|||
|
|||
string GetFunctionCallBody(string inputValue, string red, string green, string blue, string outputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ", " + red + ", " + green + ", " + blue + ", " + outputValue + ");"; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
|
|||
properties.Add(new PreviewProperty() |
|||
{ |
|||
m_Name = string.Format("_{0}_Red", GetVariableNameForNode()), |
|||
m_PropType = PropertyType.Vector3, |
|||
m_Vector4 = channelMixer.outRed |
|||
}); |
|||
|
|||
properties.Add(new PreviewProperty() |
|||
{ |
|||
m_Name = string.Format("_{0}_Green", GetVariableNameForNode()), |
|||
m_PropType = PropertyType.Vector3, |
|||
m_Vector4 = channelMixer.outGreen |
|||
}); |
|||
|
|||
properties.Add(new PreviewProperty() |
|||
{ |
|||
m_Name = string.Format("_{0}_Blue", GetVariableNameForNode()), |
|||
m_PropType = PropertyType.Vector3, |
|||
m_Vector4 = channelMixer.outBlue |
|||
}); |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
base.CollectShaderProperties(properties, generationMode); |
|||
|
|||
properties.AddShaderProperty(new Vector4ShaderProperty() |
|||
{ |
|||
overrideReferenceName = string.Format("_{0}_Red", GetVariableNameForNode()), |
|||
generatePropertyBlock = false |
|||
}); |
|||
|
|||
properties.AddShaderProperty(new Vector4ShaderProperty() |
|||
{ |
|||
overrideReferenceName = string.Format("_{0}_Green", GetVariableNameForNode()), |
|||
generatePropertyBlock = false |
|||
}); |
|||
|
|||
properties.AddShaderProperty(new Vector4ShaderProperty() |
|||
{ |
|||
overrideReferenceName = string.Format("_{0}_Blue", GetVariableNameForNode()), |
|||
generatePropertyBlock = false |
|||
}); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk(GetFunctionPrototype("In", "Red", "Green", "Blue", "Out"), false); |
|||
visitor.AddShaderChunk("{", false); |
|||
visitor.Indent(); |
|||
|
|||
visitor.AddShaderChunk(string.Format("Out = {0} (dot(In, Red), dot(In, Green), dot(In, Blue));", |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType)), true); |
|||
|
|||
visitor.Deindent(); |
|||
visitor.AddShaderChunk("}", false); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d8d3a2d8c96e5994696f30f658efebea |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Artistic/Adjustment/Replace Color")] |
|||
public class ReplaceColorNode : CodeFunctionNode |
|||
{ |
|||
public ReplaceColorNode() |
|||
{ |
|||
name = "Replace Color"; |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_ReplaceColor", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_ReplaceColor( |
|||
[Slot(0, Binding.None)] Vector3 In, |
|||
[Slot(1, Binding.None)] Color From, |
|||
[Slot(2, Binding.None)] Color To, |
|||
[Slot(3, Binding.None)] Vector1 Range, |
|||
[Slot(4, Binding.None)] out Vector3 Out) |
|||
{ |
|||
Out = Vector2.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
{precision}3 col = In; |
|||
{precision} Distance = distance(From, In); |
|||
if(Distance <= Range) |
|||
col = To; |
|||
Out = col; |
|||
}";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a60be5fb80fbbdb449fcc95fa2256cc5 |
|||
timeCreated: 1444218016 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Artistic/Adjustment/White Balance")] |
|||
public class WhiteBalanceNode : CodeFunctionNode |
|||
{ |
|||
public WhiteBalanceNode() |
|||
{ |
|||
name = "White Balance"; |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_WhiteBalance", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_WhiteBalance( |
|||
[Slot(0, Binding.None)] Vector3 In, |
|||
[Slot(1, Binding.None)] Vector1 Temperature, |
|||
[Slot(2, Binding.None)] Vector1 Tint, |
|||
[Slot(3, Binding.None)] out Vector3 Out) |
|||
{ |
|||
Out = Vector3.zero; |
|||
return @"
|
|||
{ |
|||
// Range ~[-1.67;1.67] works best
|
|||
{precision} t1 = Temperature * 10 / 6; |
|||
{precision} t2 = Tint * 10 / 6; |
|||
|
|||
// Get the CIE xy chromaticity of the reference white point.
|
|||
// Note: 0.31271 = x value on the D65 white point
|
|||
{precision} x = 0.31271 - t1 * (t1 < 0 ? 0.1 : 0.05); |
|||
{precision} standardIlluminantY = 2.87 * x - 3 * x * x - 0.27509507; |
|||
{precision} y = standardIlluminantY + t2 * 0.05; |
|||
|
|||
// Calculate the coefficients in the LMS space.
|
|||
{precision}3 w1 = {precision}3(0.949237, 1.03542, 1.08728); // D65 white point
|
|||
|
|||
// CIExyToLMS
|
|||
{precision} Y = 1; |
|||
{precision} X = Y * x / y; |
|||
{precision} Z = Y * (1 - x - y) / y; |
|||
{precision} L = 0.7328 * X + 0.4296 * Y - 0.1624 * Z; |
|||
{precision} M = -0.7036 * X + 1.6975 * Y + 0.0061 * Z; |
|||
{precision} S = 0.0030 * X + 0.0136 * Y + 0.9834 * Z; |
|||
{precision}3 w2 = {precision}3(L, M, S); |
|||
|
|||
{precision}3 balance = {precision}3(w1.x / w2.x, w1.y / w2.y, w1.z / w2.z); |
|||
|
|||
{precision}3x3 LIN_2_LMS_MAT = { |
|||
3.90405e-1, 5.49941e-1, 8.92632e-3, |
|||
7.08416e-2, 9.63172e-1, 1.35775e-3, |
|||
2.31082e-2, 1.28021e-1, 9.36245e-1 |
|||
}; |
|||
|
|||
{precision}3x3 LMS_2_LIN_MAT = { |
|||
2.85847e+0, -1.62879e+0, -2.48910e-2, |
|||
-2.10182e-1, 1.15820e+0, 3.24281e-4, |
|||
-4.18120e-2, -1.18169e-1, 1.06867e+0 |
|||
}; |
|||
|
|||
{precision}3 lms = mul(LIN_2_LMS_MAT, In); |
|||
lms *= balance; |
|||
Out = mul(LMS_2_LIN_MAT, lms); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c09bf9b59c16e0d48b9a346376d28640 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cdb8c403de0823942a95a464c32ad0f0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Channel/Flip")] |
|||
public class FlipNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction |
|||
{ |
|||
public FlipNode() |
|||
{ |
|||
name = "Flip"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
const int InputSlotId = 0; |
|||
const int OutputSlotId = 1; |
|||
const string kInputSlotName = "In"; |
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
string GetFunctionName() |
|||
{ |
|||
return "Unity_Flip_" + ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero)); |
|||
AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId }); |
|||
} |
|||
|
|||
int channelCount { get { return (int)SlotValueHelper.GetChannelCount(FindSlot<MaterialSlot>(InputSlotId).concreteValueType); } } |
|||
|
|||
[SerializeField] |
|||
private bool m_RedChannel; |
|||
|
|||
[ToggleControl("Red")] |
|||
public Toggle redChannel |
|||
{ |
|||
get { return new Toggle(m_RedChannel, channelCount > 0); } |
|||
set |
|||
{ |
|||
if (m_RedChannel == value.isOn) |
|||
return; |
|||
m_RedChannel = value.isOn; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private bool m_GreenChannel; |
|||
|
|||
[ToggleControl("Green")] |
|||
public Toggle greenChannel |
|||
{ |
|||
get { return new Toggle(m_GreenChannel, channelCount > 1); } |
|||
set |
|||
{ |
|||
if (m_GreenChannel == value.isOn) |
|||
return; |
|||
m_GreenChannel = value.isOn; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private bool m_BlueChannel; |
|||
|
|||
[ToggleControl("Blue")] |
|||
public Toggle blueChannel |
|||
{ |
|||
get { return new Toggle(m_BlueChannel, channelCount > 2); } |
|||
set |
|||
{ |
|||
if (m_BlueChannel == value.isOn) |
|||
return; |
|||
m_BlueChannel = value.isOn; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private bool m_AlphaChannel; |
|||
|
|||
[ToggleControl("Alpha")] |
|||
public Toggle alphaChannel |
|||
{ |
|||
get { return new Toggle(m_AlphaChannel, channelCount > 3); } |
|||
set |
|||
{ |
|||
if (m_AlphaChannel == value.isOn) |
|||
return; |
|||
m_AlphaChannel = value.isOn; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
string GetFunctionPrototype(string inArg, string flipArg, string outArg) |
|||
{ |
|||
return string.Format("void {0} ({1} {2}, {3} {4}, out {5} {6})", GetFunctionName(), |
|||
ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), inArg, |
|||
ConvertConcreteSlotValueTypeToString(precision, FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType), flipArg, |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), outArg); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
string outputValue = GetSlotValue(OutputSlotId, generationMode); |
|||
visitor.AddShaderChunk(string.Format("{0} {1};", ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), GetVariableNameForSlot(OutputSlotId)), true); |
|||
|
|||
if(!generationMode.IsPreview()) |
|||
{ |
|||
visitor.AddShaderChunk(string.Format("{0} _{1}_Flip = {0} ({2}{3}{4}{5});", |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), |
|||
GetVariableNameForNode(), |
|||
Convert.ToInt32(m_RedChannel).ToString(), |
|||
channelCount > 1 ? string.Format(", {0}", (Convert.ToInt32(m_GreenChannel)).ToString()) : "", |
|||
channelCount > 2 ? string.Format(", {0}", (Convert.ToInt32(m_BlueChannel)).ToString()) : "", |
|||
channelCount > 3 ? string.Format(", {0}", (Convert.ToInt32(m_AlphaChannel)).ToString()) : ""), true); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(GetFunctionCallBody(inputValue, string.Format("_{0}_Flip", GetVariableNameForNode()), outputValue), true); |
|||
} |
|||
|
|||
string GetFunctionCallBody(string inputValue, string flipValue, string outputValue) |
|||
{ |
|||
return GetFunctionName() + " (" + inputValue + ", " + flipValue + ", " + outputValue + ");"; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
|
|||
properties.Add(new PreviewProperty() |
|||
{ |
|||
m_Name = string.Format("_{0}_Flip", GetVariableNameForNode()), |
|||
m_PropType = PropertyType.Vector4, |
|||
m_Vector4 = new Vector4(Convert.ToInt32(m_RedChannel), Convert.ToInt32(m_GreenChannel), Convert.ToInt32(m_BlueChannel), Convert.ToInt32(m_AlphaChannel)), |
|||
}); |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
base.CollectShaderProperties(properties, generationMode); |
|||
|
|||
properties.AddShaderProperty(new Vector4ShaderProperty |
|||
{ |
|||
overrideReferenceName = string.Format("_{0}_Flip", GetVariableNameForNode()), |
|||
generatePropertyBlock = false |
|||
}); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("In", "Flip", "Out"), true); |
|||
outputString.AddShaderChunk("{", true); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("Out = abs(Flip - In);", true); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", true); |
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fa443691530c547418e195e22597f2af |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Texture/Cubemap Asset")] |
|||
public class CubemapAssetNode : AbstractMaterialNode, IPropertyFromNode |
|||
{ |
|||
public const int OutputSlotId = 0; |
|||
|
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public CubemapAssetNode() |
|||
{ |
|||
name = "Cubemap Asset"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new CubemapMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
[SerializeField] |
|||
private SerializableCubemap m_Cubemap = new SerializableCubemap(); |
|||
|
|||
[CubemapControl("")] |
|||
public Cubemap cubemap |
|||
{ |
|||
get { return m_Cubemap.cubemap; } |
|||
set |
|||
{ |
|||
if (m_Cubemap.cubemap == value) |
|||
return; |
|||
m_Cubemap.cubemap = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
properties.AddShaderProperty(new CubemapShaderProperty() |
|||
{ |
|||
overrideReferenceName = GetVariableNameForSlot(OutputSlotId), |
|||
generatePropertyBlock = true, |
|||
value = m_Cubemap, |
|||
modifiable = false |
|||
}); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(new PreviewProperty |
|||
{ |
|||
m_Name = GetVariableNameForSlot(OutputSlotId), |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = cubemap |
|||
}); |
|||
} |
|||
|
|||
public IShaderProperty AsShaderProperty() |
|||
{ |
|||
var prop = new CubemapShaderProperty(); |
|||
prop.value = m_Cubemap; |
|||
if (cubemap != null) |
|||
prop.displayName = cubemap.name; |
|||
return prop; |
|||
} |
|||
|
|||
public int outputSlotId { get { return OutputSlotId; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 968ed0a541658844486b1ac5ab57ee2d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Texture/Cubemap")] |
|||
public class CubemapNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireViewDirection, IMayRequireNormal |
|||
{ |
|||
public const int OutputSlotId = 0; |
|||
public const int CubemapInputId = 1; |
|||
public const int ViewDirInputId = 2; |
|||
public const int NormalInputId = 3; |
|||
public const int LODInputId = 4; |
|||
|
|||
const string kOutputSlotName = "Out"; |
|||
const string kCubemapInputName = "Cube"; |
|||
const string kViewDirInputName = "ViewDir"; |
|||
const string kNormalInputName = "Normal"; |
|||
const string kLODInputName = "LOD"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public CubemapNode() |
|||
{ |
|||
name = "Cubemap"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero)); |
|||
AddSlot(new CubemapInputMaterialSlot(CubemapInputId, kCubemapInputName, kCubemapInputName)); |
|||
AddSlot(new ViewDirectionMaterialSlot(ViewDirInputId, kViewDirInputName, kViewDirInputName, CoordinateSpace.Object)); |
|||
AddSlot(new NormalMaterialSlot(NormalInputId, kNormalInputName, kNormalInputName, CoordinateSpace.Object)); |
|||
AddSlot(new Vector1MaterialSlot(LODInputId, kLODInputName, kLODInputName, SlotType.Input, 0)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId, CubemapInputId, ViewDirInputId, NormalInputId, LODInputId }); |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get { return PreviewMode.Preview3D; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string result = string.Format("{0}4 {1} = texCUBElod ({2}, {0}4(reflect(-{3}, {4}), {5}));" |
|||
, precision |
|||
, GetVariableNameForSlot(OutputSlotId) |
|||
, GetSlotValue(CubemapInputId, generationMode) |
|||
, GetSlotValue(ViewDirInputId, generationMode) |
|||
, GetSlotValue(NormalInputId, generationMode) |
|||
, GetSlotValue(LODInputId, generationMode)); |
|||
|
|||
visitor.AddShaderChunk(result, true); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
var viewDirSlot = FindInputSlot<MaterialSlot>(ViewDirInputId); |
|||
var edgesViewDir = owner.GetEdges(viewDirSlot.slotReference); |
|||
if (!edgesViewDir.Any()) |
|||
return CoordinateSpace.Object.ToNeededCoordinateSpace(); |
|||
else |
|||
return NeededCoordinateSpace.None; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
var normalSlot = FindInputSlot<MaterialSlot>(NormalInputId); |
|||
var edgesNormal = owner.GetEdges(normalSlot.slotReference); |
|||
if (!edgesNormal.Any()) |
|||
return CoordinateSpace.Object.ToNeededCoordinateSpace(); |
|||
else |
|||
return NeededCoordinateSpace.None; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6eaeb9c846408f74daeadcc3314810e4 |
|||
timeCreated: 1495637741 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class ChannelEnumControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
int m_SlotId; |
|||
|
|||
public ChannelEnumControlAttribute(string label = null, int slotId = 0) |
|||
{ |
|||
m_Label = label; |
|||
m_SlotId = slotId; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new ChannelEnumControlView(m_Label, m_SlotId, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class ChannelEnumControlView : VisualElement, INodeModificationListener |
|||
{ |
|||
GUIContent m_Label; |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
IMGUIContainer m_Container; |
|||
int m_SlotId; |
|||
|
|||
public ChannelEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
m_SlotId = slotId; |
|||
if (!propertyInfo.PropertyType.IsEnum) |
|||
throw new ArgumentException("Property must be an enum.", "propertyInfo"); |
|||
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)); |
|||
m_Container = new IMGUIContainer(OnGUIHandler); |
|||
Add(m_Container); |
|||
} |
|||
|
|||
void OnGUIHandler() |
|||
{ |
|||
UpdatePopup(); |
|||
} |
|||
|
|||
public void OnNodeModified(ModificationScope scope) |
|||
{ |
|||
if (scope == ModificationScope.Graph) |
|||
m_Container.Dirty(ChangeType.Repaint); |
|||
} |
|||
|
|||
private void UpdatePopup() |
|||
{ |
|||
var value = (int)m_PropertyInfo.GetValue(m_Node, null); |
|||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
int channelCount = (int)SlotValueHelper.GetChannelCount(m_Node.FindSlot<MaterialSlot>(m_SlotId).concreteValueType); |
|||
var enumEntryCount = (Enum)m_PropertyInfo.GetValue(m_Node, null); |
|||
string[] enumEntryNames = Enum.GetNames(enumEntryCount.GetType()); |
|||
string[] popupEntries = new string[channelCount]; |
|||
for (int i = 0; i < popupEntries.Length; i++) |
|||
popupEntries[i] = enumEntryNames[i]; |
|||
value = EditorGUILayout.Popup(m_Label, value, popupEntries); |
|||
|
|||
if (changeCheckScope.changed) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|||
m_PropertyInfo.SetValue(m_Node, value, null); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 74fdde12d8253bd4c874acc555be0585 |
|||
timeCreated: 1507817885 |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class ChannelMixerControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
float m_Minimum; |
|||
float m_Maximum; |
|||
|
|||
public ChannelMixerControlAttribute(string label = null, float minimum = -2f, float maximum = 2f) |
|||
{ |
|||
m_Label = label; |
|||
m_Minimum = minimum; |
|||
m_Maximum = maximum; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new ChannelMixerControlView(m_Label, m_Minimum, m_Maximum, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class ChannelMixerControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
ChannelMixerNode.ChannelMixer m_ChannelMixer; |
|||
int m_OutChannel; |
|||
|
|||
Slider m_RedSlider; |
|||
Slider m_GreenSlider; |
|||
Slider m_BlueSlider; |
|||
|
|||
float m_Minimum; |
|||
float m_Maximum; |
|||
bool m_Initialized; |
|||
|
|||
public ChannelMixerControlView(string label, float minimum, float maximum, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
m_ChannelMixer = (ChannelMixerNode.ChannelMixer)m_PropertyInfo.GetValue(m_Node, null); |
|||
m_OutChannel = 0; |
|||
|
|||
m_Minimum = minimum; |
|||
m_Maximum = maximum; |
|||
|
|||
if (propertyInfo.PropertyType != typeof(ChannelMixerNode.ChannelMixer)) |
|||
throw new ArgumentException("Property must be of type ChannelMixer.", "propertyInfo"); |
|||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); |
|||
|
|||
if (!string.IsNullOrEmpty(label)) |
|||
Add(new Label(label)); |
|||
|
|||
Action changedOutputRed = () => OnClickButton(0); |
|||
var outputButtonRed = new Button(changedOutputRed); |
|||
Add(outputButtonRed); |
|||
|
|||
Action changedOutputGreen = () => OnClickButton(1); |
|||
var outputButtonGreen = new Button(changedOutputGreen); |
|||
Add(outputButtonGreen); |
|||
|
|||
Action changedOutputBlue = () => OnClickButton(2); |
|||
var outputButtonBlue = new Button(changedOutputBlue); |
|||
Add(outputButtonBlue); |
|||
|
|||
Add(new Label("Red")); |
|||
Action<float> changedRedIn = (s) => { OnChangeSlider(s, 0); }; |
|||
m_RedSlider = new Slider(m_Minimum, m_Maximum, changedRedIn); |
|||
Add(m_RedSlider); |
|||
|
|||
Add(new Label("Green")); |
|||
Action<float> changedGreenIn = (s) => { OnChangeSlider(s, 1); }; |
|||
m_GreenSlider = new Slider(m_Minimum, m_Maximum, changedGreenIn); |
|||
Add(m_GreenSlider); |
|||
|
|||
Add(new Label("Blue")); |
|||
Action<float> changedBlueIn = (s) => { OnChangeSlider(s, 2); }; |
|||
m_BlueSlider = new Slider(m_Minimum, m_Maximum, changedBlueIn); |
|||
Add(m_BlueSlider); |
|||
|
|||
m_Initialized = true; |
|||
ResetSliders(); |
|||
} |
|||
|
|||
void ResetSliders() |
|||
{ |
|||
Vector3 outputChannel = GetOutputChannel(); |
|||
m_RedSlider.value = outputChannel[0]; |
|||
m_GreenSlider.value = outputChannel[1]; |
|||
m_BlueSlider.value = outputChannel[2]; |
|||
} |
|||
|
|||
void OnChangeSlider(float value, int inChannel) |
|||
{ |
|||
if (!m_Initialized) |
|||
return; |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Slider Change"); |
|||
switch (m_OutChannel) |
|||
{ |
|||
case 1: |
|||
m_ChannelMixer.outGreen[inChannel] = value; |
|||
break; |
|||
case 2: |
|||
m_ChannelMixer.outBlue[inChannel] = value; |
|||
break; |
|||
default: |
|||
m_ChannelMixer.outRed[inChannel] = value; |
|||
break; |
|||
} |
|||
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null); |
|||
} |
|||
|
|||
void OnClickButton(int outChannel) |
|||
{ |
|||
m_OutChannel = outChannel; |
|||
ResetSliders(); |
|||
} |
|||
|
|||
Vector3 GetOutputChannel() |
|||
{ |
|||
switch (m_OutChannel) |
|||
{ |
|||
case 1: |
|||
return m_ChannelMixer.outGreen; |
|||
case 2: |
|||
return m_ChannelMixer.outBlue; |
|||
default: |
|||
return m_ChannelMixer.outRed; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 74a26e3294ebad94fa5d78ee95751556 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class CubemapControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public CubemapControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new CubemapControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class CubemapControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
public CubemapControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Cubemap)) |
|||
throw new ArgumentException("Property must be of type Texture.", "propertyInfo"); |
|||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); |
|||
|
|||
if (!string.IsNullOrEmpty(label)) |
|||
Add(new Label(label)); |
|||
|
|||
var cubemapField = new ObjectField { value = (Cubemap) m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Cubemap) }; |
|||
cubemapField.OnValueChanged(OnChange); |
|||
Add(cubemapField); |
|||
} |
|||
|
|||
void OnChange(ChangeEvent<UnityEngine.Object> evt) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Cubemap Change"); |
|||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null); |
|||
Dirty(ChangeType.Repaint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: abdad6e5c36e0994290fcacce2fab066 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[Serializable] |
|||
public struct Toggle |
|||
{ |
|||
public bool isOn; |
|||
public bool isEnabled; |
|||
|
|||
public Toggle(bool on, bool enabled) |
|||
{ |
|||
isOn = on; |
|||
isEnabled = enabled; |
|||
} |
|||
|
|||
public Toggle(bool on) |
|||
{ |
|||
isOn = on; |
|||
isEnabled = true; |
|||
} |
|||
} |
|||
|
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class ToggleControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public ToggleControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new ToggleControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class ToggleControlView : VisualElement, INodeModificationListener |
|||
{ |
|||
GUIContent m_Label; |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
IMGUIContainer m_Container; |
|||
|
|||
public ToggleControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Toggle)) |
|||
throw new ArgumentException("Property must be a Toggle.", "propertyInfo"); |
|||
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)); |
|||
m_Container = new IMGUIContainer(OnGUIHandler); |
|||
Add(m_Container); |
|||
} |
|||
|
|||
public void OnNodeModified(ModificationScope scope) |
|||
{ |
|||
if (scope == ModificationScope.Graph) |
|||
m_Container.Dirty(ChangeType.Repaint); |
|||
} |
|||
|
|||
void OnGUIHandler() |
|||
{ |
|||
var value = (Toggle) m_PropertyInfo.GetValue(m_Node, null); |
|||
|
|||
using (var changeCheckScope = new EditorGUI.ChangeCheckScope()) |
|||
{ |
|||
m_Container.SetEnabled(value.isEnabled); |
|||
|
|||
bool isOn = EditorGUILayout.Toggle(m_Label, value.isOn); |
|||
value = new Toggle(isOn, value.isEnabled); |
|||
if (changeCheckScope.changed) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); |
|||
m_PropertyInfo.SetValue(m_Node, value, null); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e83ab8eb10c20c4fbed2700d4f4f11c |
|||
timeCreated: 1507817885 |
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Slots |
|||
{ |
|||
public class CubemapSlotControlView : VisualElement |
|||
{ |
|||
CubemapInputMaterialSlot m_Slot; |
|||
|
|||
public CubemapSlotControlView(CubemapInputMaterialSlot slot) |
|||
{ |
|||
m_Slot = slot; |
|||
var objectField = new ObjectField { objectType = typeof(Cubemap), value = m_Slot.cubemap }; |
|||
objectField.OnValueChanged(OnValueChanged); |
|||
Add(objectField); |
|||
} |
|||
|
|||
void OnValueChanged(ChangeEvent<Object> evt) |
|||
{ |
|||
var cubemap = evt.newValue as Cubemap; |
|||
if (cubemap != m_Slot.cubemap) |
|||
{ |
|||
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Cubemap"); |
|||
m_Slot.cubemap = cubemap; |
|||
if (m_Slot.owner.onModified != null) |
|||
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b54f542a9d5f7b84e974b54d625d73ea |
|||
timeCreated: 1509718979 |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue