Ejemplo n.º 1
0
        // Init is called on startup.
        public override void Init()
        {
            var fontLato    = AssetStorage.Get <Font>("Lato-Black.ttf");
            var fontLatoMap = new FontMap(fontLato, 32);

            var vsTex = AssetStorage.Get <string>("texture.vert");
            var psTex = AssetStorage.Get <string>("texture.frag");

            var icosphereWithTangents = new Icosphere(5);

            icosphereWithTangents.Tangents   = icosphereWithTangents.CalculateTangents();
            icosphereWithTangents.BiTangents = icosphereWithTangents.CalculateBiTangents();

            icosphereWithTangents.BoundingBox = new AABBf(icosphereWithTangents.Vertices);

            var canvasWidth  = Width / 100f;
            var canvasHeight = Height / 100f;

            var guiDescriptionScene = new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    new CanvasNode("Canvas", CanvasRenderMode.World, new MinMaxRect
                    {
                        Min = new float2(-canvasWidth / 2, -canvasHeight / 2f),
                        Max = new float2(canvasWidth / 2, canvasHeight / 2f)
                    })
                    {
                        Children = new ChildList
                        {
                            new TextNode(
                                "How-To:\n############################\n- Move with WASD\n- Left mouse button rotates spheres\n- Mouse wheel zooms",
                                "howTo",
                                vsTex,
                                psTex,
                                UIElementPosition.GetAnchors(AnchorPos.DownDownLeft),
                                UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, new float2(-11, -5), canvasHeight, canvasWidth, new float2(12, 1)),
                                fontLatoMap,
                                new float4(1, 1, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Complete", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-15, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Complete",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center), new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.5f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and specular", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-10, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo and Specular",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo, specular and albedo texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(-5, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo, specular and\nalbedo texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Specular texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(0, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Specular texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Normal map", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(5, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Normal map",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and emissive", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(10, 2.5f, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo and emissive",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.25f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    },
                    new CanvasNode("Albedo and emissive with texture", CanvasRenderMode.World, MinMaxRect.FromCenterSize(float2.Zero, float2.One))
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Name        = "TextTransform",
                                Translation = new float3(15, 3, 0)
                            }
                        },
                        Children = new ChildList
                        {
                            new TextNode(
                                "Albedo, emissive and\nemissive texture",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect(),
                                fontLatoMap,
                                new float4(0, 0, 0, 1),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center),
                            new TextNode(
                                "NOT YET IMPLEMENTED",
                                "desc",
                                vsTex,
                                psTex,
                                MinMaxRect.FromCenterSize(float2.Zero, float2.One),
                                new MinMaxRect
                            {
                                Max = new float2(0, 0),
                                Min = new float2(0, -1.75f)
                            },
                                fontLatoMap,
                                new float4(1, 0, 0, 0.75f),
                                HorizontalTextAlignment.Left,
                                VerticalTextAlignment.Center)
                        }
                    }
                }
            };

            _scene = new SceneContainer
            {
                Header = new SceneHeader
                {
                    CreatedBy    = "MR",
                    CreationDate = DateTime.Now.ToString(),
                    Generator    = "by hand"
                },
                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Children = new ChildList
                        {
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "complete",
                                        Translation = new float3(-15, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasSpecular      = true,
                                            //HasSpecularTexture = true,
                                            HasEmissive        = true,
                                            HasEmissiveTexture = true,
                                            HasNormalMap       = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor       = float4.One * 0.25f,
                                            AlbedoMix         =                 1f,
                                            AlbedoTexture     = "albedoTex.jpg",
                                            SpecularColor     = float4.One,
                                            SpecularIntensity =                 2f,
                                            SpecularShininess =                25f,
                                            SpecularMix       =                 1f,
                                            //SpecularTexture = "specularTex.jpg",
                                            NormalMap          = "normalTex.jpg",
                                            NormalMapIntensity =                 1f,
                                            EmissiveColor      = new float4(0, 1, 1, 1),
                                            EmissiveMix        =               0.5f,
                                            EmissiveTexture    = "emissiveTex.jpg"
                                        }
                                    }),
                                    icosphereWithTangents,
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo and specular",
                                        Translation = new float3(-10, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectProto(albedoColor: new float4(0.39f, 0.19f, 0, 1),
                                                                            specularColor: new float4(.5f, .5f, .5f, 1),
                                                                            shininess: 25.0f,
                                                                            specularIntensity: 2.5f),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, specular, albedo texture",
                                        Translation = new float3(-5, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectProto(albedoColor: new float4(0.39f, 0.19f, 0, 1),
                                                                            specularColor: new float4(.5f, .5f, .5f, 1),
                                                                            albedoTexture: "albedoTex.jpg",
                                                                            albedoTextureMix: 1f,
                                                                            shininess: 256.0f,
                                                                            specularIntensity: 20.0f),
                                    icosphereWithTangents
                                }
                            },
                            // ---- Specular Textures are not implemented yet. There is no fitting shader! ---- //
                            //new SceneNode
                            //{
                            //    Components = new List<SceneComponent>
                            //    {
                            //        new Transform
                            //        {
                            //            Name = "specular texture",
                            //            Translation = new float3(0, 0, 0)
                            //        },
                            //        ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                            //        {
                            //            MatProbs =
                            //            {
                            //                HasAlbedo = true,
                            //                HasAlbedoTexture = true,
                            //                HasSpecular = true,
                            //                HasSpecularTexture = true
                            //            },
                            //            MatType = MaterialType.Standard,
                            //            MatValues =
                            //            {
                            //                AlbedoColor = new float4(0.39f, 0.19f, 0, 1),
                            //                SpecularColor = float4.One,
                            //                SpecularIntensity = 2f,
                            //                SpecularShininess = 25f,
                            //                SpecularMix = 1f, // TODO: Implement in ShaderShards
                            //                SpecularTexture = "specularTex.jpg" // TODO: Implement in ShaderShards
                            //            }
                            //        }),
                            //        icosphereWithTangents
                            //    }
                            //},
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "normal map",
                                        Translation = new float3(5, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasNormalMap     = true,
                                            HasSpecular      = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor        = float4.One * 0.25f,
                                            AlbedoMix          =                 1f,
                                            AlbedoTexture      = "albedoTex.jpg",
                                            SpecularColor      = float4.One,
                                            SpecularIntensity  =                 5f,
                                            SpecularShininess  =               200f,
                                            NormalMap          = "normalTex.jpg",
                                            NormalMapIntensity = 1f
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, emissive",
                                        Translation = new float3(10, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo        = true,
                                            HasAlbedoTexture = true,
                                            HasEmissive      = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor   = float4.One * 0.25f,
                                            AlbedoMix     =                 1f,
                                            AlbedoTexture = "albedoTex.jpg",
                                            EmissiveColor = new float4(1, 0, 0, 1) // TODO: Implement in ShaderShards
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            },
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Name        = "albedo, emissive, emissive texture",
                                        Translation = new float3(15, 0, 0)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new ShaderEffectProps
                                    {
                                        MatProbs =
                                        {
                                            HasAlbedo          = true,
                                            HasAlbedoTexture   = true,
                                            HasEmissive        = true,
                                            HasEmissiveTexture = true
                                        },
                                        MatType   = MaterialType.Standard,
                                        MatValues =
                                        {
                                            AlbedoColor     = float4.One * 0.25f,
                                            AlbedoMix       =                 1f,
                                            AlbedoTexture   = "albedoTex.jpg",
                                            EmissiveColor   = new float4(0, 1, 1, 1), // TODO: Implement in ShaderShards
                                            EmissiveMix     =               0.5f,     // TODO: Implement in ShaderShards
                                            EmissiveTexture = "emissiveTex.jpg"       // TODO: Implement in ShaderShards
                                        }
                                    }),
                                    icosphereWithTangents
                                }
                            }
                        }
                    }
                }
            };

            _guiDescRenderer = new SceneRendererForward(guiDescriptionScene);
            _renderer        = new SceneRendererDeferred(_scene);
        }
Ejemplo n.º 2
0
        // Init is called on startup.
        public override void Init()
        {
            _camTransform = new Transform()
            {
                Scale       = float3.One,
                Translation = float3.Zero
            };

            _gui = CreateGui();

            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            // Set the clear color for the backbuffer to white (100% intensity in all color channels R, G, B, A).
            _campComp.BackgroundColor = _backgroundColorDay = _backgroundColor = new float4(0.8f, 0.9f, 1, 1);
            _backgroundColorNight     = new float4(0, 0, 0.05f, 1);

            // Load the rocket model
            _rocketScene = AssetStorage.Get <SceneContainer>("sponza.fus");
            //_rocketScene = AssetStorage.Get<SceneContainer>("sponza_wo_textures.fus");
            //_rocketScene = AssetStorage.Get<Scene>("shadowTest.fus");



            //Add lights to the scene
            _sun = new Light()
            {
                Type = LightType.Parallel, Color = new float4(0.99f, 0.9f, 0.8f, 1), Active = true, Strength = 1f, IsCastingShadows = true, Bias = 0.0f
            };
            var redLight = new Light()
            {
                Type = LightType.Point, Color = new float4(1, 0, 0, 1), MaxDistance = 150, Active = true, IsCastingShadows = false, Bias = 0.015f
            };
            var blueLight = new Light()
            {
                Type = LightType.Spot, Color = new float4(0, 0, 1, 1), MaxDistance = 900, Active = true, OuterConeAngle = 25, InnerConeAngle = 5, IsCastingShadows = true, Bias = 0.000040f
            };
            var greenLight = new Light()
            {
                Type = LightType.Point, Color = new float4(0, 1, 0, 1), MaxDistance = 600, Active = true, IsCastingShadows = true, Bias = 0f
            };

            _sunTransform = new Transform()
            {
                Translation = new float3(0, 2000, 0), Rotation = new float3(M.DegreesToRadians(90), 0, 0), Scale = new float3(500, 500, 500)
            };

            var aLotOfLights = new ChildList
            {
                new SceneNode()
                {
                    Name       = "sun",
                    Components = new List <SceneComponent>()
                    {
                        _sunTransform,
                        _sun,
                    },
                    //Children = new ChildList()
                    //{
                    //    new SceneNode()
                    //    {
                    //        s = new List<Scene>()
                    //        {
                    //            new Transform
                    //            {
                    //                Scale = float3.One/2f
                    //            },
                    //            new Cube()
                    //        }
                    //    }
                    //}
                },
                new SceneNode()
                {
                    Name       = "blueLight",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(-600, 180, 180), Rotation = new float3(M.DegreesToRadians(180), 0, 0)
                        },
                        blueLight,
                    }
                },
                new SceneNode()
                {
                    Name       = "redLight1",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(-600, 180, 180)
                        },
                        redLight,
                    }
                },
                new SceneNode()
                {
                    Name       = "redLight2",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(-600, 180, -140)
                        },
                        redLight,
                    }
                },
                new SceneNode()
                {
                    Name       = "redLight3",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(500, 180, 180)
                        },
                        redLight,
                    }
                },
                new SceneNode()
                {
                    Name       = "redLight4",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(500, 180, -140)
                        },
                        redLight,
                    }
                },
                new SceneNode()
                {
                    Name       = "greenLight",
                    Components = new List <SceneComponent>()
                    {
                        new Transform()
                        {
                            Translation = new float3(0, 100, 150)
                        },
                        greenLight,
                    }
                },
            };

            _rocketScene.Children.Add(new SceneNode()
            {
                Name     = "Light",
                Children = aLotOfLights
            });

            _rocketScene.Children.Add(
                new SceneNode()
            {
                Name       = "Cam",
                Components = new List <SceneComponent>()
                {
                    _camTransform,
                    _campComp
                }
            }
                );

            // Wrap a SceneRenderer around the scene.
            _sceneRenderer = new SceneRendererDeferred(_rocketScene);

            // Wrap a SceneRenderer around the GUI.
            _guiRenderer = new SceneRendererForward(_gui);
        }