Ejemplo n.º 1
0
        private void InitializeConvertersFloatToVector()
        {
            HLSLValuePair pair;

            // float -> float2
            pair = new HLSLValuePair
            {
                From = HLSLValueBaseType.FLOAT,
                To   = HLSLValueBaseType.FLOAT2
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                switch (from)
                {
                case HLSLValueSubType.X_R: return(string.Format("float2({0}, 0.0f)", value));

                case HLSLValueSubType.Y_G: return(string.Format("float2(0.0f, {0})", value));
                }
                return(string.Format("float2({0}, {0})", value));
            });
            // float -> float3
            pair = new HLSLValuePair
            {
                From = HLSLValueBaseType.FLOAT,
                To   = HLSLValueBaseType.FLOAT3
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                switch (from)
                {
                case HLSLValueSubType.X_R: return(string.Format("float3({0}, 0.0f, 0.0f)", value));

                case HLSLValueSubType.Y_G: return(string.Format("float3(0.0f, {0}, 0.0f)", value));

                case HLSLValueSubType.Z_B: return(string.Format("float3(0.0f, 0.0f, {0})", value));
                }
                return(string.Format("float3({0}, {0}, {0})", value));
            });
            // float -> float4
            pair = new HLSLValuePair
            {
                From = HLSLValueBaseType.FLOAT,
                To   = HLSLValueBaseType.FLOAT4
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                switch (from)
                {
                case HLSLValueSubType.X_R: return(string.Format("float4({0}, 0.0f, 0.0f, 0.0f)", value));

                case HLSLValueSubType.Y_G: return(string.Format("float4(0.0f, {0}, 0.0f, 0.0f)", value));

                case HLSLValueSubType.Z_B: return(string.Format("float4(0.0f, 0.0f, {0}, 0.0f)", value));

                case HLSLValueSubType.W_A: return(string.Format("float4(0.0f, 0.0f, 0.0f, {0})", value));
                }
                return(string.Format("float4({0}, {0}, {0}, 1.0f)", value));
            });
        }
Ejemplo n.º 2
0
        private void InitializeConvertersVectorToVector()
        {
            HLSLValuePair pair;

            // float2 -> float4
            pair = new HLSLValuePair
            {
                From = HLSLValueBaseType.FLOAT2,
                To   = HLSLValueBaseType.FLOAT4
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                return(string.Format("float4({0}, 0.0f, 1.0f)", value));
            });
            // float3 -> float4
            pair = new HLSLValuePair
            {
                From = HLSLValueBaseType.FLOAT3,
                To   = HLSLValueBaseType.FLOAT4
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                return(string.Format("float4({0}, 1.0f)", value));
            });
            // float4 -> float2, float3 -> float2
            Func <HLSLValueSubType, HLSLValueSubType, object, string> func = (from, to, value) => {
                return(string.Format("float2({0}.xy)", value));
            };

            converters[new HLSLValuePair {
                           From = HLSLValueBaseType.FLOAT3, To = HLSLValueBaseType.FLOAT2
                       }] = new HLSLValueConverter(func);
            converters[new HLSLValuePair {
                           From = HLSLValueBaseType.FLOAT4, To = HLSLValueBaseType.FLOAT2
                       }] = new HLSLValueConverter(func);

            // float4 -> float3
            pair = new HLSLValuePair {
                From = HLSLValueBaseType.FLOAT4, To = HLSLValueBaseType.FLOAT3
            };
            converters[pair] = new HLSLValueConverter((from, to, value) => {
                return(string.Format("float3({0}.xyz)", value));
            });
        }