|
|
|
|
|
|
namespace UnityEngine.MaterialGraph |
|
|
|
{ |
|
|
|
[Title("UV/Tri-Planar Mapping")] |
|
|
|
public class UVTriPlanar : Function2Input, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition |
|
|
|
public class UVTriPlanar : Function3Input, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition |
|
|
|
private const string kTileSlotName = "Tile"; |
|
|
|
private const string kBlendSlotName = "Blend"; |
|
|
|
|
|
|
|
protected override string GetFunctionName() |
|
|
|
|
|
|
|
|
|
|
protected override MaterialSlot GetInputSlot2() |
|
|
|
{ |
|
|
|
return new MaterialSlot(InputSlot2Id, kBlendSlotName, kBlendSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one); |
|
|
|
return new MaterialSlot(InputSlot2Id, kTileSlotName, kTileSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one); |
|
|
|
} |
|
|
|
|
|
|
|
protected override MaterialSlot GetInputSlot3() |
|
|
|
{ |
|
|
|
return new MaterialSlot(InputSlot3Id, kBlendSlotName, kBlendSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one); |
|
|
|
} |
|
|
|
|
|
|
|
protected override MaterialSlot GetOutputSlot() |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override string GetFunctionPrototype(string arg1Name, string arg2Name) |
|
|
|
protected override string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name) |
|
|
|
+ "sampler2D " + arg1Name + ", " + precision + " " + arg2Name + ", float3 normal, float3 pos)"; |
|
|
|
+ "sampler2D " + arg1Name + ", " |
|
|
|
+ precision + " " + arg2Name + ", " |
|
|
|
+ precision + " " + arg3Name + |
|
|
|
", float3 normal, float3 pos)"; |
|
|
|
protected override string GetFunctionCallBody(string input1Value, string input2Value) |
|
|
|
protected override string GetFunctionCallBody(string input1Value, string input2Value, string input3Value) |
|
|
|
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ", IN.worldNormal, IN.worldPos)"; |
|
|
|
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ", " + input3Value + ", IN.worldNormal, IN.worldPos)"; |
|
|
|
} |
|
|
|
|
|
|
|
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|
|
|
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2", "arg3"), false); |
|
|
|
// create UVs from position
|
|
|
|
outputString.AddShaderChunk("fixed3 uvs = pos * arg2;", false); |
|
|
|
outputString.AddShaderChunk("half3 blend = abs(normal);", false); |
|
|
|
|
|
|
|
//control the influence of the blend
|
|
|
|
outputString.AddShaderChunk("blend = lerp(0, 1, arg2);", false); |
|
|
|
outputString.AddShaderChunk("half3 blend = pow(abs(normal), arg3);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cx = tex2D(arg1, pos.yz);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cy = tex2D(arg1, pos.xz);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cz = tex2D(arg1, pos.xy);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cx = tex2D(arg1, uvs.yz);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cy = tex2D(arg1, uvs.xz);", false); |
|
|
|
outputString.AddShaderChunk("fixed4 cz = tex2D(arg1, uvs.xy);", false); |
|
|
|
|
|
|
|
|
|
|
|
// blend the textures based on weights
|
|
|
|