Exemplo n.º 1
0
 public ProjectionShader(Effect effect, PhongMaterial material, Texture2D texture) : base(effect)
 {
     effect.Parameters["ProjectorPosition"].SetValue(ProjectorPosition);
     effect.Parameters["AmbientColor"].SetValue(material.AmbientColor.ToVector3());
     effect.Parameters["DiffuseColor"].SetValue(material.DiffuseColor.ToVector3());
     effect.Parameters["AmbientIntensity"].SetValue(material.AmbientIntensity);
     effect.Parameters["ProjectedTexture"].SetValue(texture);
 }
Exemplo n.º 2
0
 public SpotLightShader(Effect effect, PhongMaterial material) : base(effect)
 {
     effect.Parameters["LightPosition"].SetValue(new Vector3(5.0f, 5.0f, 5.0f));
     effect.Parameters["LightDirection"].SetValue(new Vector3(-1.0f, -1.0f, 0.0f));
     effect.Parameters["AmbientColor"].SetValue(material.AmbientColor.ToVector3());
     effect.Parameters["DiffuseColor"].SetValue(material.DiffuseColor.ToVector3());
     effect.Parameters["LightColor"].SetValue(material.SpecularColor.ToVector3());
     effect.Parameters["AmbientIntensity"].SetValue(material.AmbientIntensity);
     effect.Parameters["OuterAngle"].SetValue(20.0f);
     effect.Parameters["InnerAngle"].SetValue(5.0f);
 }
Exemplo n.º 3
0
 public PhongShader(Effect effect, PhongMaterial material, Camera camera) : base(effect)
 {
     effect.Parameters["LightPosition"].SetValue(new Vector3(100.0f, 100.0f, 100.0f));
     effect.Parameters["CameraPosition"].SetValue(camera.Position);
     effect.Parameters["AmbientColor"].SetValue(material.AmbientColor.ToVector3());
     effect.Parameters["DiffuseColor"].SetValue(material.DiffuseColor.ToVector3());
     effect.Parameters["AmbientIntensity"].SetValue(material.AmbientIntensity);
     effect.Parameters["SpecularColor"].SetValue(material.SpecularColor.ToVector3());
     effect.Parameters["SpecularIntensity"].SetValue(material.SpecularIntensity);
     effect.Parameters["SpecularPower"].SetValue(material.SpecularPower);
 }
Exemplo n.º 4
0
        protected override void LoadContent()
        {
            // Setup graphics device
            graphicsDevice = graphicsDeviceManager.GraphicsDevice;
            graphicsDevice.RasterizerState = new RasterizerState();

            // Initialize bitmap renderer and font texture
            SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice);
            SpriteFont  spriteFont  = Content.Load <SpriteFont>("fonts/arial12");

            // Initialize scenemanager
            sceneManager = new SceneManager(graphicsDevice, spriteBatch, spriteFont);

            // Load models
            Microsoft.Xna.Framework.Graphics.Model xhead = Content.Load <Microsoft.Xna.Framework.Graphics.Model>("models/head");

            Model head          = new Model(xhead);
            Model terrain       = new Model(graphicsDevice, Content.Load <Texture2D>("textures/heightmap"), Vector3.Zero, Vector3.Zero, 0.5f);
            Model teapotModel   = new Model(Content.Load <Microsoft.Xna.Framework.Graphics.Model>("models/teapot"), Vector3.Zero, Vector3.Zero, 10f);
            Model tabletopModel = new Model(Content.Load <Microsoft.Xna.Framework.Graphics.Model>("models/tabletop"), Vector3.Zero, Vector3.Zero, 20f);

            List <Model> headgerow = new List <Model>()
            {
                new Model(xhead, new Vector3(-80f + 0 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 1 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 2 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 3 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 4 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 5 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 6 * 40f, 0f, 0f)),
                new Model(xhead, new Vector3(-80f + 7 * 40f, 0f, 0f))
            };

            // Initialize materials
            LambertianMaterial lambertianMaterial = new LambertianMaterial()
            {
                AmbientColor     = Color.Red,
                AmbientIntensity = 0.2f,
                DiffuseColor     = Color.Orange
            };

            PhongMaterial phongMaterial = new PhongMaterial()
            {
                AmbientColor      = Color.Red,
                AmbientIntensity  = 0.2f,
                DiffuseColor      = Color.Orange,
                SpecularColor     = Color.White,
                SpecularIntensity = 1f,
                SpecularPower     = 32f
            };

            PhongMaterial woodMaterial = new PhongMaterial()
            {
                AmbientColor      = Color.Black,
                AmbientIntensity  = 0.2f,
                DiffuseColor      = Color.BurlyWood,
                SpecularColor     = Color.White,
                SpecularIntensity = 0.2f,
                SpecularPower     = 32f
            };

            CookTorranceMaterial cookTorranceMaterial = new CookTorranceMaterial()
            {
                AmbientColor           = Color.Gold,
                AmbientIntensity       = 0.2f,
                DiffuseColor           = Color.Goldenrod,
                SpecularColor          = Color.White,
                SpecularIntensity      = 2f,
                SpecularPower          = 25f,
                Roughness              = 0.5f,
                ReflectanceCoefficient = 1.42f
            };

            // Initialize shaders
            BasicEffect basicEffect = new BasicEffect(graphicsDevice);

            basicEffect.VertexColorEnabled             = true;
            basicEffect.LightingEnabled                = true;
            basicEffect.AmbientLightColor              = new Vector3(0.3f);
            basicEffect.DirectionalLight0.Enabled      = true;
            basicEffect.DirectionalLight0.DiffuseColor = Color.White.ToVector3();
            basicEffect.DirectionalLight0.Direction    = new Vector3(0, -1, 0);

            Shader basicShader        = new Shader(basicEffect);
            Shader woodShader         = new WoodShader(Content.Load <Effect>("shaders/wooden"), woodMaterial, sceneManager.Camera, Content.Load <Texture2D>("textures/wood"));
            Shader phongShader        = new PhongShader(Content.Load <Effect>("shaders/phong"), phongMaterial, sceneManager.Camera);
            Shader normalShader       = new Shader(Content.Load <Effect>("shaders/normals"));
            Shader checkersShader     = new Shader(Content.Load <Effect>("shaders/checkers"));
            Shader spotLightShader    = new SpotLightShader(Content.Load <Effect>("shaders/spotlight"), phongMaterial);
            Shader lambertianShader   = new LambertianShader(Content.Load <Effect>("shaders/lambertian"), lambertianMaterial);
            Shader multiLightShader   = new MultiLightShader(Content.Load <Effect>("shaders/multilight"), cookTorranceMaterial);
            Shader projectionShader   = new ProjectionShader(Content.Load <Effect>("shaders/projective-texture"), phongMaterial, Content.Load <Texture2D>("textures/smiley"));
            Shader cookTorranceShader = new CookTorranceShader(Content.Load <Effect>("shaders/cook-torrance"), cookTorranceMaterial);

            // Initialize post-processors
            Filter monochromeFilter = new Filter(graphicsDevice, spriteBatch, Content.Load <Effect>("shaders/monochrome"));
            Filter gaussianFilter   = new GaussianBlur(graphicsDevice, spriteBatch, Content.Load <Effect>("shaders/gaussian-blur"));

            // Create scenes in the scene manager
            sceneManager.AddScene(SceneID.Terrain, basicShader, terrain, null, Vector3.Transform(new Vector3(0f, 0f, 100f), Matrix.CreateRotationX(MathHelper.ToRadians(-40f))));
            sceneManager.AddScene(SceneID.Wood, woodShader, tabletopModel, null, Vector3.Transform(new Vector3(0f, 0f, 100f), Matrix.CreateRotationX(MathHelper.ToRadians(20f))));
            sceneManager.AddScene(SceneID.Lambertian, lambertianShader, teapotModel, null, Vector3.Transform(new Vector3(0f, 0f, 100f), Matrix.CreateRotationX(MathHelper.ToRadians(-20f))));
            sceneManager.AddScene(SceneID.Phong, phongShader, teapotModel, null, Vector3.Transform(new Vector3(0f, 0f, 100f), Matrix.CreateRotationX(MathHelper.ToRadians(-20f))));
            sceneManager.AddScene(SceneID.Normals, normalShader, head);
            sceneManager.AddScene(SceneID.Checkers, checkersShader, teapotModel, null, Vector3.Transform(new Vector3(0f, 0f, 100f), Matrix.CreateRotationX(MathHelper.ToRadians(-20f))));
            sceneManager.AddScene(SceneID.CookTorrance, cookTorranceShader, head);
            sceneManager.AddScene(SceneID.Spotlight, spotLightShader, head);
            sceneManager.AddScene(SceneID.Multilight, multiLightShader, head);
            sceneManager.AddScene(SceneID.Culling, normalShader, headgerow);
            sceneManager.AddScene(SceneID.Projection, projectionShader, head);
            sceneManager.AddScene(SceneID.Monochrome, cookTorranceShader, head, monochromeFilter);
            sceneManager.AddScene(SceneID.GaussianBlur, normalShader, head, gaussianFilter);
        }