Ejemplo n.º 1
0
 /// <summary>
 /// Creates a description of a parameter used in a shader.
 /// </summary>
 /// <param name="name">The variable name used in the shader.</param>
 /// <param name="type">An identifier of the variable used in the shader.</param>
 /// <param name="effect">A reference to the effect instance.</param>
 /// <param name="updateMethod">A delegate method that "polls" the updated value.</param>
 public SharedParameter(string name, SceneVariable type, Effect effect, dynamic variableRef, UpdateSharedParameter updateMethod)
     : base(name, effect)
 {
     Contract.Requires(updateMethod != null);
     Type = type;
     effectVariable = variableRef;
     update = updateMethod;
 }
Ejemplo n.º 2
0
        public void LoadLevel(SceneVariable sceneVariable)
        {
            //validate
            if (sceneVariable == null)
            {
                throw new ArgumentNullException(nameof(sceneVariable));
            }

            //work
            levelHistory.Push(CurrentScene);
            CurrentScene = sceneVariable;             //track
            LoadLevel(CurrentScene.Value.SceneIndex); //load
        }
 public void LoadLevel(SceneVariable sceneVariable)
 => SceneManager.LoadScene(sceneVariable.Value.SceneIndex);
Ejemplo n.º 4
0
 /// <summary>
 /// Load a scene and prompt User to save the scene.
 /// </summary>
 public static void LoadScene(SceneVariable sceneVar)
 => LoadScene(sceneVar.Value.SceneName);
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a "default parameter", such as World, View, Projection Matrices, 
        /// light direction, positionV3, ambient Color and so on.
        /// </summary>
        /// <param name="type">The type of the parameter to create.</param>
        /// <param name="effect">A reference of the effect instance.</param>
        /// <returns>An istance of EffectParameter containg all the needed information
        /// to correctly set and update this value into the shader.</returns>
        public static SharedParameter Create(SceneVariable type, Effect effect)
        {
            Contract.Requires(effect != null);
            string varName = string.Empty;
            dynamic eV = null;
            UpdateSharedParameter update = null;

            switch (type)
            {

                //case SceneVariable.LightWorldViewProjection:
                //    varName = ParamHandles.Matrices.LightWorldViewProjection;
                //    eV = effect.GetVariableByName(varName);

                //    update = delegate(EffectParameter fxParam)
                //    {
                //        Matrix mLightVP =
                //            BaseLight.CreateLightViewProjectionMatrix(
                //                (Spotlight) Game.CurrentRenderer.LightManager.GetLight(0));

                //        Matrix mWorld = renderer.Camera.World;

                //        fxParam.ownerEffect.SetValue(eH,mWorld * mLightVP);
                //    };
                //    break;

                //case SceneVariable.LightPosition:
                //    varName = ParamHandles.Vectors.LightPosition;
                //    eV = effect.GetVariableByName(varName).AsVector();
                //    update = ((fxParam,renderer) => Vector3Update(fxParam.EffectVariable, renderer.l)

                case SceneVariable.EyePosition:
                    varName = ParamHandles.Vectors.EyePosition;
                    eV = effect.GetVariableByName(varName).AsVector();

                    update = ((fxParam, renderer) => Vector3Update(fxParam.EffectVariable, renderer.Camera.PositionV3));
                    break;

                case SceneVariable.FarClip:
                    varName = ParamHandles.Floats.FarClip;
                    eV = effect.GetVariableByName(varName).AsScalar();
                    update = ((fxParam, renderer) => FloatUpdate(fxParam.EffectVariable, renderer.Camera.FarClip));
                    break;

                case SceneVariable.CameraProjection:
                    varName = ParamHandles.Matrices.Projection;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, renderer.Camera.Projection));
                    break;

                case SceneVariable.CameraProjectionTranspose:
                    varName = ParamHandles.Matrices.Projection;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, Matrix.Transpose(renderer.Camera.Projection)));
                    break;

                //case SceneVariable.TextureBias:
                //    varName = ParamHandles.Matrices.TextureBias;
                //    eV = effect.GetVariableByName(varName);
                //    update =
                //        (fxParam => fxParam.ownerEffect.SetValue(
                //                        eH,
                //                        BaseLight.CreateTextureBiasMatrix(256, 0.001f))
                //                        );
                //    break;

                case SceneVariable.CameraView:
                    varName = ParamHandles.Matrices.View;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, renderer.Camera.View));
                    break;

                case SceneVariable.CameraRotation:
                    varName = ParamHandles.Matrices.View;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, renderer.Camera.Rotation));
                    break;

                case SceneVariable.CameraViewTranspose:
                    varName = ParamHandles.Matrices.View;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, Matrix.Transpose(renderer.Camera.View)));
                    break;

                case SceneVariable.CameraViewInverse:
                    varName = ParamHandles.Matrices.ViewInverse;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, Matrix.Invert(renderer.Camera.View)));
                    break;

                case SceneVariable.CameraWorld:
                    varName = ParamHandles.Matrices.World;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, renderer.Camera.World));
                    break;

                case SceneVariable.CameraWorldInverse:
                    varName = ParamHandles.Matrices.WorldInverse;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, Matrix.Invert(renderer.Camera.World)));
                    break;

                    case SceneVariable.CameraWorldView:
                    varName = ParamHandles.Matrices.WorldView;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = (fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable,
                        Matrix.Multiply(renderer.Camera.World,renderer.Camera.View));
                    break;

                case SceneVariable.CameraWorldViewInverse:
                    varName = ParamHandles.Matrices.WorldViewInverse;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, Matrix.Invert(renderer.Camera.World * renderer.Camera.View)));
                    break;

                case SceneVariable.CameraWorldViewProjection:
                    varName = ParamHandles.Matrices.WorldViewProjection;
                    eV = effect.GetVariableByName(varName).AsMatrix();

                    update =
                        (fxParam, renderer) =>
                         MatrixUpdate(fxParam.EffectVariable,
                                      renderer.Camera.World * renderer.Camera.View * renderer.Camera.Projection);
                    break;

                case SceneVariable.CameraOrthographicProjection:
                    varName = ParamHandles.Matrices.Projection;
                    eV = effect.GetVariableByName(varName).AsMatrix();
                    update = ((fxParam, renderer) => MatrixUpdate(fxParam.EffectVariable, renderer.Camera.OrthoProjection));
                    break;

            }

            return new SharedParameter(varName, type, effect, eV, update);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets a static default parameter (eg: the World/View/Projection matrix, 
 /// the view vector, etc. A static parameter is updated only once.
 /// </summary>
 /// <param name="fxParam">The parameter type</param>
 public void SetStaticParameter(SceneVariable fxParam)
 {
     SharedParameter ep = SharedParameter.Create(fxParam, effect);
     SetStaticParameter(ep);
 }