Beispiel #1
0
        internal static void SetDiffuseAlphaInShaderEffect(this DefaultSurfaceEffect effect, float alpha)
        {
            float4 color = effect.SurfaceInput.Albedo;

            color.w = alpha;
            effect.SurfaceInput.Albedo = color;
        }
        // Init is called on startup.
        public override void Init()
        {
            // Set the clear color for the backbuffer to "greenery" ;-) (https://store.pantone.com/de/de/color-of-the-year-2017/).
            RC.ClearColor = new float4(136f / 255f, 176f / 255f, 75f / 255f, 1);

            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 0)
            };
            _cubeEffect = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);
            var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

            // Assemble the cube node containing the three components
            var cubeNode = new SceneNode();

            cubeNode.Components.Add(_cubeTransform);
            cubeNode.Components.Add(_cubeEffect);
            cubeNode.Components.Add(cubeMesh);

            // Create the scene containing the cube as the only object
            _scene = new SceneContainer();
            _scene.Children.Add(cubeNode);

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);

            _camAngle = 0;
        }
        public override void Init()
        {
            // Set the clear color for the backbuffer to "greenery"
            RC.ClearColor = (float4)(ColorUint.Black);
            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh

            /* _cubeTransform1 = new Transform {
             *   Translation = new float3(-10, 0, 40),
             *   Rotation = new float3(0,0.3f,0),
             *   };
             * _cubeshader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);
             * var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));
             *
             *
             * _cubeTransform2 = new Transform{
             *   Translation = new float3(10,0,40),
             *   Rotation = new float3(0,0.3f,0),
             * };
             *
             *
             * // Assemble the cube node containing the three components
             *
             * var Cubenode2 = new SceneNode();
             * Cubenode2.Components.Add(_cubeTransform2);
             * Cubenode2.Components.Add(_cubeshader);
             * Cubenode2.Components.Add(cubeMesh);
             *
             * var cubeNode = new SceneNode(); //Hauptnode
             * cubeNode.Components.Add(_cubeTransform1);// kinderKomponenten werden gesetzt
             * cubeNode.Components.Add(_cubeshader);
             * cubeNode.Components.Add(cubeMesh);
             *
             * // Create the scene containing the cube as the only object
             * _scene = new SceneContainer();
             * _scene.Children.Add(cubeNode);
             * _scene.Children.Add(Cubenode2);                                // in childrenliste der szene einreihen
             */
            // Create a scene renderer holding the scene above


            _cubeTransform1 = new Transform {
                Translation = new float3(-10, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };
            _cubeshader  = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);
            _cubeshader2 = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Cyan, float4.Zero);

            _cubeTransform2 = new Transform {
                Translation = new float3(10, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeTransform3 = new Transform {
                Translation = new float3(0, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeTransform4 = new Transform {
                Translation = new float3(0, 0, 70),
                Rotation    = new float3(0, 0.3f, 0),
            };

            _cubeMesh = SimpleMeshes.CreateCuboid(new float3(6, 6, 6));


            node = new SceneNode {
                Components =
                {
                    _cubeTransform4,
                    _cubeshader2,
                    _cubeMesh,
                }
            };

            _scene = new SceneContainer
            {
                Children =
                {
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform1,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform2,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform3,
                            _cubeshader,
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    node
                }
            };


            _sceneRenderer = new SceneRendererForward(_scene);//renderer der einzelne pixel einfärben kann
        }
Beispiel #4
0
        public override void Init()//Farbe wird definiert
        {
            // Set the clear color for the backbuffer to "greenery"
            RC.ClearColor = (float4)ColorUint.Greenery;

            // Create a scene with a cube
            // The three components: one Transform, one ShaderEffect (blue material) and the Mesh

            //Umständliche Schreibweise

            /*_cubeTransform = new Transform
             * {
             *  Translation = new float3(0, 0, 20), //Position wird festgelegt (3D), x,y,z
             *  Rotation = new float3(0, 0.3f, 0),
             * };
             * _cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero); //hier wird die Farbe festgelegt; Grundfarbe
             * var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));// Größe des Würfels
             *
             * // Assemble the cube node containing the three components
             * var cubeNode = new SceneNode();
             * cubeNode.Components.Add(_cubeTransform); //fügt die Transform-Kompenente an
             * cubeNode.Components.Add(_cubeShader); // fügt den Shader
             * cubeNode.Components.Add(cubeMesh);// fügt den Mesh
             *
             * // Create the scene containing the cube as the only object
             * _scene = new SceneContainer(); // Container, der alles enthält
             * _scene.Children.Add(cubeNode);// Node zu den Kinder-Komponenten hinzufügen
             */

            //Alternative (einfache) Schreibweise
            _cubeTransform = new Transform {
                Translation = new float3(0, 0, 20),
                Rotation    = new float3(0, 0.3f, 0),
            };
            _cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);

            _scene = new SceneContainer
            {
                Children =
                {
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,
                            _cubeShader,
                            SimpleMeshes.CreateCuboid(new float3(10, 10, 10))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            new Transform {
                                Translation = new float3(0, 0, 10), Rotation = new float3(0, 0.3f, 0)
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(5, 10, 5))
                        }
                    }
                }
            };

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene); //
        }
        public override void Init()
        {
            // Set the clear color for the backbuffer to "greenery"
            RC.ClearColor = (float4)ColorUint.Greenery;

            _cubeTransform = new Transform
            {
                Translation = new float3(0, 0, 50),
                Rotation    = new float3(0, 0, 2.3f),
            };
            _cubeShader = MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero);
            _scene      = new SceneContainer
            {
                Children =
                {
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,
                            _cubeShader,
                            SimpleMeshes.CreateCuboid(new float3(4, 4, 4))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,                                              new Transform{
                                Translation = new float3(12,                          5, 15),
                                Rotation    = new float3(20.8f,                                                           55.3f, 6.9f),
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.BlueViolet, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(4, 4, 4))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,                                         new Transform{
                                Translation = new float3(12,                       -15, 17),
                                Rotation    = new float3(34f,                                                      0.03f * Time.DeltaTime, 0)
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.Wheat, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(6, 6, 6))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,                                        new Transform{
                                Translation = new float3(0,                     15, -15),
                                Rotation    = new float3(6.9f,                                                     0.3f * Time.DeltaTime, 0)
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.Blue, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(3, 3, 3))
                        }
                    },
                    new SceneNode
                    {
                        Components =
                        {
                            _cubeTransform,                                          new Transform{
                                Translation = new float3(-25,                          -10, 8),
                                Rotation    = new float3(0,                                                       6.9f, 67.2f)
                            },
                            MakeEffect.FromDiffuseSpecular((float4)ColorUint.Yellow, float4.Zero),
                            SimpleMeshes.CreateCuboid(new float3(2, 2, 2))
                        }
                    }
                }
            };

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRendererForward(_scene);
        }