An editor-only Shader Graph node that outputs the determinant of a matrix. It declares an input matrix and returns shader code calling HLSL/ShaderLab determinant(...) on the provided matrix, with validation and a default fallback.
using Editor;
namespace ShaderGraphPlus.Nodes;
[Title( "Matrix Determinant" ), Category( "Math/Matrix" )]
public sealed class MatrixDeterminantNode : ShaderNodePlus
{
[JsonIgnore, Hide, Browsable( false )]
public override Color NodeTitleColor => ShaderGraphPlusTheme.NodeHeaderColors.MatrixNode;
[Input, Title( "Matrix" )]
[Hide]
public NodeInput Input { get; set; }
[Hide, JsonIgnore]
public override bool CanPreview => false;
[Output, Title( "Matrix" )]
[Hide]
public NodeResult.Func Result => ( GraphCompiler compiler ) =>
{
var inputResult = compiler.Result( Input );
if ( !inputResult.IsValid )
{
return new NodeResult( ResultType.Float2x2, $"determinant( float4x4( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ) )" );
}
if ( !inputResult.IsMatrixResult() )
{
return NodeResult.Error( $"Input must be a matrix type!" );
}
return new NodeResult( inputResult.ResultType, $"determinant( {inputResult.Code} )" );
};
}