Esempio n. 1
0
        public override void Init()
        {
            base.Init();

            scene = new Scene
            {
                new Node("Camera", new vec3(120.0f, 0.0f, -50))
                {
                    new Camera
                    {
                        Fov = glm.radians(60)
                    },
                },
            };

            camera = scene.GetComponent <Camera>(true);
            camera.Node.LookAt(new vec3(0.0f, 5.0f, -50), TransformSpace.WORLD);

            envMap  = Texture.Create(kEnvMapSize, kEnvMapSize, VkImageViewType.ImageCube, 6, VkFormat.R16G16B16A16SFloat, 0, VkImageUsageFlags.Storage | VkImageUsageFlags.TransferSrc);
            irMap   = Texture.Create(kIrradianceMapSize, kIrradianceMapSize, VkImageViewType.ImageCube, 6, VkFormat.R16G16B16A16SFloat, 1, VkImageUsageFlags.Storage);
            brdfLUT = Texture.Create(kBRDF_LUT_Size, kBRDF_LUT_Size, VkImageViewType.Image2D, 1, VkFormat.R16G16SFloat, 1, VkImageUsageFlags.Storage);

            {
                var model = GeometryUtil.CreateCubeModel(10, 10, 10);
                var node  = scene.CreateChild("Sky");

                var staticModel = node.AddComponent <StaticModel>();
                staticModel.SetModel(model);

                skyMaterial = new Material("Shaders/Skybox.shader");
                staticModel.SetMaterial(skyMaterial);
            }

            {
                var node = scene.CreateChild("Mesh");
                node.EulerAngles = glm.radians(0, 180, 0);
                var staticModel = node.AddComponent <StaticModel>();
                staticModel.ModelFile = "models/cerberus/cerberus.fbx";

                KtxTextureReader texReader = new KtxTextureReader
                {
                    Format = VkFormat.R8G8B8A8UNorm,
                };

                var colorMap  = texReader.Load("models/cerberus/albedo.ktx");// VkFormat.R8g8b8a8Srgb);
                var normalMap = texReader.Load("models/cerberus/normal.ktx");
                texReader.Format = VkFormat.R8UNorm;
                var metallicMap = texReader.Load("models/cerberus/metallic.ktx");
                texReader.Format = VkFormat.R8UNorm;
                var roughnessMap = texReader.Load("models/cerberus/roughness.ktx");
                //var aoMap = Texture.LoadFromFile("models/cerberus/ao.ktx", VkFormat.R8Unorm);

                var mat = new Material("Shaders/LitPbr.shader");
                mat.SetTexture("albedoMap", colorMap);
                mat.SetTexture("normalMap", normalMap);
                mat.SetTexture("metallicMap", metallicMap);
                mat.SetTexture("roughnessMap", roughnessMap);
                //mat.SetTexture("aoMap", aoMap);

                //AddDebugImage(colorMap, normalMap, metallicMap, roughnessMap);

                staticModel.SetMaterial(mat);

                pbrMaterial = mat;
            }

            //todo:
            pbrMaterial.PipelineResourceSet[0].ResourceSet[2].Bind(envMap, irMap, brdfLUT);

            computeSampler = new Sampler(VkFilter.Linear, VkSamplerMipmapMode.Linear, VkSamplerAddressMode.ClampToBorder, 1, false, VkBorderColor.FloatTransparentBlack);
            brdfLUTSampler = new Sampler(VkFilter.Linear, VkSamplerMipmapMode.Linear, VkSamplerAddressMode.ClampToEdge, 1, false);

            SetCubeMap(cubeMaps[0]);

//             FrameGraph.AddDebugImage(envMap);
//             FrameGraph.AddDebugImage(irMap);
//             FrameGraph.AddDebugImage(brdfLUT);

            MainView.Attach(camera, scene);
        }