Exemplo n.º 1
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);

            Light light = LightSystem.GetSingleton().GetLight(0);

            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["Texture"].SetValue(this.Tex1);
            this.Shader.Parameters["Tiling"].SetValue(new Vector2(10, 10));
            this.Shader.Parameters["LightDir"].SetValue(light.GetLightDirection());
            this.Shader.Parameters["LightColor"].SetValue(light.LightColor);
            this.Shader.Parameters["LightPosition"].SetValue(light.gameObject.Position);
            if (light.Type == LightType.POINT)
            {
                this.Shader.Parameters["LightAttenuation"].SetValue(light.Attenuation);
                this.Shader.Parameters["LightCutOffDistance"].SetValue(light.CutOffDistance);
            }
            else if (light.Type == LightType.SPOT)
            {
                this.Shader.Parameters["LightAttenuation"].SetValue(light.Attenuation);
                this.Shader.Parameters["LightCutOffDistance"].SetValue(light.CutOffDistance);
                this.Shader.Parameters["ConeAngle"].SetValue(light.ConeAngle);
            }
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["SpecularPower"].SetValue(4.0f);
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            RenderSystem.GetSingleton().Initialize();
            GameObjectManager.GetSingleton().Initialize();
            LightSystem.GetSingleton().Initialize();
            //LightSystem.GetSingleton().AmbientColor = Vector3.Zero;

            this.MainCamera          = new Camera();
            this.MainCamera.Position = new Vector3(0, 50, 80);
            this.MainCamera.Ratio    = this.mGraphics.GraphicsDevice.Viewport.AspectRatio;
            this.MainCamera.Far      = 1000.0f;

            //this.SkyBox = new Skybox();
            //this.SkyBox.Init(
            //    this.Content.Load<Model>("Skybox/Cube"),
            //    this.Content.Load<TextureCube>("Skybox/Skybox"),
            //    this.Content.Load<Effect>("Skybox/SkyboxShader")
            //    );

            //GameObject go1 = new GameObject();
            //go1.AddComponent<Light>().Type = LightType.DIRECTION;
            //go1.AddComponent<Light>().LightColor = new Vector3(0.1f, 0.1f, 0.1f);
            //go1.LocalRotation = new Vector3(-45, -45, 0);

            GameObject go2 = new GameObject();

            go2.Position = new Vector3(0, 20, 30);
            Light PointLight1 = go2.AddComponent <Light>();

            PointLight1.Type           = LightType.POINT;
            PointLight1.Attenuation    = 5000;
            PointLight1.CutOffDistance = 50;
            PointLight1.LightColor     = new Vector3(0, 0.5f, 0);
            go2.AddComponent <TestLogic>();

            GameObject go3 = new GameObject();

            go3.Position      = new Vector3(0, 50, 0);
            go3.LocalRotation = new Vector3(-90, 0, 0);
            Light SpotLight1 = go3.AddComponent <Light>();

            SpotLight1.Type           = LightType.SPOT;
            SpotLight1.Attenuation    = 5000;
            SpotLight1.CutOffDistance = 100;
            SpotLight1.ConeAngle      = 15;
            SpotLight1.LightColor     = new Vector3(1, 0, 0);
            go3.AddComponent <TestLogic>();


            base.Initialize();
        }
Exemplo n.º 3
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);
            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["Texture"].SetValue(this.Tex1);
            this.Shader.Parameters["Tiling"].SetValue(this.Tiling);
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["SpecularPower"].SetValue(4.0f);

            int lightNum = LightSystem.GetSingleton().GetLightNum();

            this.Shader.Parameters["LightNum"].SetValue(lightNum);
            for (int i = 0; i < lightNum; i++)
            {
                Light light = LightSystem.GetSingleton().GetLight(i);
                this.mLightType[i]           = (int)light.Type;
                this.mLightPosition[i]       = light.gameObject.Position;
                this.mLightDir[i]            = light.GetLightDirection();
                this.mLightColor[i]          = light.LightColor;
                this.mLightAttenuation[i]    = light.Attenuation;
                this.mLightCutOffDistance[i] = light.CutOffDistance;
                this.mConeAngle[i]           = light.ConeAngle;
            }


            this.Shader.Parameters["LightType"].SetValue(this.mLightType);
            this.Shader.Parameters["LightPosition"].SetValue(this.mLightPosition);
            this.Shader.Parameters["LightDir"].SetValue(this.mLightDir);
            this.Shader.Parameters["LightColor"].SetValue(this.mLightColor);
            this.Shader.Parameters["LightAttenuation"].SetValue(this.mLightAttenuation);
            this.Shader.Parameters["LightCutOffDistance"].SetValue(this.mLightCutOffDistance);
            this.Shader.Parameters["ConeAngle"].SetValue(this.mConeAngle);
        }
Exemplo n.º 4
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);

            Light light = LightSystem.GetSingleton().GetLight(0);

            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["TexDiffuse"].SetValue(this.TexDiffuse);
            this.Shader.Parameters["TexNormal"].SetValue(this.TexNormal);
            this.Shader.Parameters["UseNormalTexture"].SetValue(false);
            this.Shader.Parameters["Tiling"].SetValue(new Vector2(1, 1));
            this.Shader.Parameters["LightDir"].SetValue(light.GetLightDirection());
            this.Shader.Parameters["LightColor"].SetValue(light.LightColor);
            this.Shader.Parameters["LightPosition"].SetValue(light.gameObject.Position);
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(2, 2, 2));
            this.Shader.Parameters["SpecularPower"].SetValue(1.0f);
        }
Exemplo n.º 5
0
 public Light()
 {
     LightSystem.GetSingleton().AddLight(this);
 }