Eduardo Chaves
8 年前
当前提交
e2223047
共有 5 个文件被更改,包括 90 次插入 和 6 次删除
-
2MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
-
7MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
63MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
-
12MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs.meta
2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("HeightToNormal")] |
|||
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction |
|||
{ |
|||
|
|||
public HeightToNormalNode() |
|||
{ |
|||
name = "HeightToNormal"; |
|||
AddSlot("HeightMap", "heightmap", Graphing.SlotType.Input, SlotValueType.sampler2D, Vector4.zero); |
|||
AddSlot("UV", "texCoord", Graphing.SlotType.Input, SlotValueType.Vector2, Vector4.zero); |
|||
AddSlot("Offset", "texOffset", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(0.005f, 0,0,0)); |
|||
AddSlot("Strength", "strength", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(8,0,0,0)); |
|||
|
|||
AddSlot("Normal", "normalRes", Graphing.SlotType.Output, SlotValueType.Vector3, Vector4.zero); |
|||
|
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_ObjectScale"; |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype(), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.AddShaderChunk("float2 offsetU = float2(texCoord.x + texOffset, texCoord.y);", false); |
|||
outputString.AddShaderChunk("float2 offsetV = float2(texCoord.x, texCoord.y + texOffset);", false); |
|||
|
|||
outputString.AddShaderChunk("float normalSample = tex2D(heightmap, texCoord).r;", false); |
|||
outputString.AddShaderChunk("float uSample = tex2D(heightmap, offsetU).r;", false); |
|||
outputString.AddShaderChunk("float vSample = tex2D(heightmap, offsetV).r;", false); |
|||
|
|||
outputString.AddShaderChunk("float uMinusNormal = uSample - normalSample;", false); |
|||
outputString.AddShaderChunk("float vMinusNormal = vSample - normalSample;", false); |
|||
|
|||
outputString.AddShaderChunk("uMinusNormal = uMinusNormal * strength;", false); |
|||
outputString.AddShaderChunk("vMinusNormal = vMinusNormal * strength;", false); |
|||
|
|||
outputString.AddShaderChunk("float3 va = float3(1, 0, uMinusNormal);", false); |
|||
outputString.AddShaderChunk("float3 vb = float3(0, 1, vMinusNormal);", false); |
|||
|
|||
outputString.AddShaderChunk("normalRes = cross(va, vb);", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c943843c9c7424a4d9b629c087d93df5 |
|||
timeCreated: 1495565761 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue