浏览代码

Adding 3d checkerboard & 3d output from sphere dent

/main
ChrisTchou 7 年前
当前提交
5c5083d0
共有 5 个文件被更改,包括 78 次插入4 次删除
  1. 6
      MaterialGraphProject/Assets/NewNodes/WIP/SphericalIndentationNode.cs
  2. 2
      MaterialGraphProject/Assets/SphereDent.ShaderGraph
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  4. 61
      MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs
  5. 12
      MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs.meta

6
MaterialGraphProject/Assets/NewNodes/WIP/SphericalIndentationNode.cs


{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero },
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UVW texture coordinates", slotValueType = SlotValueType.Vector3, value = Vector4.zero },
new AnyNodeSlot { slotId= 5, name = "outNormal", description = "Output Normal in tangent space", slotValueType = SlotValueType.Vector3, value = Vector4.zero }
};
}

"float3 sphereCenter = float3(center, height);\n" +
"float3 edgeA = sphereCenter - cur;\n" +
"float a2 = dot(edgeA, edgeA);\n" +
"outUVs= inUVs;\n" +
"outUVs= float3(inUVs.xy, 0.0f);\n" +
"outNormal= float3(0.0f, 0.0f, 1.0f);\n" +
"if (a2 < radius2)\n" +
"{\n" +

" float x = cosineR * a - sqrt(-a2 + radius2 + a2 * cosineR * cosineR);\n" +
" float3 intersectedEdge = cur + tangentSpaceViewDirection * x;\n" +
" outNormal= normalize(sphereCenter - intersectedEdge);\n" +
" outUVs = intersectedEdge.xy;\n" +
" outUVs = intersectedEdge.xyz;\n" +
"}\n";
}

2
MaterialGraphProject/Assets/SphereDent.ShaderGraph
文件差异内容过多而无法显示
查看文件

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(SphereWarpNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphericalIndentationNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboardNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
typeMapper[typeof(RemapMasterNode)] = typeof(RemapMasterNodePresenter);
typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);

61
MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Procedural/AACheckerboard3d")]
public class AACheckerboard3dNode : AnyNode<AACheckerboard3dNode.Definition>
{
public class Definition : IAnyNodeDefinition
{
public string name { get { return "AACheckerboard3d"; } }
public AnyNodeProperty[] properties
{
get
{
return new AnyNodeProperty[]
{
// slotId is the 'immutable' value we used to connect things
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UVW coords", propertyType = PropertyType.Vector3, value = Vector4.zero, state = AnyNodePropertyState.Slot },
new AnyNodeProperty { slotId= 1, name = "A", description = "color A", propertyType = PropertyType.Vector4, value= new Vector4(0.2f, 0.2f, 0.2f, 0.2f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 2, name = "B", description = "color B", propertyType = PropertyType.Vector4, value= new Vector4(0.7f, 0.7f, 0.7f, 0.7f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 3, name = "aaTweak", description = "AA Tweak", propertyType = PropertyType.Vector3, value= new Vector4(0.05f, 3.0f, 0.0f, 0.0f),state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 4, name = "frequency", description = "Frequency", propertyType = PropertyType.Vector3, value = Vector4.one, state = AnyNodePropertyState.Constant },
};
}
}
public AnyNodeSlot[] outputs
{
get
{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 5, name = "outColor", description = "Output color", slotValueType = SlotValueType.Vector4, value = Vector4.zero }
};
}
}
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { }; } }
public string hlsl
{
get
{
return
"float3 dx = ddx(inUVs);\n" +
"float3 dy = ddy(inUVs);\n" +
"float du= sqrt(dx.x * dx.x + dy.x * dy.x);\n" +
"float dv= sqrt(dx.y * dx.y + dy.y * dy.y);\n" +
"float dw= sqrt(dx.z * dx.z + dy.z * dy.z);\n" +
"float3 distance3 = 2.0f * abs(frac((inUVs.xyz + 0.5f) * frequency.xyz) - 0.5f) - 0.5f;\n" +
"float3 scale = aaTweak.xxx / float3(du, dv, dw);\n" +
"float3 blend_out = saturate((scale - aaTweak.zzz) / (aaTweak.yyy - aaTweak.zzz));\n" +
"float3 vectorAlpha = clamp(distance3 * scale.xyz * blend_out.xyz, -1.0f, 1.0f);\n" +
"float alpha = saturate(0.5f + 0.5f * vectorAlpha.x * vectorAlpha.y * vectorAlpha.z);\n" +
"outColor= lerp(A, B, alpha.xxxx);";
}
}
}
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs.meta


fileFormatVersion: 2
guid: 7ed58c9badcb30d4e8c5ad54d3f33134
timeCreated: 1495756788
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存