Example #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);
        }
        public static SceneContainer SceneShouldGT()
        {
            return(new SceneContainer
            {
                Header = new SceneHeader
                {
                    CreationDate = DateTime.Today.ToString(),
                    Generator = "SerializationTest",
                    CreatedBy = "Fusee Test Code"
                },

                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Name = "Base",
                        Components = new List <SceneComponent>
                        {
                            new CanvasTransform(Engine.Core.Scene.CanvasRenderMode.Screen)
                            {
                                Name = "CanvasTransform",
                                Scale = float2.One * 2,
                                ScreenSpaceSize = new MinMaxRect
                                {
                                    Max = float2.One * 22,
                                    Min = float2.One * -1
                                },
                                Size = new MinMaxRect
                                {
                                    Min = float2.One * 22,
                                    Max = float2.One * -1
                                }
                            },
                            new XFormText
                            {
                                Name = "XFormText",
                                Height = 10,
                                HorizontalAlignment = Engine.Core.Scene.HorizontalTextAlignment.Center,
                                VerticalAlignment = Engine.Core.Scene.VerticalTextAlignment.Top,
                                Width = 200
                            },
                            new XForm
                            {
                                Name = "XForm"
                            },
                            new RectTransform
                            {
                                Anchors = new MinMaxRect
                                {
                                    Max = float2.Zero,
                                    Min = float2.One
                                },
                                Name = "Rect",
                                Offsets = new MinMaxRect
                                {
                                    Max = float2.Zero,
                                    Min = float2.One
                                }
                            },
                            new Transform {
                                Scale = new float3(100, 20, 100)
                            },
                            new Bone
                            {
                                Name = "MyBone"
                            },
                            new Weight
                            {
                                BindingMatrices = new List <float4x4>(),
                                Joints = new List <SceneNode>(),
                                Name = "MyWeight",
                                WeightMap = new List <Engine.Core.Scene.VertexWeightList>
                                {
                                    new Engine.Core.Scene.VertexWeightList
                                    {
                                        VertexWeights = new List <Engine.Core.Scene.VertexWeight>
                                        {
                                            new Engine.Core.Scene.VertexWeight
                                            {
                                                Weight = 20,
                                                JointIndex = 0
                                            },
                                            new Engine.Core.Scene.VertexWeight
                                            {
                                                Weight = 30,
                                                JointIndex = 1
                                            },
                                        }
                                    }
                                }
                            },
                            ShaderCodeBuilder.MakeShaderEffectProto(
                                albedoColor: ColorUint.Tofloat4(ColorUint.Red),
                                specularColor: ColorUint.Tofloat4(ColorUint.White),
                                shininess: 4.0f,
                                specularIntensity: 1.0f),

                            new Light
                            {
                                Name = "MyLight",
                                Bias = 0,
                                MaxDistance = 100,
                                Active = true,
                                Color = float4.One,
                                InnerConeAngle = 20,
                                IsCastingShadows = true,
                                OuterConeAngle = 20,
                                Strength = 100,
                                Type = LightType.Point
                            },
                            new Octant
                            {
                                Center = double3.One,
                                Guid = new Guid(1, 2, 3, new byte[] { 4, 4, 4, 4, 4, 4, 4, 4 }),
                                IsLeaf = false,
                                Level = 10,
                                Name = "MyOctant",
                                NumberOfPointsInNode = 2,
                                PosInHierarchyTex = 0,
                                PosInParent = 5,
                                Size = 20,
                                VisibleChildIndices = 1,
                                WasLoaded = true
                            },
                            new Camera(Engine.Core.Scene.ProjectionMethod.Orthographic, 0, 500, 2000),
                            ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto(new Engine.Core.ShaderShards.ShaderEffectProps
                            {
                                MatValues =
                                {
                                    FresnelReflectance = 100,
                                    DiffuseFraction    = 200,
                                    RoughnessValue     = 1
                                }
                            }),
                            new Cube()
                        },
                        Children = new ChildList
                        {
                            new SceneNode
                            {
                                Name = "Arm01",
                                Components = new List <SceneComponent>
                                {
                                    new Transform {
                                        Translation = new float3(0, 60, 0), Scale = new float3(20, 100, 20)
                                    },
                                    ShaderCodeBuilder.MakeShaderEffectProto(
                                        albedoColor: ColorUint.Tofloat4(ColorUint.Green),
                                        specularColor: ColorUint.Tofloat4(ColorUint.White),
                                        specularIntensity: 1.0f,
                                        shininess: 4.0f),
                                    new Cube()
                                },
                                Children = new ChildList
                                {
                                    new SceneNode
                                    {
                                        Name = "Arm02Rot",
                                        Components = new List <SceneComponent>
                                        {
                                            new Bone
                                            {
                                                Name = "MyBone2"
                                            },
                                            new Transform {
                                                Translation = new float3(-20, 40, 0), Rotation = new float3(0.35f, 0, 0), Scale = float3.One
                                            },
                                        },
                                        Children = new ChildList
                                        {
                                            new SceneNode
                                            {
                                                Name = "Arm02",
                                                Components = new List <SceneComponent>
                                                {
                                                    new Transform {
                                                        Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20)
                                                    },
                                                    ShaderCodeBuilder.MakeShaderEffectProto(
                                                        albedoColor: ColorUint.Tofloat4(ColorUint.Yellow),
                                                        specularColor: ColorUint.Tofloat4(ColorUint.White),
                                                        specularIntensity: 1.0f,
                                                        shininess: 4.0f),
                                                    new Cube()
                                                },
                                                Children = new ChildList
                                                {
                                                    new SceneNode
                                                    {
                                                        Name = "Arm03Rot",
                                                        Components = new List <SceneComponent>
                                                        {
                                                            new Transform {
                                                                Translation = new float3(20, 40, 0), Rotation = new float3(0.25f, 0, 0), Scale = float3.One
                                                            },
                                                        },
                                                        Children = new ChildList
                                                        {
                                                            new SceneNode
                                                            {
                                                                Name = "Arm03",
                                                                Components = new List <SceneComponent>
                                                                {
                                                                    new Transform {
                                                                        Translation = new float3(0, 40, 0), Scale = new float3(20, 100, 20)
                                                                    },
                                                                    ShaderCodeBuilder.MakeShaderEffectProto(
                                                                        albedoColor: ColorUint.Tofloat4(ColorUint.Blue),
                                                                        specularColor: ColorUint.Tofloat4(ColorUint.White),
                                                                        specularIntensity: 1.0f,
                                                                        shininess: 4.0f),
                                                                    new Cube()
                                                                }
                                                            },
                                                        }
                                                    }
                                                }
                                            },
                                        }
                                    }
                                }
                            },
                        }
                    },
                }
            });
        }