Beispiel #1
0
        private void LoadDefaultParameters()
        {
            var shaderParameters   = defaultParameters; // Default Parameters contains all registered Parameters used effectively by the effect
            var constantBufferKeys = new Dictionary <string, ParameterKey <ParameterConstantBuffer> >();

            // Create parameter bindings
            for (int i = 0; i < resourceBindings.Length; i++)
            {
                // Update binding key
                var key = UpdateResourceBindingKey(ref resourceBindings[i].Description);

                // ConstantBuffers are handled by next loop
                if (resourceBindings[i].Description.Param.Class != EffectParameterClass.ConstantBuffer)
                {
                    shaderParameters.RegisterParameter(key, false);
                }
            }

            // Create constant buffers from descriptions (previously generated from shader reflection)
            foreach (var constantBuffer in reflection.ConstantBuffers)
            {
                var constantBufferMembers = constantBuffer.Members;

                for (int i = 0; i < constantBufferMembers.Length; ++i)
                {
                    // Update binding key
                    var key = UpdateValueBindingKey(ref constantBufferMembers[i]);

                    // Register ParameterKey with this effect and store its index for direct access during rendering
                    shaderParameters.RegisterParameter(key, false);
                }

                // Handle ConstantBuffer. Share the same key ParameterConstantBuffer with all the stages
                var parameterConstantBuffer = new ParameterConstantBuffer(graphicsDeviceDefault, constantBuffer.Name, constantBuffer);
                var constantBufferKey       = ParameterKeys.New(parameterConstantBuffer, constantBuffer.Name);
                shaderParameters.RegisterParameter(constantBufferKey, false);

                for (int i = 0; i < resourceBindings.Length; i++)
                {
                    if (resourceBindings[i].Description.Param.Class == EffectParameterClass.ConstantBuffer && resourceBindings[i].Description.Param.Key.Name == constantBuffer.Name)
                    {
                        resourceBindings[i].Description.Param.Key = constantBufferKey;
                    }
                }

                // Update constant buffer mapping (to avoid name clashes)
                constantBufferKeys[constantBuffer.Name] = constantBufferKey;
            }

            UpdateKeyIndices();

            // Once we have finished binding, we can fully prepare them
            graphicsDeviceDefault.StageStatus.PrepareBindings(resourceBindings);
        }
        public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
        {
            var parameterKey = ParameterKeys.FindByName(fromScalar.Value);

            if (parameterKey == null)
            {
                parameterKey = ParameterKeys.New <object>(null, fromScalar.Value);
                // Dont' throw an exception if keys was not found
                //throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to find registered ParameterKey [{0}]".ToFormat(fromScalar.Value));
            }
            return(parameterKey);
        }
 static TransformationKeys()
 {
     View                = ParameterKeys.New(Matrix.Identity);
     Projection          = ParameterKeys.New(Matrix.Identity);
     World               = ParameterKeys.New(Matrix.Identity);
     ViewProjection      = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix, Matrix>(View, Projection, Matrix.MultiplyRef));
     WorldView           = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix, Matrix>(World, View, Matrix.MultiplyRef));
     WorldViewProjection = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix, Matrix>(World, ViewProjection, Matrix.MultiplyRef));
     ProjScreenRay       = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Vector2, Matrix>(Projection, ExtractProjScreenRay));
     Eye              = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Vector4, Matrix>(View, ViewToEye));
     EyeMS            = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Vector4, Matrix>(WorldView, WorldViewToEyeMS));
     WorldInverse     = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix>(World, InvertMatrix));
     ViewInverse      = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix>(View, InvertMatrix));
     WorldViewInverse = ParameterKeys.NewDynamic(ParameterDynamicValue.New <Matrix, Matrix>(WorldView, InvertMatrix));
 }
 static ImageScalerShaderKeys()
 {
     // Default value of 1.0f
     Color = ParameterKeys.New(Color4.White);
 }
Beispiel #5
0
        private ParameterKey FindOrCreateValueKey <T>(EffectParameterValueData binding) where T : struct
        {
            var name = binding.Param.KeyName;

            return(ParameterKeys.FindByName(name) ?? (binding.Count > 1 ? (ParameterKey)ParameterKeys.New <T[]>(name) : ParameterKeys.New <T>(name)));
        }
Beispiel #6
0
 private ParameterKey FindOrCreateResourceKey <T>(string name)
 {
     return(ParameterKeys.FindByName(name) ?? ParameterKeys.New <T>(name));
 }
Beispiel #7
0
 static SpriteBaseKeys()
 {
     MatrixTransform = ParameterKeys.New(Matrix.Identity);
 }