@@ -465,22 +465,22 @@ public override string GetCodeString(string[] parents)
465465 }
466466 }
467467
468- class VFXExpressionVector3sToMatrix : VFXExpression
468+ class VFXExpressionRowToMatrix : VFXExpression
469469 {
470- public VFXExpressionVector3sToMatrix ( ) : this ( new VFXExpression [ ] { new VFXValue < Vector3 > ( Vector3 . right ) , new VFXValue < Vector3 > ( Vector3 . up ) , new VFXValue < Vector3 > ( Vector3 . forward ) , VFXValue < Vector3 > . Default }
470+ public VFXExpressionRowToMatrix ( ) : this ( new VFXExpression [ ] { new VFXValue < Vector4 > ( new Vector4 ( 1 , 0 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 1 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 1 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 0 , 1 ) ) }
471471 )
472472 {
473473 }
474474
475- public VFXExpressionVector3sToMatrix ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
475+ public VFXExpressionRowToMatrix ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
476476 {
477477 }
478478
479479 public override VFXExpressionOperation operation
480480 {
481481 get
482482 {
483- return VFXExpressionOperation . Vector3sToMatrix ;
483+ return VFXExpressionOperation . RowToMatrix ;
484484 }
485485 }
486486
@@ -491,42 +491,42 @@ sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
491491 var zReduce = constParents [ 2 ] ;
492492 var wReduce = constParents [ 3 ] ;
493493
494- var x = xReduce . Get < Vector3 > ( ) ;
495- var y = yReduce . Get < Vector3 > ( ) ;
496- var z = zReduce . Get < Vector3 > ( ) ;
497- var w = wReduce . Get < Vector3 > ( ) ;
494+ var x = xReduce . Get < Vector4 > ( ) ;
495+ var y = yReduce . Get < Vector4 > ( ) ;
496+ var z = zReduce . Get < Vector4 > ( ) ;
497+ var w = wReduce . Get < Vector4 > ( ) ;
498498
499499 Matrix4x4 matrix = new Matrix4x4 ( ) ;
500- matrix . SetColumn ( 0 , new Vector4 ( x . x , x . y , x . z , 0.0f ) ) ;
501- matrix . SetColumn ( 1 , new Vector4 ( y . x , y . y , y . z , 0.0f ) ) ;
502- matrix . SetColumn ( 2 , new Vector4 ( z . x , z . y , z . z , 0.0f ) ) ;
503- matrix . SetColumn ( 3 , new Vector4 ( w . x , w . y , w . z , 1.0f ) ) ;
500+ matrix . SetRow ( 0 , x ) ;
501+ matrix . SetRow ( 1 , y ) ;
502+ matrix . SetRow ( 2 , z ) ;
503+ matrix . SetRow ( 3 , w ) ;
504504
505505 return VFXValue . Constant ( matrix ) ;
506506 }
507507
508508 public override string GetCodeString ( string [ ] parents )
509509 {
510- return string . Format ( "VFXCreateMatrixFromColumns(float4( {0}, 0.0), float4( {1}, 0.0), float4( {2}, 0.0), float4( {3}, 1.0) );" , parents [ 0 ] , parents [ 1 ] , parents [ 2 ] , parents [ 3 ] ) ;
510+ return string . Format ( "VFXCreateMatrixFromRows( {0}, {1}, {2}, {3});" , parents [ 0 ] , parents [ 1 ] , parents [ 2 ] , parents [ 3 ] ) ;
511511 }
512512 }
513513
514- class VFXExpressionVector4sToMatrix : VFXExpression
514+ class VFXExpressionColumnToMatrix : VFXExpression
515515 {
516- public VFXExpressionVector4sToMatrix ( ) : this ( new VFXExpression [ ] { new VFXValue < Vector4 > ( new Vector4 ( 1 , 0 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 1 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 1 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 0 , 1 ) ) }
516+ public VFXExpressionColumnToMatrix ( ) : this ( new VFXExpression [ ] { new VFXValue < Vector4 > ( new Vector4 ( 1 , 0 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 1 , 0 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 1 , 0 ) ) , new VFXValue < Vector4 > ( new Vector4 ( 0 , 0 , 0 , 1 ) ) }
517517 )
518518 {
519519 }
520520
521- public VFXExpressionVector4sToMatrix ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
521+ public VFXExpressionColumnToMatrix ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
522522 {
523523 }
524524
525525 public override VFXExpressionOperation operation
526526 {
527527 get
528528 {
529- return VFXExpressionOperation . Vector4sToMatrix ;
529+ return VFXExpressionOperation . ColumnToMatrix ;
530530 }
531531 }
532532
@@ -557,25 +557,80 @@ public override string GetCodeString(string[] parents)
557557 }
558558 }
559559
560- class VFXExpressionMatrixToVector3s : VFXExpression
560+ class VFXExpressionAxisToMatrix : VFXExpression
561+ {
562+ public VFXExpressionAxisToMatrix ( ) : this ( new VFXExpression [ ] { new VFXValue < Vector3 > ( Vector3 . right ) , new VFXValue < Vector3 > ( Vector3 . up ) , new VFXValue < Vector3 > ( Vector3 . forward ) , VFXValue < Vector3 > . Default }
563+ )
564+ {
565+ }
566+
567+ public VFXExpressionAxisToMatrix ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
568+ {
569+ }
570+
571+ public override VFXExpressionOperation operation
572+ {
573+ get
574+ {
575+ return VFXExpressionOperation . AxisToMatrix ;
576+ }
577+ }
578+
579+ sealed protected override VFXExpression Evaluate ( VFXExpression [ ] constParents )
580+ {
581+ var xReduce = constParents [ 0 ] ;
582+ var yReduce = constParents [ 1 ] ;
583+ var zReduce = constParents [ 2 ] ;
584+ var wReduce = constParents [ 3 ] ;
585+
586+ var x = xReduce . Get < Vector3 > ( ) ;
587+ var y = yReduce . Get < Vector3 > ( ) ;
588+ var z = zReduce . Get < Vector3 > ( ) ;
589+ var w = wReduce . Get < Vector3 > ( ) ;
590+
591+ Matrix4x4 matrix = new Matrix4x4 ( ) ;
592+ matrix . SetColumn ( 0 , new Vector4 ( x . x , x . y , x . z , 0.0f ) ) ;
593+ matrix . SetColumn ( 1 , new Vector4 ( y . x , y . y , y . z , 0.0f ) ) ;
594+ matrix . SetColumn ( 2 , new Vector4 ( z . x , z . y , z . z , 0.0f ) ) ;
595+ matrix . SetColumn ( 3 , new Vector4 ( w . x , w . y , w . z , 1.0f ) ) ;
596+
597+ return VFXValue . Constant ( matrix ) ;
598+ }
599+
600+ public override string GetCodeString ( string [ ] parents )
601+ {
602+ return string . Format ( "VFXCreateMatrixFromColumns(float4({0}, 0.0), float4({1}, 0.0), float4({2}, 0.0), float4({3}, 1.0));" , parents [ 0 ] , parents [ 1 ] , parents [ 2 ] , parents [ 3 ] ) ;
603+ }
604+ }
605+
606+ class VFXExpressionMatrixToRow : VFXExpression
561607 {
562- public VFXExpressionMatrixToVector3s ( ) : this ( new VFXExpression [ ] { VFXValue < Matrix4x4 > . Default , VFXValue . Constant < int > ( 0 ) } // TODO row index should not be an expression!
608+ public VFXExpressionMatrixToRow ( ) : this ( new VFXExpression [ ] { VFXValue < Matrix4x4 > . Default , VFXValue . Constant < int > ( 0 ) }
563609 )
564610 {
565611 }
566612
567- public VFXExpressionMatrixToVector3s ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
613+ public VFXExpressionMatrixToRow ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
568614 {
569615 }
570616
571617 public override VFXExpressionOperation operation
572618 {
573619 get
574620 {
575- return VFXExpressionOperation . MatrixToVector3s ;
621+ return VFXExpressionOperation . MatrixToRow ;
576622 }
577623 }
578624
625+ protected sealed override VFXExpression Reduce ( VFXExpression [ ] reducedParents )
626+ {
627+ var parent = reducedParents [ 0 ] ;
628+ if ( parent is VFXExpressionRowToMatrix && reducedParents [ 1 ] . Is ( Flags . Constant ) )
629+ return parent . parents [ reducedParents [ 1 ] . Get < int > ( ) ] ;
630+
631+ return base . Reduce ( reducedParents ) ;
632+ }
633+
579634 sealed protected override VFXExpression Evaluate ( VFXExpression [ ] constParents )
580635 {
581636 var matReduce = constParents [ 0 ] ;
@@ -584,34 +639,43 @@ sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
584639 var mat = matReduce . Get < Matrix4x4 > ( ) ;
585640 var axis = axisReduce . Get < int > ( ) ;
586641
587- return VFXValue . Constant < Vector3 > ( mat . GetColumn ( axis ) ) ;
642+ return VFXValue . Constant ( mat . GetRow ( axis ) ) ;
588643 }
589644
590645 public override string GetCodeString ( string [ ] parents )
591646 {
592- return string . Format ( "VFXGetColumnFromMatrix ({0}, {1}).xyz " , parents [ 0 ] , parents [ 1 ] ) ;
647+ return string . Format ( "VFXGetRowFromMatrix ({0}, {1})" , parents [ 0 ] , parents [ 1 ] ) ;
593648 }
594649 }
595650
596- class VFXExpressionMatrixToVector4s : VFXExpression
651+ class VFXExpressionMatrixToColumn : VFXExpression
597652 {
598- public VFXExpressionMatrixToVector4s ( ) : this ( new VFXExpression [ ] { VFXValue < Matrix4x4 > . Default , VFXValue . Constant < int > ( 0 ) } // TODO row index should not be an expression!
653+ public VFXExpressionMatrixToColumn ( ) : this ( new VFXExpression [ ] { VFXValue < Matrix4x4 > . Default , VFXValue . Constant < int > ( 0 ) }
599654 )
600655 {
601656 }
602657
603- public VFXExpressionMatrixToVector4s ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
658+ public VFXExpressionMatrixToColumn ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
604659 {
605660 }
606661
607662 public override VFXExpressionOperation operation
608663 {
609664 get
610665 {
611- return VFXExpressionOperation . MatrixToVector4s ;
666+ return VFXExpressionOperation . MatrixToColumn ;
612667 }
613668 }
614669
670+ protected sealed override VFXExpression Reduce ( VFXExpression [ ] reducedParents )
671+ {
672+ var parent = reducedParents [ 0 ] ;
673+ if ( parent is VFXExpressionColumnToMatrix && reducedParents [ 1 ] . Is ( Flags . Constant ) )
674+ return parent . parents [ reducedParents [ 1 ] . Get < int > ( ) ] ;
675+
676+ return base . Reduce ( reducedParents ) ;
677+ }
678+
615679 sealed protected override VFXExpression Evaluate ( VFXExpression [ ] constParents )
616680 {
617681 var matReduce = constParents [ 0 ] ;
@@ -628,4 +692,50 @@ public override string GetCodeString(string[] parents)
628692 return string . Format ( "VFXGetColumnFromMatrix({0}, {1})" , parents [ 0 ] , parents [ 1 ] ) ;
629693 }
630694 }
695+
696+ class VFXExpressionMatrixToAxis : VFXExpression
697+ {
698+ public VFXExpressionMatrixToAxis ( ) : this ( new VFXExpression [ ] { VFXValue < Matrix4x4 > . Default , VFXValue . Constant < int > ( 0 ) }
699+ )
700+ {
701+ }
702+
703+ public VFXExpressionMatrixToAxis ( params VFXExpression [ ] parents ) : base ( VFXExpression . Flags . None , parents )
704+ {
705+ }
706+
707+ public override VFXExpressionOperation operation
708+ {
709+ get
710+ {
711+ return VFXExpressionOperation . MatrixToAxis ;
712+ }
713+ }
714+
715+ protected sealed override VFXExpression Reduce ( VFXExpression [ ] reducedParents )
716+ {
717+ var parent = reducedParents [ 0 ] ;
718+ if ( parent is VFXExpressionAxisToMatrix && reducedParents [ 1 ] . Is ( Flags . Constant ) )
719+ return parent . parents [ reducedParents [ 1 ] . Get < int > ( ) ] ;
720+
721+ return base . Reduce ( reducedParents ) ;
722+ }
723+
724+ sealed protected override VFXExpression Evaluate ( VFXExpression [ ] constParents )
725+ {
726+ var matReduce = constParents [ 0 ] ;
727+ var axisReduce = constParents [ 1 ] ;
728+
729+ var mat = matReduce . Get < Matrix4x4 > ( ) ;
730+ var axis = axisReduce . Get < int > ( ) ;
731+
732+ Vector4 c = mat . GetColumn ( axis ) ;
733+ return VFXValue . Constant ( new Vector3 ( c . x , c . y , c . z ) ) ;
734+ }
735+
736+ public override string GetCodeString ( string [ ] parents )
737+ {
738+ return string . Format ( "VFXGetColumnFromMatrix({0}, {1}).xyz" , parents [ 0 ] , parents [ 1 ] ) ;
739+ }
740+ }
631741}
0 commit comments