protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var expressions = Block.CameraHelper.AddCameraExpressions(GetExpressionsFromSlots(this), camera);

            // camera matrix is already in world even in custom mode due to GetOutputSpaceFromSlot returning world space
            Block.CameraMatricesExpressions matricesExpressions = Block.CameraHelper.GetMatricesExpressions(expressions, VFXCoordinateSpace.World, VFXCoordinateSpace.World);

            // result = position * VFXToView * ViewToClip
            VFXExpression positionExpression = inputExpression[0];
            VFXExpression viewPosExpression  = new VFXExpressionTransformPosition(matricesExpressions.VFXToView.exp, positionExpression);
            VFXExpression clipPosExpression  = new VFXExpressionTransformVector4(matricesExpressions.ViewToClip.exp, VFXOperatorUtility.CastFloat(viewPosExpression, VFXValueType.Float4, 1.0f));

            // normalize using w component and renormalize to range [0, 1]
            VFXExpression halfExpression       = VFXValue.Constant(0.5f);
            VFXExpression normalizedExpression = new VFXExpressionCombine(new VFXExpression[]
            {
                (clipPosExpression.x / clipPosExpression.w) * halfExpression + halfExpression,
                (clipPosExpression.y / clipPosExpression.w) * halfExpression + halfExpression,
                viewPosExpression.z     // The z position is in world units from the camera
            });

            return(new VFXExpression[]
            {
                normalizedExpression
            });
        }
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            VFXExpression inverseTRS    = new VFXExpressionInverseTRSMatrix(inputExpression[1]);
            VFXExpression scale         = new VFXExpressionExtractScaleFromMatrix(inputExpression[1]);
            VFXExpression uvw           = new VFXExpressionTransformPosition(inverseTRS, inputExpression[2]) + VFXValue.Constant(new Vector3(0.5f, 0.5f, 0.5f));
            VFXExpression distanceExpr  = new VFXExpressionSampleSDF(inputExpression[0], uvw, scale, inputExpression[3]);
            VFXExpression directionExpr = new VFXExpressionSampleSDFNormal(inputExpression[0], inverseTRS, uvw, inputExpression[3]) * VFXValue.Constant(new Vector3(-1.0f, -1.0f, -1.0f));

            return(new[] { distanceExpr, directionExpr });
        }
Esempio n. 3
0
        public void ProcessExpressionTransformPosition()
        {
            var t = new Vector3(0.2f, 0.3f, 0.4f);
            var m = new Matrix4x4();

            m.SetTRS(new Vector3(1.0f, 2.0f, 3.0f), Quaternion.Euler(0.2f, 0.3f, 0.4f), new Vector3(2.0f, 3.0f, 4.0f));

            var result = m.MultiplyPoint(t);

            var value_t = new VFXValue <Vector3>(t);
            var value_m = new VFXValue <Matrix4x4>(m);

            var expression = new VFXExpressionTransformPosition(value_m, value_t);

            var context          = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
            var resultExpression = context.Compile(expression);

            Assert.AreEqual(result, resultExpression.Get <Vector3>());
        }
Esempio n. 4
0
        protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var expressions = Block.CameraHelper.AddCameraExpressions(GetExpressionsFromSlots(this), camera);

            // camera matrix is already in world even in custom mode due to GetOutputSpaceFromSlot returning world space
            Block.CameraMatricesExpressions matricesExpressions = Block.CameraHelper.GetMatricesExpressions(expressions, VFXCoordinateSpace.World, VFXCoordinateSpace.World);

            // renormalize XY from viewport position [0, 1] to clip position [-1, 1]
            VFXExpression viewportPosExpression = inputExpression[0];
            VFXExpression oneExpression         = VFXValue.Constant(1.0f);
            VFXExpression twoExpression         = VFXValue.Constant(2.0f);
            VFXExpression clipPosExpression     = new VFXExpressionCombine(viewportPosExpression.x * twoExpression - oneExpression, viewportPosExpression.y * twoExpression - oneExpression, oneExpression, oneExpression);

            // result = clipPos * ClipToView * ViewToVFX
            VFXExpression viewPosExpression = new VFXExpressionTransformVector4(matricesExpressions.ClipToView.exp, clipPosExpression);

            viewPosExpression = new VFXExpressionCombine(viewPosExpression.x, viewPosExpression.y, viewPosExpression.z) * viewportPosExpression.zzz;
            VFXExpression positionExpression = new VFXExpressionTransformPosition(matricesExpressions.ViewToVFX.exp, viewPosExpression);

            return(new VFXExpression[]
            {
                positionExpression
            });
        }