Пример #1
0
        void SetCubeMap(string cubemap)
        {
            KtxTextureReader texReader = new KtxTextureReader
            {
                Format      = VkFormat.R16G16B16A16SFloat,
                BorderColor = VkBorderColor.FloatTransparentBlack
            };

            cubeMap = texReader.Load("textures/hdr/" + cubemap);
            skyMaterial.SetTexture("EnvMap", cubeMap);
            Preprocess();
        }
Пример #2
0
        public override void Init()
        {
            scene = new Scene
            {
                new Node("Camera", new vec3(0, 5, -10), glm.radians(30, 0, 0))
                {
                    new Camera
                    {
                        Fov = glm.radians(60)
                    },
                },
            };

            camera = scene.GetComponent <Camera>(true);

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

            var cubeMap = texReader.Load("textures/hdr/uffizi_cube.ktx");

            {
                var model = Resources.Load <Model>("Models/cube.obj");
                var node  = scene.CreateChild("Sky");
                node.Scaling = new vec3(30.0f);
                var staticModel = node.AddComponent <StaticModel>();
                staticModel.SetModel(model);

                var mat = new Material("Shaders/Skybox.shader");
                mat.SetTexture("EnvMap", cubeMap);

                staticModel.SetMaterial(mat);
            }

            {
                material = new Material("Shaders/Reflect.shader");
                material.SetTexture("ReflMap", cubeMap);
                material.SetShaderParameter("lodBias", lodBias);

                var node = scene.CreateChild("Model");
                node.Scaling = new vec3(0.1f);

                staticModel = node.AddComponent <StaticModel>();
                SetModel(filenames[0]);
                staticModel.SetMaterial(material);
            }

            MainView.Attach(camera, scene, new ForwardHdrRenderer());
        }
Пример #3
0
        public override void Init()
        {
            scene = new Scene()
            {
                new Octree {
                },
                new DebugRenderer {
                },

                new Environment
                {
                    SunlightDir = glm.normalize(new vec3(-1.0f, -1.0f, 0.0f))
                },

                new Node("Camera", new vec3(0, 2, -30), glm.radians(10, 0, 0))
                {
                    new Camera
                    {
                        NearClip = 0.5f,
                        FarClip  = 50,
                    },
                },
            };

            camera = scene.GetComponent <Camera>(true);

            {
                var model       = GeometryUtil.CreatePlaneModel(100, 100, 32, 32, true);
                var node        = scene.CreateChild("Plane");
                var staticModel = node.AddComponent <StaticModel>();
                staticModel.SetModel(model);
                var mat = Resources.Load <Material>("materials/Grass.material");
                mat.SetTexture("NormalMap", Texture.Blue);
                staticModel.SetMaterial(mat);
            }

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

                var mat = new Material("Shaders/LitSolid.shader");
                var tex = texReader.Load("textures/oak_bark.ktx");
                mat.SetTexture("DiffMap", tex);
                mat.SetTexture("NormalMap", Texture.Blue);
                mat.SetTexture("SpecMap", Texture.Black);

                var mat1 = new Material("Shaders/LitSolid.shader");
                var tex1 = texReader.Load("textures/oak_leafs.ktx");
                mat1.SetTexture("DiffMap", tex1);
                mat1.SetTexture("NormalMap", Texture.Blue);
                mat1.SetTexture("SpecMap", Texture.Black);

                List <Geometry>    geoList  = new List <Geometry>();
                List <BoundingBox> bboxList = new List <BoundingBox>();
                AssimpModelReader.Import("Models/oak_trunk.dae", geoList, bboxList);
                AssimpModelReader.Import("Models/oak_leafs.dae", geoList, bboxList);
                var model = Model.Create(geoList, bboxList);

                for (int i = 0; i < 400; i++)
                {
                    var node = scene.CreateChild("Model");
                    node.Position = new vec3(glm.random(-40, 40), 0, glm.random(-40, 40));
                    node.Rotation = new quat(new vec3(0, glm.radians(glm.random(0, 360)), 0));
                    node.Scaling  = new vec3(glm.random(2.0f, 4.0f));
                    var staticModel = node.AddComponent <StaticModel>();
                    staticModel.CastShadows = true;
                    staticModel.SetModel(model);
                    staticModel.SetMaterial(0, mat);
                    staticModel.SetMaterial(1, mat1);
                }
            }

            MainView.Attach(camera, scene);
        }
Пример #4
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);
        }