浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Jennifer Nordwall
8 年前
当前提交
b94d71ca
共有 66 个文件被更改,包括 2924 次插入 和 316 次删除
-
146MaterialGraphProject/Assets/Andre/Materials/Mat.mat
-
2MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs
-
2MaterialGraphProject/Assets/Andre/Shaders/TestingGraph.ShaderGraph
-
2MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
-
54MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
26MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
-
127MaterialGraphProject/Assets/GeneratedShader.shader
-
2MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
-
2MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
-
2MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs
-
5MaterialGraphProject/Assets/TestAssets/Materials/Default.mat
-
2MaterialGraphProject/Assets/TestAssets/Teapot.fbx.meta
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template
-
25MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
-
8MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
-
122MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
-
2MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
-
9MaterialGraphProject/Assets/Florent.meta
-
1MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph
-
9MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph.meta
-
81MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat
-
9MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat.meta
-
1MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph
-
9MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph.meta
-
335MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
-
12MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs.meta
-
1MaterialGraphProject/Assets/POM_Graph.ShaderGraph
-
9MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta
-
21MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg
-
75MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg.meta
-
33MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg
-
75MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg.meta
-
12MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg
-
75MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg.meta
-
151MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs.meta
-
64MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs.meta
-
445MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png
-
75MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png.meta
-
137MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga
-
75MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga.meta
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp
-
75MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters.meta
-
133MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs
-
12MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs.meta
-
246MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs
-
12MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs.meta
-
1MaterialGraphProject/Assets/Florent/GeneratedTexture.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs.meta
-
287MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs
2
MaterialGraphProject/Assets/Andre/Shaders/TestingGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
Shader "Hidden/PreviewShader/Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output" { |
|||
Properties { |
|||
Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform("", Float) = 0.1 |
|||
Shader "Graph/Generated.MetallicMasterNode554b91b5-7a00-4f5f-b71a-f7729fcbdee8" |
|||
{ |
|||
Properties |
|||
{ |
|||
[NonModifiableTextureData] TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform("TextureAsset", 2D) = "white" {} |
|||
SubShader { |
|||
// inside SubShader |
|||
SubShader |
|||
{ |
|||
"Queue"="Geometry" |
|||
"IgnoreProjector"="True" |
|||
"Queue"="Geometry" |
|||
// inside Pass |
|||
Blend One Zero |
|||
|
|||
Cull Back |
|||
|
|||
ZTest LEqual |
|||
|
|||
Blend One Zero |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
LOD 200 |
|||
|
|||
CGPROGRAM |
|||
#pragma target 3.0 |
|||
#pragma surface surf Standard vertex:vert |
|||
#pragma glsl |
|||
#pragma debug |
|||
float3 ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25_normalDir; |
|||
float Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform; |
|||
#ifdef UNITY_COMPILER_HLSL |
|||
Texture2D TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform; |
|||
#endif |
|||
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset; |
|||
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength; |
|||
#ifdef UNITY_COMPILER_HLSL |
|||
SamplerState my_linear_repeat_sampler; |
|||
#endif |
|||
#ifdef UNITY_COMPILER_HLSL |
|||
#endif |
|||
inline void unity_HeightToNormal (Texture2D heightmap, float2 texCoord, float texOffset, float strength, out float3 normalRes) |
|||
{ |
|||
float2 offsetU = float2(texCoord.x + texOffset, texCoord.y); |
|||
float2 offsetV = float2(texCoord.x, texCoord.y + texOffset); |
|||
float normalSample = 0; |
|||
float uSample = 0; |
|||
float vSample = 0; |
|||
normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r; |
|||
uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r; |
|||
vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r; |
|||
float uMinusNormal = uSample - normalSample; |
|||
float vMinusNormal = vSample - normalSample; |
|||
uMinusNormal = uMinusNormal * strength; |
|||
vMinusNormal = vMinusNormal * strength; |
|||
float3 va = float3(1, 0, uMinusNormal); |
|||
float3 vb = float3(0, 1, vMinusNormal); |
|||
normalRes = cross(va, vb); |
|||
} |
|||
struct v2f |
|||
{ |
|||
float4 pos : SV_POSITION; |
|||
float4 color : COLOR; |
|||
float3 worldNormal : TEXCOORD1; |
|||
}; |
|||
struct Input |
|||
{ |
|||
float4 color : COLOR; |
|||
half4 meshUV0; |
|||
inline float unity_posterize_float (float input, float stepsize) |
|||
{ |
|||
return floor(input / stepsize) * stepsize; |
|||
} |
|||
}; |
|||
void vert (inout appdata_full v, out Input o) |
|||
{ |
|||
UNITY_INITIALIZE_OUTPUT(Input,o); |
|||
o.meshUV0 = v.texcoord; |
|||
v2f vert (appdata_full v) |
|||
{ |
|||
v2f o = (v2f)0; |
|||
o.pos = UnityObjectToClipPos(v.vertex);; |
|||
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; |
|||
float3 viewDir = UnityWorldSpaceViewDir(worldPos); |
|||
float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex)); |
|||
float3 worldNormal = UnityObjectToWorldNormal(v.normal); |
|||
o.worldNormal = worldNormal; |
|||
} |
|||
|
|||
void surf (Input IN, inout SurfaceOutputStandard o) |
|||
{ |
|||
half4 uv0 = IN.meshUV0; |
|||
float4 UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV = uv0; |
|||
float3 HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes; |
|||
#ifdef UNITY_COMPILER_HLSL |
|||
unity_HeightToNormal (TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform, UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes); |
|||
#endif |
|||
o.Normal = HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes; |
|||
o.Normal += 1e-6; |
|||
return o; |
|||
} |
|||
} |
|||
ENDCG |
|||
} |
|||
half4 frag (v2f IN) : COLOR |
|||
{ |
|||
float3 worldSpaceNormal = normalize(IN.worldNormal); |
|||
float3 ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25 = ShadeSH9(float4(worldSpaceNormal.xyz , 1)); |
|||
float4 Split_f630c862_c9a4_4765_b085_f9b01dd46061 = float4(ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25, 1.0); |
|||
float Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output = unity_posterize_float (Split_f630c862_c9a4_4765_b085_f9b01dd46061.r, Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform); |
|||
return half4(Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, 1.0); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback Off |
|||
} |
|||
FallBack "Diffuse" |
|||
CustomEditor "LegacyIlluminShaderGUI" |
|||
} |
2
MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
2
MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: e9dab59e587c7f244adde1add29b34fc |
|||
folderAsset: yes |
|||
timeCreated: 1495531757 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 85377c065145c6f4380b09435f049950 |
|||
timeCreated: 1495721666 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: Anisotropy |
|||
m_Shader: {fileID: 4800000, guid: 9ab5e16c2083a4fe689209a8c1ae425e, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 0 |
|||
m_EnableInstancingVariants: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- Texture_3db1140f_b814_4ba5_a49c_d40499367921_Uniform: |
|||
m_Texture: {fileID: 2800000, guid: cbf25f5368b2350408963109a1c8f22d, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailAlbedoMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ParallaxMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- Vector1_3c037cd0_a4ae_48b0_8e8c_e1507ff6f738_Uniform: 1 |
|||
- Vector1_da8ece50_8bc4_4e14_b77a_24dfc74c32da_Uniform: 0.817 |
|||
- _BumpScale: 1 |
|||
- _Cutoff: 0.5 |
|||
- _DetailNormalMapScale: 1 |
|||
- _DstBlend: 0 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0.5 |
|||
- _GlossyReflections: 1 |
|||
- _Metallic: 0 |
|||
- _Mode: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _Parallax: 0.02 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 1 |
|||
- _UVSec: 0 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _Color: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: b691b84f941db2740ba393773c55e10e |
|||
timeCreated: 1495722255 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 778b0a6ad2007a14e8beec62e3904ba4 |
|||
timeCreated: 1495717986 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("UV/ParallaxOcclusionMapping")] |
|||
public class ParallaxOcclusionMappingNode : |
|||
AbstractMaterialNode, |
|||
IGeneratesBodyCode, |
|||
IGeneratesFunction, |
|||
IMayRequireMeshUV, |
|||
IMayRequireViewDirection, |
|||
IMayRequireNormal, |
|||
IMayRequireViewDirectionTangentSpace |
|||
{ |
|||
protected const string kInputHeightScaleShaderName = "HeightScale"; |
|||
protected const string kTextureSlotShaderName = "Texture"; |
|||
protected const string kOutputSlotShaderName = "UV"; |
|||
|
|||
public const int HeightScaleSlotId = 0; // 'height_scale'
|
|||
public const int TextureSlotId = 1; // 'tex'
|
|||
public const int OutputSlotId = 2; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
return PreviewMode.Preview3D; |
|||
} |
|||
} |
|||
|
|||
public ParallaxOcclusionMappingNode() |
|||
{ |
|||
name = "ParallaxOcclusionMapping"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public string GetFunctionName() |
|||
{ |
|||
return "unity_parallax_occlusion_mapping_" + precision; |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputHeightScaleSlot()); |
|||
AddSlot(GetTextureSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
|
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { HeightScaleSlotId, TextureSlotId, OutputSlotId }; } |
|||
} |
|||
protected virtual string GetInputHeightScaleName() |
|||
{ |
|||
return kInputHeightScaleShaderName; |
|||
} |
|||
protected virtual MaterialSlot GetInputHeightScaleSlot() |
|||
{ |
|||
return new MaterialSlot( |
|||
HeightScaleSlotId, GetInputHeightScaleName(), kInputHeightScaleShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero); |
|||
} |
|||
protected virtual MaterialSlot GetTextureSlot() |
|||
{ |
|||
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector2, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetTextureSlotName() |
|||
{ |
|||
return kTextureSlotShaderName; |
|||
} |
|||
|
|||
protected virtual string GetOutputSlotName() |
|||
{ |
|||
return kOutputSlotShaderName; |
|||
} |
|||
|
|||
private string inputHeightScaleDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(HeightScaleSlotId).concreteValueType); } |
|||
} |
|||
|
|||
protected virtual string GetFunctionPrototype( |
|||
string heightScale, string tex, string UVs, string viewTangentSpace, string worldSpaceNormal, string worldSpaceViewDirection) |
|||
{ |
|||
return "inline " + precision + "2 " + GetFunctionName() + " (" + |
|||
precision + inputHeightScaleDimension + " " + heightScale + ", " + |
|||
"sampler2D " + tex + ", " + |
|||
precision + "2 " + UVs + ", " + |
|||
precision + "3 " + viewTangentSpace + ", " + |
|||
precision + "3 " + worldSpaceNormal + ", " + |
|||
precision + "3 " + worldSpaceViewDirection + ")"; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration( |
|||
this, |
|||
new[] { HeightScaleSlotId, TextureSlotId }, |
|||
new[] { OutputSlotId }); |
|||
string heightScaleValue = GetSlotValue(HeightScaleSlotId, generationMode); |
|||
string textureValue = GetSlotValue(TextureSlotId, generationMode); |
|||
|
|||
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForSlot(OutputSlotId) + " = " + |
|||
GetFunctionCallBody(heightScaleValue, textureValue) + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk( |
|||
GetFunctionPrototype("heightScale", "tex", "UVs", "viewTangentSpace", "worldSpaceNormal", "worldSpaceViewDirection" ), |
|||
false); |
|||
|
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk(precision + "2 " + "height_map_dimensions = " + precision + "2" + "(256.0f, 256.0f); //HARDCODE", false); |
|||
//height_map.tex.GetDimensions(height_map_dimensions.x, height_map_dimensions.y);
|
|||
|
|||
outputString.AddShaderChunk(precision + "2 texcoord= UVs;", false); |
|||
|
|||
// Compute the current gradients:
|
|||
outputString.AddShaderChunk(precision + "2 " + " texcoords_per_size = texcoord * height_map_dimensions;", false); |
|||
|
|||
// Compute all 4 derivatives in x and y in a single instruction to optimize:
|
|||
outputString.AddShaderChunk("float2 dx, dy;", false); |
|||
|
|||
outputString.AddShaderChunk(" float4 temp_ddx = ddx(float4(texcoords_per_size, texcoord));", false); |
|||
|
|||
outputString.AddShaderChunk("dx.xy = temp_ddx.zw;", false); |
|||
|
|||
outputString.AddShaderChunk("float4 temp_ddy = ddy(float4(texcoords_per_size, texcoord));", false); |
|||
|
|||
outputString.AddShaderChunk("dy.xy = temp_ddy.zw;", false); |
|||
|
|||
// Start the current sample located at the input texture coordinate, which would correspond
|
|||
// to computing a bump mapping result:
|
|||
outputString.AddShaderChunk(precision + "2 " + "result_texcoord = texcoord;", false); |
|||
|
|||
outputString.AddShaderChunk("float height_scale_value = heightScale;", false); |
|||
outputString.AddShaderChunk("float height_scale_adjust = height_scale_value;", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("float per_pixel_height_scale_value = height_scale_value * heightScale;", false); |
|||
|
|||
// Parallax occlusion mapping offset computation
|
|||
//--------------
|
|||
|
|||
// Utilize dynamic flow control to change the number of samples per ray
|
|||
// depending on the viewing angle for the surface. Oblique angles require
|
|||
// smaller step sizes to achieve more accurate precision for computing displacement.
|
|||
// We express the sampling rate as a linear function of the angle between
|
|||
// the geometric normal and the view direction ray:
|
|||
outputString.AddShaderChunk("float max_samples = 30.0f;", false); |
|||
outputString.AddShaderChunk("float min_samples = 4.0f;", false); |
|||
|
|||
outputString.AddShaderChunk("float view_dot_normal= dot(worldSpaceNormal, worldSpaceViewDirection);", false); |
|||
|
|||
outputString.AddShaderChunk("int number_of_steps = (int)lerp(max_samples, min_samples, saturate(view_dot_normal));", false); |
|||
|
|||
// Intersect the view ray with the height field profile along the direction of
|
|||
// the parallax offset ray (computed in the vertex shader. Note that the code is
|
|||
// designed specifically to take advantage of the dynamic flow control constructs
|
|||
// in HLSL and is very sensitive to specific syntax. When converting to other examples,
|
|||
// if still want to use dynamic flow control in the resulting assembly shader,
|
|||
// care must be applied.
|
|||
//
|
|||
// In the below steps we approximate the height field profile as piecewise linear
|
|||
// curve. We find the pair of endpoints between which the intersection between the
|
|||
// height field profile and the view ray is found and then compute line segment
|
|||
// intersection for the view ray and the line segment formed by the two endpoints.
|
|||
// This intersection is the displacement offset from the original texture coordinate.
|
|||
// See the above SI3D 06 paper for more details about the process and derivation.
|
|||
//
|
|||
|
|||
outputString.AddShaderChunk("float current_height = 0.0;", false); |
|||
outputString.AddShaderChunk("float step_size = 1.0 / (float)number_of_steps;", false); |
|||
|
|||
outputString.AddShaderChunk("float previous_height = 1.0;", false); |
|||
outputString.AddShaderChunk("float next_height = 0.0;", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("int step_index = 0;", false); |
|||
|
|||
// Optimization: this should move to vertex shader, however, we compute it here for simplicity of
|
|||
// integration into our shaders for now.
|
|||
outputString.AddShaderChunk("float3 normalized_view_dir_in_tangent_space = normalize(viewTangentSpace.xyz);", false); |
|||
|
|||
// Compute initial parallax displacement direction:
|
|||
outputString.AddShaderChunk("float2 parallax_direction = normalize(viewTangentSpace.xy);", false); |
|||
|
|||
// The length of this vector determines the furthest amount of displacement:
|
|||
outputString.AddShaderChunk("float parallax_direction_length = length(normalized_view_dir_in_tangent_space);", false); |
|||
|
|||
outputString.AddShaderChunk( |
|||
"float max_parallax_amount = sqrt(parallax_direction_length * parallax_direction_length - viewTangentSpace.z * viewTangentSpace.z) / viewTangentSpace.z;", false); |
|||
|
|||
// Compute the actual reverse parallax displacement vector:
|
|||
outputString.AddShaderChunk("float2 parallax_offset_in_tangent_space = parallax_direction * max_parallax_amount;", false); |
|||
|
|||
// Need to scale the amount of displacement to account for different height ranges
|
|||
// in height maps. This is controlled by an artist-editable parameter:
|
|||
outputString.AddShaderChunk("parallax_offset_in_tangent_space *= saturate(heightScale);", false); |
|||
|
|||
outputString.AddShaderChunk("float2 texcoord_offset_per_step = step_size * parallax_offset_in_tangent_space;", false); |
|||
|
|||
outputString.AddShaderChunk(precision + "2 " + "current_texcoord_offset = texcoord;", false); |
|||
outputString.AddShaderChunk("float current_bound = 1.0;", false); |
|||
|
|||
outputString.AddShaderChunk("float current_parallax_amount = 0.0;", false); |
|||
|
|||
outputString.AddShaderChunk("float2 pt1 = 0;", false); |
|||
outputString.AddShaderChunk("float2 pt2 = 0;", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk(precision + "2 " + "temp_texcoord_offset = 0;", false); |
|||
|
|||
outputString.AddShaderChunk("while (step_index < number_of_steps)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("current_texcoord_offset -= texcoord_offset_per_step;", false); |
|||
|
|||
// Sample height map which in this case is stored in the alpha channel of the normal map:
|
|||
outputString.AddShaderChunk("current_height = tex2Dgrad(tex, current_texcoord_offset, dx, dy).r;", false); |
|||
|
|||
outputString.AddShaderChunk("current_bound -= step_size;", false); |
|||
|
|||
outputString.AddShaderChunk("if (current_height > current_bound)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("pt1 = float2(current_bound, current_height);", false); |
|||
|
|||
outputString.AddShaderChunk("pt2 = float2(current_bound + step_size, previous_height);", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("temp_texcoord_offset = current_texcoord_offset - texcoord_offset_per_step;", false); |
|||
|
|||
outputString.AddShaderChunk("step_index = number_of_steps + 1;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("else", false); |
|||
|
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("step_index++;", false); |
|||
outputString.AddShaderChunk("previous_height = current_height;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("} // End of while ( step_index < number_of_steps)", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("float delta2 = pt2.x - pt2.y;", false); |
|||
outputString.AddShaderChunk("float delta1 = pt1.x - pt1.y;", false); |
|||
|
|||
outputString.AddShaderChunk("float denominator = delta2 - delta1;", false); |
|||
|
|||
// SM 3.0 and above requires a check for divide by zero since that operation
|
|||
// will generate an 'Inf' number instead of 0
|
|||
outputString.AddShaderChunk("if (denominator== 0.0f) ", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("current_parallax_amount= 0.0f;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("else", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("current_parallax_amount= (pt1.x* delta2 - pt2.x* delta1) / denominator;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
outputString.AddShaderChunk("float2 parallax_offset = parallax_offset_in_tangent_space * (1.0f - current_parallax_amount);", false); |
|||
|
|||
// The computed texture offset for the displaced point on the pseudo-extruded surface:
|
|||
outputString.AddShaderChunk("float2 parallaxed_texcoord = texcoord - parallax_offset;", false); |
|||
|
|||
outputString.AddShaderChunk("return parallaxed_texcoord;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
protected virtual string GetFunctionCallBody(string heightScale, string texValue) |
|||
{ |
|||
var channel = UVChannel.uv0; |
|||
|
|||
return GetFunctionName() + " (" + |
|||
heightScale + ", " + |
|||
texValue + ", " + |
|||
channel.GetUVName() + ", " + |
|||
ShaderGeneratorNames.TangentSpaceViewDirection + ", " + |
|||
ShaderGeneratorNames.WorldSpaceNormal + ", " + |
|||
ShaderGeneratorNames.WorldSpaceViewDirection + ")"; |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
return channel == UVChannel.uv0; |
|||
} |
|||
public bool RequiresViewDirectionTangentSpace() |
|||
{ |
|||
return true; |
|||
} |
|||
public bool RequiresNormal() |
|||
{ |
|||
return true; |
|||
} |
|||
public bool RequiresViewDirection() |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: daac036bc09be70438149124ccd0a11b |
|||
timeCreated: 1495700896 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/POM_Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 96bf971901c0d7c468d21e8511ced163 |
|||
timeCreated: 1495479560 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: fd9dcc0042b460046917799942414fe0 |
|||
timeCreated: 1495721640 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ff1fa8d5d8b0945499c7785f1b0f2a4f |
|||
timeCreated: 1495721640 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cbf25f5368b2350408963109a1c8f22d |
|||
timeCreated: 1495721640 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine.MaterialGraph; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
class ConvolutionFilterControlPresenter : GraphControlPresenter |
|||
{ |
|||
enum KernelPresets |
|||
{ |
|||
Presets, |
|||
BoxBlur, |
|||
GaussianBlur, |
|||
EdgesDetection, |
|||
EnhanceEdges, |
|||
Sharpen, |
|||
Emboss, |
|||
}; |
|||
|
|||
private void ApplyPreset(KernelPresets preset, ref float[,] values, ref float divisor) |
|||
{ |
|||
if (preset == KernelPresets.BoxBlur) |
|||
{ |
|||
values = new float[,] { {1,1,1,1,1}, |
|||
{1,1,1,1,1}, |
|||
{1,1,1,1,1}, |
|||
{1,1,1,1,1}, |
|||
{1,1,1,1,1} }; |
|||
divisor = 25; |
|||
} |
|||
if (preset == KernelPresets.GaussianBlur) |
|||
{ |
|||
values = new float[,] { { 1, 4, 6, 4, 1}, |
|||
{ 4,16,24,16, 4}, |
|||
{ 6,24,36,24, 6}, |
|||
{ 4,16,24,16, 4}, |
|||
{ 1, 4, 6, 4, 1} }; |
|||
divisor = 256; |
|||
} |
|||
if (preset == KernelPresets.EdgesDetection) |
|||
{ |
|||
values = new float[,] { {-1,-1,-1, -1,-1}, |
|||
{-1,-2,-2, -2,-1}, |
|||
{-1,-2, 33,-2,-1}, |
|||
{-1,-2,-2, -2,-1}, |
|||
{-1,-1,-1, -1,-1} }; |
|||
divisor = 1; |
|||
} |
|||
if (preset == KernelPresets.EnhanceEdges) |
|||
{ |
|||
values = new float[,] { { 0, 0, 0, 0, 0}, |
|||
{ 0, 1, 1, 1, 0}, |
|||
{ 0, 1,-7, 1, 0}, |
|||
{ 0, 1, 1, 1, 0}, |
|||
{ 0, 0, 0, 0, 0} }; |
|||
divisor = 1; |
|||
} |
|||
if (preset == KernelPresets.Sharpen) |
|||
{ |
|||
values = new float[,] { {-1,-1,-1, -1,-1}, |
|||
{-1, 2, 2, 2,-1}, |
|||
{-1, 2, 8, 2,-1}, |
|||
{-1, 2, 2, 2,-1}, |
|||
{-1,-1,-1, -1,-1} }; |
|||
divisor = 8; |
|||
} |
|||
if (preset == KernelPresets.Emboss) |
|||
{ |
|||
values = new float[,] { {-1,-1,-1,-1, 0}, |
|||
{-1,-1,-1, 0, 1}, |
|||
{-1,-1, 0, 1, 1}, |
|||
{-1, 0, 1, 1, 1}, |
|||
{ 0, 1, 1, 1, 1} }; |
|||
divisor = 1; |
|||
} |
|||
} |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var tNode = node as ConvolutionFilterNode; |
|||
if (tNode == null) |
|||
return; |
|||
|
|||
float divisor = tNode.GetConvolutionDivisor(); |
|||
float[,] values = new float[5,5]; |
|||
for (int row = 0; row < 5; ++row) |
|||
{ |
|||
for (int col = 0; col < 5; ++col) |
|||
{ |
|||
values[row,col] = tNode.GetConvolutionWeight(row,col); |
|||
} |
|||
} |
|||
|
|||
EditorGUILayout.BeginVertical(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
EditorGUILayout.LabelField("Kernel"); |
|||
KernelPresets kernelPresets = KernelPresets.Presets; |
|||
kernelPresets = (KernelPresets)EditorGUILayout.EnumPopup(kernelPresets); |
|||
ApplyPreset(kernelPresets, ref values, ref divisor); |
|||
|
|||
for (int col = 0; col < 5; ++col) |
|||
{ |
|||
EditorGUILayout.BeginHorizontal(); |
|||
for (int row = 0; row < 5; ++row) |
|||
{ |
|||
values[row, col] = EditorGUILayout.FloatField(values[row, col], GUILayout.Width(35)); |
|||
} |
|||
EditorGUILayout.EndHorizontal(); |
|||
} |
|||
EditorGUILayout.Space(); |
|||
|
|||
divisor = EditorGUILayout.FloatField("Divisor", divisor); |
|||
|
|||
EditorGUILayout.EndVertical(); |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
tNode.SetConvolutionDivisor(divisor); |
|||
for (int row = 0; row < 5; ++row) |
|||
{ |
|||
for (int col = 0; col < 5; ++col) |
|||
{ |
|||
tNode.SetConvolutionWeight(row, col, values[row, col]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return (EditorGUIUtility.singleLineHeight * 10 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class ConvolutionFilterNodePresenter : PropertyNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<ConvolutionFilterControlPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter>(base.GetControlData()) { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f3a416c372d21b6479241e837d4257da |
|||
timeCreated: 1495705790 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.MaterialGraph; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
[Serializable] |
|||
class SamplerStateControlPresenter : GraphControlPresenter |
|||
{ |
|||
|
|||
private string[] samplerFilterMode; |
|||
private string[] samplerWrapMode; |
|||
|
|||
private string[] _samplerFilterMode |
|||
{ |
|||
get |
|||
{ |
|||
if (samplerFilterMode == null) |
|||
samplerFilterMode = Enum.GetNames(typeof(SamplerStateNode.FilterMode)); |
|||
return samplerFilterMode; |
|||
} |
|||
} |
|||
|
|||
private string[] _samplerWrapMode |
|||
{ |
|||
get |
|||
{ |
|||
if (samplerWrapMode == null) |
|||
samplerWrapMode = Enum.GetNames(typeof(SamplerStateNode.WrapMode)); |
|||
return samplerWrapMode; |
|||
} |
|||
} |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var cNode = node as UnityEngine.MaterialGraph.SamplerStateNode; |
|||
if (cNode == null) |
|||
return; |
|||
|
|||
cNode.filter = (SamplerStateNode.FilterMode)EditorGUILayout.Popup((int)cNode.filter, _samplerFilterMode, EditorStyles.popup); |
|||
cNode.wrap = (SamplerStateNode.WrapMode)EditorGUILayout.Popup((int)cNode.wrap, _samplerWrapMode, EditorStyles.popup); |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class SamplerStateNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<SamplerStateControlPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8ffcc48ccff1aea44b90acb362bc0dfc |
|||
timeCreated: 1495659152 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
class TextureSamplerContolPresenter : GraphControlPresenter |
|||
{ |
|||
private string[] m_TextureTypeNames; |
|||
private string[] textureTypeNames |
|||
{ |
|||
get |
|||
{ |
|||
if (m_TextureTypeNames == null) |
|||
m_TextureTypeNames = Enum.GetNames(typeof(TextureType)); |
|||
return m_TextureTypeNames; |
|||
} |
|||
} |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var tNode = node as UnityEngine.MaterialGraph.TextureAssetNode; |
|||
if (tNode == null) |
|||
return; |
|||
|
|||
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState); |
|||
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture; |
|||
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup); |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class TextureSamplerNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<TextureSamplerContolPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 86fe3d2371b24d34399f4b116a238d45 |
|||
timeCreated: 1495638407 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5d84e1086e00e3347aaa0bbba206bb80 |
|||
timeCreated: 1495717214 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
137
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: e017404169662f041a969b0a924cc2ed |
|||
timeCreated: 1495717224 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: b5a88303611082242a4eb08e645752d2 |
|||
timeCreated: 1495717081 |
|||
licenseType: Pro |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
serializedVersion: 4 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -1 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spritePixelsToUnits: 100 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
spritePackingTag: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
SubShader |
|||
{ |
|||
${Tags} |
|||
${Blending} |
|||
${Culling} |
|||
${ZTest} |
|||
${ZWrite} |
|||
|
|||
LOD ${LOD} |
|||
|
|||
CGPROGRAM |
|||
#include "Tessellation.cginc" |
|||
#pragma target 4.6 |
|||
#pragma surface surf ${LightingFunctionName} ${VertexShaderDecl} vertex:Displacement tessellate:tessEdge tessphong:_Phong |
|||
#pragma glsl |
|||
#pragma debug |
|||
|
|||
|
|||
//Tessellation Edge Function |
|||
float4 tessEdge(appdata v0, appdata v1, appdata v2) |
|||
{ |
|||
float quality = 20-(_Subdivision * 2); |
|||
return UnityEdgeLengthBasedTess(v0.vertex, v1.vertex, v2.vertex, quality); |
|||
} |
|||
|
|||
//Tessellation Vertex Function |
|||
void Displacement (inout appdata v) |
|||
{ |
|||
float d = tex2Dlod(_DisplacementTex, float4(v.texcoord.xy * (_DisplacementTex_ST.xy * float2(_WeaveScale*25, _WeaveScale*25)) + _DisplacementTex_ST.zw, 0, 0)).r * _Displacement*0.1; |
|||
v.vertex.xyz += v.normal * (d * 0.5); |
|||
} |
|||
|
|||
${ShaderFunctions} |
|||
${ShaderPropertyUsages} |
|||
|
|||
struct Input |
|||
{ |
|||
${ShaderInputs} |
|||
}; |
|||
|
|||
void vert (inout appdata_full v, out Input o) |
|||
{ |
|||
UNITY_INITIALIZE_OUTPUT(Input,o); |
|||
${VertexShaderBody} |
|||
} |
|||
|
|||
void surf (Input IN, inout ${SurfaceOutputStructureName} o) |
|||
{ |
|||
${PixelShaderBody} |
|||
} |
|||
ENDCG |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 71a3d46ddb1693340a7de3973be90309 |
|||
timeCreated: 1481194716 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7ed888a282fe7b54e968311cd68c4862 |
|||
folderAsset: yes |
|||
timeCreated: 1495638073 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine.MaterialGraph; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Sampler State")] |
|||
public class SamplerStateNode : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
|
|||
public enum FilterMode |
|||
{ |
|||
Linear, |
|||
Point |
|||
} |
|||
|
|||
public enum WrapMode |
|||
{ |
|||
Repeat, |
|||
Clamp |
|||
} |
|||
|
|||
static Dictionary<FilterMode, string> filterMode = new Dictionary<FilterMode, string> |
|||
{ |
|||
{FilterMode.Linear, "_linear"}, |
|||
{FilterMode.Point, "_point"}, |
|||
}; |
|||
|
|||
static Dictionary<WrapMode, string> wrapMode = new Dictionary<WrapMode, string> |
|||
{ |
|||
{WrapMode.Repeat, "_repeat"}, |
|||
{WrapMode.Clamp, "_clamp"}, |
|||
}; |
|||
|
|||
|
|||
[SerializeField] |
|||
private FilterMode m_filter = FilterMode.Linear; |
|||
|
|||
|
|||
public FilterMode filter |
|||
{ |
|||
get { return m_filter; } |
|||
set |
|||
{ |
|||
if (m_filter == value) |
|||
return; |
|||
|
|||
m_filter = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
private WrapMode m_wrap = WrapMode.Repeat; |
|||
|
|||
|
|||
public WrapMode wrap |
|||
{ |
|||
get { return m_wrap; } |
|||
set |
|||
{ |
|||
if (m_wrap == value) |
|||
return; |
|||
|
|||
m_wrap = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public SamplerStateNode() |
|||
{ |
|||
name = "SamplerState"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public override bool hasPreview { get { return false; } } |
|||
|
|||
private const int kOutputSlotId = 0; |
|||
private const string kOutputSlotName = "Sampler Output"; |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.SamplerState, Vector4.zero, false)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotId }); |
|||
} |
|||
|
|||
/* |
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.SamplerState; } |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName + "HEEEEEEYYYYY", |
|||
m_PropType = PropertyType.Float, |
|||
// m_Float = filterMode[filter];
|
|||
}; |
|||
} |
|||
|
|||
*/ |
|||
|
|||
|
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
// GetVariableNameForSlot();
|
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
// var slot = FindSlot<MaterialSlot>(slotId);
|
|||
//if (slot == null)
|
|||
// throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
|
|||
|
|||
return GetVariableNameForNode(); |
|||
} |
|||
|
|||
//my_linear_repeat_sampler
|
|||
public override string GetVariableNameForNode() |
|||
{ |
|||
return "my" + filterMode[filter] + wrapMode[wrap] + "_sampler"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5fe2c333e043511478cc507ee61a8c21 |
|||
timeCreated: 1495658099 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Input/Texture/Texture Sampler")] |
|||
public class TextureSamplerNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
private const string kTextureAssetName = "Texture Asset"; |
|||
private const string kUVSlotName = "UV"; |
|||
private const string kSamplerName = "Sampler"; |
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
|
|||
public const int TextureAssetSlotId = 0; |
|||
public const int UVSlotId = 1; |
|||
public const int SamplerSlotId = 2; |
|||
public const int OutputSlotRGBAId = 3; |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture2D texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture2D defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture2D defaultTexture {get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
|
|||
|
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public TextureSamplerNode() |
|||
{ |
|||
name = "TextureSamplerNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(TextureAssetSlotId, kTextureAssetName, kTextureAssetName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(UVSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(SamplerSlotId, kSamplerName, kSamplerName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { OutputSlotRGBAId, SamplerSlotId, UVSlotId, TextureAssetSlotId }; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
|
|||
//Texture input slot
|
|||
var textureSlot = FindInputSlot<MaterialSlot>(TextureAssetSlotId); |
|||
var textureAssetName = ""; |
|||
var edgesTexture = owner.GetEdges(textureSlot.slotReference).ToList(); |
|||
|
|||
if (edgesTexture.Count > 0) |
|||
{ |
|||
var edge = edgesTexture[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
textureAssetName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Texture2D, true); |
|||
} |
|||
|
|||
//UV input slot
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId); |
|||
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var edgesUV = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
|
|||
if (edgesUV.Count > 0) |
|||
{ |
|||
var edge = edgesUV[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
|
|||
//Sampler input slot
|
|||
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId); |
|||
var samplerName = "my_linear_repeat_sampler"; |
|||
|
|||
if (samplerSlot == null) |
|||
return; |
|||
|
|||
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList(); |
|||
|
|||
if (edgesSampler.Count > 0) |
|||
{ |
|||
var edge = edgesSampler[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + "_Uniform = " + precision + "4(0,0,0,0);", true); |
|||
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true); |
|||
string body = textureAssetName + ".Sample(" + samplerName + ", " + uvName + ");"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
|
|||
visitor.AddShaderChunk(GetVariableNameForNode() + "_Uniform" + " = " + body, true); |
|||
|
|||
visitor.AddShaderChunk("#endif", true); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ /* |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
*/ |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
|
|||
//Sampler input slot
|
|||
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId); |
|||
var samplerName = "my_linear_repeat_sampler"; |
|||
|
|||
if (samplerSlot == null) |
|||
return; |
|||
|
|||
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList(); |
|||
|
|||
if (edgesSampler.Count > 0) |
|||
{ |
|||
var edge = edgesSampler[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true); |
|||
} |
|||
|
|||
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false); |
|||
visitor.AddShaderChunk(samplerSlot.valueType + " " + samplerName + ";", true); |
|||
visitor.AddShaderChunk("#endif", false); |
|||
} |
|||
|
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture; } } |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
} |
|||
|
|||
//prevent validation errors when a sampler2D input is missing
|
|||
//use on any input requiring a TextureAssetNode
|
|||
public override void ValidateNode() |
|||
{ |
|||
base.ValidateNode(); |
|||
var slot = FindInputSlot<MaterialSlot>(TextureAssetSlotId); |
|||
if (slot == null) |
|||
return; |
|||
|
|||
var edges = owner.GetEdges(slot.slotReference).ToList(); |
|||
hasError |= edges.Count == 0; |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5ca9d434229e11f44888abcbf66062a5 |
|||
timeCreated: 1495637741 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
guid: fbb15485f0112484eaa58e88a4ac393f |
|
|||
fileFormatVersion: 2 |
|||
guid: 930d27407d5f02d4a931a8a2aaf451cf |
|||
timeCreated: 1495638643 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Art/Filters/Convolution")] |
|||
public class ConvolutionFilterNode : Function2Input, IGeneratesFunction, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
private const string kUVSlotName = "UV"; |
|||
private const string kTextureSlotName = "Texture"; |
|||
private const int kNumConvolutionVector4 = 7; |
|||
|
|||
[SerializeField] |
|||
private Vector4[] m_ConvolutionFilter = new Vector4[kNumConvolutionVector4] |
|||
{ new Vector4(1,1,1,1), |
|||
new Vector4(1,1,1,1), |
|||
new Vector4(1,1,1,1), |
|||
new Vector4(1,1,1,1), |
|||
new Vector4(1,1,1,1), |
|||
new Vector4(1,1,1,1), |
|||
new Vector4(1,0,0,25.0f) }; |
|||
|
|||
private void GetPositionInData(int row, int col, out int vectorIndex, out int vectorOffset) |
|||
{ |
|||
row = Math.Max(row, 0); |
|||
col = Math.Max(col, 0); |
|||
|
|||
row = Math.Min(row, 4); |
|||
col = Math.Min(col, 4); |
|||
|
|||
int valueIndex = col * 5 + row; |
|||
vectorIndex = valueIndex / 4; |
|||
vectorOffset = valueIndex % 4; |
|||
} |
|||
|
|||
public float GetConvolutionDivisor() |
|||
{ |
|||
return m_ConvolutionFilter[6].w; |
|||
} |
|||
|
|||
public void SetConvolutionDivisor(float value) |
|||
{ |
|||
if (value == m_ConvolutionFilter[6].w) |
|||
return; |
|||
|
|||
m_ConvolutionFilter[6].w = value; |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
|
|||
public float GetConvolutionWeight(int row, int col) |
|||
{ |
|||
int vectorIndex; |
|||
int vectorOffset; |
|||
GetPositionInData(row, col, out vectorIndex, out vectorOffset); |
|||
|
|||
switch(vectorOffset) |
|||
{ |
|||
case 0: return m_ConvolutionFilter[vectorIndex].x; |
|||
case 1: return m_ConvolutionFilter[vectorIndex].y; |
|||
case 2: return m_ConvolutionFilter[vectorIndex].z; |
|||
default: return m_ConvolutionFilter[vectorIndex].w; |
|||
} |
|||
} |
|||
|
|||
public void SetConvolutionWeight(int row, int col, float value) |
|||
{ |
|||
float prevValue = GetConvolutionWeight(row, col); |
|||
|
|||
if (value == prevValue) |
|||
return; |
|||
|
|||
int vectorIndex; |
|||
int vectorOffset; |
|||
GetPositionInData(row, col, out vectorIndex, out vectorOffset); |
|||
|
|||
switch (vectorOffset) |
|||
{ |
|||
case 0: m_ConvolutionFilter[vectorIndex].x = value; break; |
|||
case 1: m_ConvolutionFilter[vectorIndex].y = value; break; |
|||
case 2: m_ConvolutionFilter[vectorIndex].z = value; break; |
|||
default: m_ConvolutionFilter[vectorIndex].w = value; break; |
|||
} |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_convolution_" + precision; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(InputSlot1Id, kTextureSlotName, kTextureSlotName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero, false); |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(InputSlot2Id, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, kOutputSlotShaderName, kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector4, Vector4.zero); |
|||
} |
|||
|
|||
public ConvolutionFilterNode() |
|||
{ |
|||
name = "Convolution"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
return PreviewMode.Preview2D; |
|||
} |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (generationMode.IsPreview()) |
|||
{ |
|||
string propGuid = guid.ToString().Replace("-", "_"); |
|||
for (int i = 0; i < kNumConvolutionVector4; ++i) |
|||
{ |
|||
visitor.AddShaderChunk(precision + "4 " + GetPropertyName(i, propGuid) + ";", true); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private string GetPropertyName(int index, string nodeGuid) |
|||
{ |
|||
return "convolutionFilter" + index + "_" + nodeGuid; |
|||
} |
|||
|
|||
public override void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId }); |
|||
|
|||
if (!generationMode.IsPreview()) |
|||
{ |
|||
string propGuid = guid.ToString().Replace("-", "_"); |
|||
for (int i = 0; i < kNumConvolutionVector4; ++i) |
|||
{ |
|||
visitor.AddShaderChunk(precision + "4 " + GetPropertyName(i, propGuid) + "=" + precision + "4 (" + m_ConvolutionFilter[i].x + ", " + m_ConvolutionFilter[i].y + ", " + m_ConvolutionFilter[i].z + ", " + m_ConvolutionFilter[i].w + ");", true); |
|||
} |
|||
} |
|||
|
|||
string samplerName = GetSlotValue(InputSlot1Id, generationMode); |
|||
|
|||
//uv
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot2Id); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var baseUV = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
var uvEdges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
if (uvEdges.Count > 0) |
|||
{ |
|||
var uvEdge = uvEdges[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(uvEdge.outputSlot.nodeGuid); |
|||
baseUV = ShaderGenerator.AdaptNodeOutput(fromNode, uvEdge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
//texelSize
|
|||
string texelSize = samplerName + "_TexelSize.xy"; |
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(samplerName, baseUV, texelSize) + ";", true); |
|||
|
|||
|
|||
} |
|||
|
|||
protected string GetFunctionCallBody(string samplerName, string baseUv, string texelSize) |
|||
{ |
|||
string propGuid = guid.ToString().Replace("-", "_"); |
|||
|
|||
return GetFunctionName() + " (" + samplerName + ", " + baseUv + ", " |
|||
+ GetPropertyName(0, propGuid) + ", " |
|||
+ GetPropertyName(1, propGuid) + ", " |
|||
+ GetPropertyName(2, propGuid) + ", " |
|||
+ GetPropertyName(3, propGuid) + ", " |
|||
+ GetPropertyName(4, propGuid) + ", " |
|||
+ GetPropertyName(5, propGuid) + ", " |
|||
+ GetPropertyName(6, propGuid) + ", " |
|||
+ texelSize + ")"; |
|||
} |
|||
|
|||
protected override string GetFunctionPrototype(string arg1Name, string arg2Name) |
|||
{ |
|||
string propGuid = guid.ToString().Replace("-", "_"); |
|||
|
|||
return "inline " + precision + "4 " + GetFunctionName() + " (" |
|||
+ "sampler2D " + arg1Name + ", " |
|||
+ precision + "2 " + arg2Name + ", " |
|||
+ precision + "4 weights0," |
|||
+ precision + "4 weights1," |
|||
+ precision + "4 weights2," |
|||
+ precision + "4 weights3," |
|||
+ precision + "4 weights4," |
|||
+ precision + "4 weights5," |
|||
+ precision + "4 weights6, float2 texelSize)"; |
|||
} |
|||
|
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
|
|||
outputString.AddShaderChunk(GetFunctionPrototype("textSampler", "baseUv"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("fixed4 fetches = fixed4(0,0,0,0);", false); |
|||
outputString.AddShaderChunk("fixed weight = 1;", false); |
|||
|
|||
string[] channelNames = { ".x", ".y", ".z", ".w" }; |
|||
for(int col=0; col < 5; ++col) |
|||
{ |
|||
for(int row=0; row < 5; ++row) |
|||
{ |
|||
int valueIndex = col * 5 + row; |
|||
int vectorIndex = valueIndex / 4; |
|||
int vectorOffset = valueIndex % 4; |
|||
outputString.AddShaderChunk("weight = weights" + vectorIndex + channelNames[vectorOffset] + ";", false); |
|||
outputString.AddShaderChunk("fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2("+(row-2)+","+(col-2)+"));", false); |
|||
} |
|||
} |
|||
|
|||
outputString.AddShaderChunk("fetches /= weights6.w;", false); |
|||
outputString.AddShaderChunk("return fetches;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
//prevent validation errors when a sampler2D input is missing
|
|||
//use on any input requiring a TextureAssetNode
|
|||
public override void ValidateNode() |
|||
{ |
|||
base.ValidateNode(); |
|||
var slot = FindInputSlot<MaterialSlot>(InputSlot1Id); |
|||
if (slot == null) |
|||
return; |
|||
|
|||
var edges = owner.GetEdges(slot.slotReference).ToList(); |
|||
hasError |= edges.Count == 0; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
string propGuid = guid.ToString().Replace("-", "_"); |
|||
for (int i = 0; i < kNumConvolutionVector4; ++i) |
|||
{ |
|||
properties.Add(new PreviewProperty { m_Name = GetPropertyName(i, propGuid), m_PropType = PropertyType.Vector4, m_Vector4 = m_ConvolutionFilter[i] }); |
|||
} |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot2Id); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue