Format code for shader generators
This commit is contained in:
@@ -9,24 +9,24 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
{
|
||||
switch (node->TypeID)
|
||||
{
|
||||
// World Position
|
||||
// World Position
|
||||
case 2:
|
||||
value = Value(VariantType::Vector3, TEXT("input.WorldPosition.xyz"));
|
||||
break;
|
||||
// View
|
||||
// View
|
||||
case 3:
|
||||
{
|
||||
switch (box->ID)
|
||||
{
|
||||
// Position
|
||||
// Position
|
||||
case 0:
|
||||
value = Value(VariantType::Vector3, TEXT("ViewPos"));
|
||||
break;
|
||||
// Direction
|
||||
// Direction
|
||||
case 1:
|
||||
value = Value(VariantType::Vector3, TEXT("ViewDir"));
|
||||
break;
|
||||
// Far Plane
|
||||
// Far Plane
|
||||
case 2:
|
||||
value = Value(VariantType::Float, TEXT("ViewFar"));
|
||||
break;
|
||||
@@ -34,15 +34,15 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Normal
|
||||
// Normal
|
||||
case 4:
|
||||
value = getNormal;
|
||||
break;
|
||||
// Camera Vector
|
||||
// Camera Vector
|
||||
case 5:
|
||||
value = getCameraVector(node);
|
||||
break;
|
||||
// Screen Position
|
||||
// Screen Position
|
||||
case 6:
|
||||
{
|
||||
// Position
|
||||
@@ -54,11 +54,11 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
|
||||
break;
|
||||
}
|
||||
// Screen Size
|
||||
// Screen Size
|
||||
case 7:
|
||||
value = Value(VariantType::Vector2, box->ID == 0 ? TEXT("ScreenSize.xy") : TEXT("ScreenSize.zw"));
|
||||
break;
|
||||
// Custom code
|
||||
// Custom code
|
||||
case 8:
|
||||
{
|
||||
// Skip if has no code
|
||||
@@ -127,15 +127,15 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = box->Cache;
|
||||
break;
|
||||
}
|
||||
// Object Position
|
||||
// Object Position
|
||||
case 9:
|
||||
value = Value(VariantType::Vector3, TEXT("GetObjectPosition(input)"));
|
||||
break;
|
||||
// Two Sided Sign
|
||||
// Two Sided Sign
|
||||
case 10:
|
||||
value = Value(VariantType::Float, TEXT("input.TwoSidedSign"));
|
||||
break;
|
||||
// Camera Depth Fade
|
||||
// Camera Depth Fade
|
||||
case 11:
|
||||
{
|
||||
auto faeLength = tryGetValue(node->GetBox(0), node->Values[0]).AsFloat();
|
||||
@@ -152,40 +152,40 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = x5;
|
||||
break;
|
||||
}
|
||||
// Vertex Color
|
||||
// Vertex Color
|
||||
case 12:
|
||||
value = getVertexColor;
|
||||
_treeLayer->UsageFlags |= MaterialUsageFlags::UseVertexColor;
|
||||
break;
|
||||
// Pre-skinned Local Position
|
||||
// Pre-skinned Local Position
|
||||
case 13:
|
||||
value = _treeType == MaterialTreeType::VertexShader ? Value(VariantType::Vector3, TEXT("input.PreSkinnedPosition")) : Value::Zero;
|
||||
break;
|
||||
// Pre-skinned Local Normal
|
||||
// Pre-skinned Local Normal
|
||||
case 14:
|
||||
value = _treeType == MaterialTreeType::VertexShader ? Value(VariantType::Vector3, TEXT("input.PreSkinnedNormal")) : Value::Zero;
|
||||
break;
|
||||
// Depth
|
||||
// Depth
|
||||
case 15:
|
||||
value = writeLocal(VariantType::Float, TEXT("distance(ViewPos, input.WorldPosition)"), node);
|
||||
break;
|
||||
// Tangent
|
||||
// Tangent
|
||||
case 16:
|
||||
value = Value(VariantType::Vector3, TEXT("input.TBN[0]"));
|
||||
break;
|
||||
// Bitangent
|
||||
// Bitangent
|
||||
case 17:
|
||||
value = Value(VariantType::Vector3, TEXT("input.TBN[1]"));
|
||||
break;
|
||||
// Camera Position
|
||||
// Camera Position
|
||||
case 18:
|
||||
value = Value(VariantType::Vector3, TEXT("ViewPos"));
|
||||
break;
|
||||
// Per Instance Random
|
||||
// Per Instance Random
|
||||
case 19:
|
||||
value = Value(VariantType::Float, TEXT("GetPerInstanceRandom(input)"));
|
||||
break;
|
||||
// Interpolate VS To PS
|
||||
// Interpolate VS To PS
|
||||
case 20:
|
||||
{
|
||||
const auto input = node->GetBox(0);
|
||||
@@ -219,7 +219,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
_vsToPsInterpolants.Add(input);
|
||||
break;
|
||||
}
|
||||
// Terrain Holes Mask
|
||||
// Terrain Holes Mask
|
||||
case 21:
|
||||
{
|
||||
MaterialLayer* baseLayer = GetRootLayer();
|
||||
@@ -229,7 +229,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = Value::One;
|
||||
break;
|
||||
}
|
||||
// Terrain Layer Weight
|
||||
// Terrain Layer Weight
|
||||
case 22:
|
||||
{
|
||||
MaterialLayer* baseLayer = GetRootLayer();
|
||||
@@ -252,7 +252,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = Value(VariantType::Float, String::Format(TEXT("input.Layers[{0}][{1}]"), slotIndex, componentIndex));
|
||||
break;
|
||||
}
|
||||
// Depth Fade
|
||||
// Depth Fade
|
||||
case 23:
|
||||
{
|
||||
// Calculate screen-space UVs
|
||||
@@ -278,7 +278,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(VariantType::Float, String::Format(TEXT("saturate({0} / {1})"), depthDiff.Value, fadeDistance.Value), node);
|
||||
break;
|
||||
}
|
||||
// Material Function
|
||||
// Material Function
|
||||
case 24:
|
||||
{
|
||||
// Load function asset
|
||||
@@ -333,11 +333,11 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
_graphStack.Pop();
|
||||
break;
|
||||
}
|
||||
// Object Size
|
||||
// Object Size
|
||||
case 25:
|
||||
value = Value(VariantType::Vector3, TEXT("GetObjectSize(input)"));
|
||||
break;
|
||||
// Blend Normals
|
||||
// Blend Normals
|
||||
case 26:
|
||||
{
|
||||
const auto baseNormal = tryGetValue(node->GetBox(0), getNormalZero).AsVector3();
|
||||
@@ -350,7 +350,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Vector3, text2, node);
|
||||
break;
|
||||
}
|
||||
// Rotator
|
||||
// Rotator
|
||||
case 27:
|
||||
{
|
||||
const auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
|
||||
@@ -366,7 +366,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Vector2, String::Format(TEXT("{3} + float2(dot({0},{1}), dot({0},{2}))"), x1.Value, dotB1.Value, dotB2.Value, center.Value), node);
|
||||
break;
|
||||
}
|
||||
// Sphere Mask
|
||||
// Sphere Mask
|
||||
case 28:
|
||||
{
|
||||
const auto a = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
@@ -384,7 +384,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Float, String::Format(TEXT("{0} ? (1 - {1}) : {1}"), invert.Value, x2.Value), node);
|
||||
break;
|
||||
}
|
||||
// Tiling & Offset
|
||||
// Tiling & Offset
|
||||
case 29:
|
||||
{
|
||||
const auto uv = tryGetValue(node->GetBox(0), getUVs).AsVector2();
|
||||
@@ -394,42 +394,42 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Vector2, String::Format(TEXT("{0} * {1} + {2}"), uv.Value, tiling.Value, offset.Value), node);
|
||||
break;
|
||||
}
|
||||
// DDX
|
||||
// DDX
|
||||
case 30:
|
||||
{
|
||||
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
|
||||
break;
|
||||
}
|
||||
// DDY
|
||||
// DDY
|
||||
case 31:
|
||||
{
|
||||
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
|
||||
break;
|
||||
}
|
||||
// Sign
|
||||
// Sign
|
||||
case 32:
|
||||
{
|
||||
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
value = writeLocal(ValueType::Float, String::Format(TEXT("sign({0})"), inValue.Value), node);
|
||||
break;
|
||||
}
|
||||
// Any
|
||||
// Any
|
||||
case 33:
|
||||
{
|
||||
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
value = writeLocal(ValueType::Bool, String::Format(TEXT("any({0})"), inValue.Value), node);
|
||||
break;
|
||||
}
|
||||
// All
|
||||
// All
|
||||
case 34:
|
||||
{
|
||||
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
|
||||
value = writeLocal(ValueType::Bool, String::Format(TEXT("all({0})"), inValue.Value), node);
|
||||
break;
|
||||
}
|
||||
// Blackbody
|
||||
// Blackbody
|
||||
case 35:
|
||||
{
|
||||
// Reference: Mitchell Charity, http://www.vendian.org/mncharity/dir3/blackbody/
|
||||
@@ -451,7 +451,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1} < 1000.0f ? {0} * {1}/1000.0f : {0}"), color.Value, temperature.Value), node);
|
||||
break;
|
||||
}
|
||||
// HSVToRGB
|
||||
// HSVToRGB
|
||||
case 36:
|
||||
{
|
||||
const auto hsv = tryGetValue(node->GetBox(0), node->Values[0]).AsVector3();
|
||||
@@ -463,7 +463,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
value = writeLocal(ValueType::Vector3, String::Format(TEXT("{1}.z * lerp(float3(1.0, 1.0, 1.0), {0}, {1}.y)"), x1.Value, color.Value), node);
|
||||
break;
|
||||
}
|
||||
// RGBToHSV
|
||||
// RGBToHSV
|
||||
case 37:
|
||||
{
|
||||
// Reference: Ian Taylor, https://www.chilliant.com/rgb2hsv.html
|
||||
@@ -474,8 +474,8 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
auto p = writeLocal(ValueType::Vector4, String::Format(TEXT("({0}.g < {0}.b) ? float4({0}.bg, -1.0f, 2.0f/3.0f) : float4({0}.gb, 0.0f, -1.0f/3.0f)"), rgb.Value), node);
|
||||
auto q = writeLocal(ValueType::Vector4, String::Format(TEXT("({0}.r < {1}.x) ? float4({1}.xyw, {0}.r) : float4({0}.r, {1}.yzx)"), rgb.Value, p.Value), node);
|
||||
auto c = writeLocal(ValueType::Float, String::Format(TEXT("{0}.x - min({0}.w, {0}.y)"), q.Value), node);
|
||||
auto h = writeLocal(ValueType::Float , String::Format(TEXT("abs(({0}.w - {0}.y) / (6 * {1} + {2}) + {0}.z)"), q.Value, c.Value, epsilon.Value), node);
|
||||
|
||||
auto h = writeLocal(ValueType::Float, String::Format(TEXT("abs(({0}.w - {0}.y) / (6 * {1} + {2}) + {0}.z)"), q.Value, c.Value, epsilon.Value), node);
|
||||
|
||||
auto hcv = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}, {1}, {2}.x)"), h.Value, c.Value, q.Value), node);
|
||||
value = writeLocal(ValueType::Vector3, String::Format(TEXT("float3({0}.x * 360.0f, {0}.y / ({0}.z + {1}), {0}.z)"), hcv.Value, epsilon.Value), node);
|
||||
break;
|
||||
@@ -489,7 +489,7 @@ void MaterialGenerator::ProcessGroupFunction(Box* box, Node* node, Value& value)
|
||||
{
|
||||
switch (node->TypeID)
|
||||
{
|
||||
// Function Input
|
||||
// Function Input
|
||||
case 1:
|
||||
{
|
||||
// Find the function call
|
||||
|
||||
Reference in New Issue
Block a user