コード例 #1
0
    private void SpreadEnvironmentalZone(ZoneGeneration generationData, EnvironmentCube source)
    {
        int numSpread   = Random.Range(generationData.minSpread, generationData.maxSpread + 1);
        int spreadCount = 0;

        while (spreadCount < numSpread)
        {
            EnvironmentCube randomCube = GetRandomAdjacentCube(source, true);

            if (randomCube.cubeType != EnvironmentCube.CubeType.Water)
            {
                if (generationData.isCubeGeneration)
                {
                    source = ReplaceCube(randomCube, generationData.currentPrefab);
                }
                else
                {
                    randomCube.CreateEnvironmentalObject(generationData.currentPrefab);
                    source = randomCube;
                }

                spreadCount++;
            }
            else
            {
                source = randomCube;
            }
        }
    }
コード例 #2
0
ファイル: PbrPipeline.cs プロジェクト: jpbruyere/vke.net
        public PBRPipeline(Queue staggingQ, RenderPass renderPass, string cubeMapPath, PipelineCache pipelineCache = null) :
            base(renderPass, pipelineCache, "pbr pipeline")
        {
            descriptorPool = new DescriptorPool(Dev, 2,
                                                new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2),
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 8)
                                                );

            descLayoutMain = new DescriptorSetLayout(Dev,
                                                     new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),
                                                     new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer));

            descLayoutTextures = new DescriptorSetLayout(Dev,
                                                         new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                         );

            using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples)) {
                cfg.Layout = new PipelineLayout(Dev, descLayoutMain, descLayoutTextures);
                cfg.Layout.AddPushConstants(
                    new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()),
                    new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64)
                    );
                cfg.RenderPass = renderPass;
                cfg.AddVertexBinding <PbrModel.Vertex> (0);
                cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat);

                cfg.AddShader(Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv");
                cfg.AddShader(Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv");

                layout = cfg.Layout;

                init(cfg);
            }

            dsMain = descriptorPool.Allocate(descLayoutMain);

            envCube = new EnvironmentCube(cubeMapPath, layout, staggingQ, RenderPass);

            matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels;
            uboMats = new HostBuffer(Dev, VkBufferUsageFlags.UniformBuffer, matrices, true);

            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain.Bindings.GetRange(0, 4).ToArray());

            uboUpdate.Write(Dev, dsMain,
                            uboMats.Descriptor,
                            envCube.irradianceCube.Descriptor,
                            envCube.prefilterCube.Descriptor,
                            envCube.lutBrdf.Descriptor);
        }
コード例 #3
0
	public void Spawn( EnvironmentCube cube )
	{
		gameObject.SetActive( true );
		transform.position = cube.GetCoordinates().GetWorldPosition();

		_currentCube = cube;
		_canMove = true;
		_canAttack = true;

		BeginMovement();
	}
コード例 #4
0
    private EnvironmentCube ReplaceCube(EnvironmentCube oldCube, GameObject newCubePrefab)
    {
        GridCoordinates coordinates = oldCube._coordinates;

        Destroy(oldCube.gameObject);

        EnvironmentCube newCube = CreateCube(newCubePrefab, coordinates);

        _grid[coordinates.x, coordinates.z] = newCube;

        return(newCube);
    }
コード例 #5
0
    private void CreateGrid(EnvironmentCube basePrefab)
    {
        _grid = new EnvironmentCube[gridSizeX, gridSizeZ];

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int z = 0; z < gridSizeZ; z++)
            {
                GridCoordinates coordinates = new GridCoordinates(x, z);
                _grid[x, z] = CreateCube(basePrefab.gameObject, coordinates);
            }
        }
    }
コード例 #6
0
    private EnvironmentCube CreateCube(GameObject prefab, GridCoordinates coordinates)
    {
        GameObject gameObject = GameObject.Instantiate(prefab) as GameObject;

        gameObject.transform.parent   = transform;
        gameObject.transform.position = coordinates.GetWorldPosition();

        EnvironmentCube environmentCube = gameObject.GetComponent <EnvironmentCube>();

        environmentCube._coordinates = coordinates;

        return(environmentCube);
    }
コード例 #7
0
    public void Spawn(EnvironmentCube cube)
    {
        gameObject.SetActive(true);
        transform.position             = cube.GetCoordinates().GetWorldPosition();
        Camera.main.transform.position = new Vector3(transform.position.x, Camera.main.transform.position.y, transform.position.z);

        _currentCube = cube;
        _canMove     = true;
        _health      = MAX_HEALTH;

        CameraOperator.SetFocusObject(transform);
        CameraOperator.SnapToFocus();
        CameraOperator.FollowFocusObject();
    }
コード例 #8
0
    public EnvironmentCube GetRandomAdjacentCube(EnvironmentCube source, bool unoccupied = false)
    {
        EnvironmentCube adjacent    = null;
        GridCoordinates coordinates = source._coordinates;
        int             option      = Random.Range(0, 4);

        while (adjacent == null)
        {
            switch (option)
            {
            case 0:
                coordinates.z += 1;                 // north
                break;

            case 1:
                coordinates.z -= 1;                 // south
                break;

            case 2:
                coordinates.x += 1;                 // east
                break;

            case 3:
                coordinates.x -= 1;                 // west
                break;
            }

            if (AreValidCoordinates(coordinates))
            {
                adjacent = _grid[coordinates.x, coordinates.z];
            }

            if (adjacent == null || (unoccupied && adjacent.IsOccupied()))
            {
                coordinates = source._coordinates;

                if (++option > 3)
                {
                    option = 0;
                }
            }
        }

        return(adjacent);
    }
コード例 #9
0
    private void LineWaterWithDirt(EnvironmentCube dirtPrefab)
    {
        if (dirtPrefab == null)
        {
            return;
        }

        for (int x = 0; x < gridSizeX; x++)
        {
            for (int z = 0; z < gridSizeZ; z++)
            {
                GridCoordinates coordinates = new GridCoordinates(x, z);
                EnvironmentCube cube        = _grid[coordinates.x, coordinates.z];
                if (cube != null)
                {
                    if (cube.cubeType == EnvironmentCube.CubeType.Grass)
                    {
                        EnvironmentCube adjacentNorth     = GetAdjacentNorth(cube);
                        EnvironmentCube adjacentSouth     = GetAdjacentSouth(cube);
                        EnvironmentCube adjacentEast      = GetAdjacentEast(cube);
                        EnvironmentCube adjacentWest      = GetAdjacentWest(cube);
                        EnvironmentCube adjacentNorthEast = GetAdjacentNorthEast(cube);
                        EnvironmentCube adjacentNorthWest = GetAdjacentNorthWest(cube);
                        EnvironmentCube adjacentSouthEast = GetAdjacentSouthEast(cube);
                        EnvironmentCube adjacentSouthWest = GetAdjacentSouthWest(cube);

                        if ((adjacentNorth != null && adjacentNorth.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentSouth != null && adjacentSouth.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentEast != null && adjacentEast.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentWest != null && adjacentWest.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentNorthEast != null && adjacentNorthEast.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentNorthWest != null && adjacentNorthWest.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentSouthEast != null && adjacentSouthEast.cubeType == EnvironmentCube.CubeType.Water) ||
                            (adjacentSouthWest != null && adjacentSouthWest.cubeType == EnvironmentCube.CubeType.Water))
                        {
                            ReplaceCube(cube, dirtPrefab.gameObject);
                        }
                    }
                }
            }
        }
    }
コード例 #10
0
    private void MoveToCube(EnvironmentCube cube, Vector3 rotation)
    {
        if (cube != null && cube != _currentCube)
        {
            _previousCube = _currentCube;
            _currentCube  = cube;
            _canMove      = false;

            if (MathUtils.IsNotEqual(transform.eulerAngles, rotation, 1.0f))
            {
                transform.DOKill();
                transform.DORotate(rotation, MOVEMENT_ANIMATION_ROTATION_DURATION).
                OnComplete(StartMovementAnimation);
            }
            else
            {
                StartMovementAnimation();
            }
        }
    }
コード例 #11
0
    public EnvironmentCube GetRandomCubeOfType(EnvironmentCube.CubeType type, bool unoccupied = false)
    {
        EnvironmentCube randomCube = null;

        while (randomCube == null)
        {
            randomCube = GetRandomCube();
            bool isUnoccupied = !randomCube.IsOccupied();

            if (randomCube.cubeType == type && (!unoccupied || (unoccupied && isUnoccupied)))
            {
                break;
            }
            else
            {
                randomCube = null;
            }
        }

        return(randomCube);
    }
コード例 #12
0
    private void GenerateEnvironmentalZone(ZoneGeneration generationData)
    {
        int numSources = Random.Range(generationData.minSources, generationData.maxSources + 1);

        for (int i = 0; i < numSources; i++)
        {
            EnvironmentCube randomCube = GetRandomCubeOfType(EnvironmentCube.CubeType.Grass, true);
            EnvironmentCube sourceCube = randomCube;

            generationData.currentPrefab = generationData.prefabs[Random.Range(0, generationData.prefabs.Length)];

            if (generationData.isCubeGeneration)
            {
                sourceCube = ReplaceCube(randomCube, generationData.currentPrefab);
            }
            else
            {
                randomCube.CreateEnvironmentalObject(generationData.currentPrefab);
            }

            SpreadEnvironmentalZone(generationData, sourceCube);
        }
    }
コード例 #13
0
        void init()
        {
            renderPass = new RenderPass(dev);
            renderPass.AddAttachment(swapChain.ColorFormat, VkImageLayout.ColorAttachmentOptimal, VkSampleCountFlags.SampleCount1);
            renderPass.AddAttachment(dev.GetSuitableDepthFormat(), VkImageLayout.DepthStencilAttachmentOptimal, samples);
            renderPass.AddAttachment(VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal);
            renderPass.AddAttachment(VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal);
            renderPass.AddAttachment(VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal);
            renderPass.AddAttachment(VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal);

            renderPass.ClearValues.Add(new VkClearValue {
                color = new VkClearColorValue(0.0f, 0.0f, 0.0f)
            });
            renderPass.ClearValues.Add(new VkClearValue {
                depthStencil = new VkClearDepthStencilValue(1.0f, 0)
            });
            renderPass.ClearValues.Add(new VkClearValue {
                color = new VkClearColorValue(0.0f, 0.0f, 0.0f)
            });
            renderPass.ClearValues.Add(new VkClearValue {
                color = new VkClearColorValue(0.0f, 0.0f, 0.0f)
            });
            renderPass.ClearValues.Add(new VkClearValue {
                color = new VkClearColorValue(0.0f, 0.0f, 0.0f)
            });
            renderPass.ClearValues.Add(new VkClearValue {
                color = new VkClearColorValue(0.0f, 0.0f, 0.0f)
            });

            SubPass[] subpass = { new SubPass(), new SubPass() };
            subpass[0].AddColorReference(new VkAttachmentReference(2, VkImageLayout.ColorAttachmentOptimal),
                                         new VkAttachmentReference(3, VkImageLayout.ColorAttachmentOptimal),
                                         new VkAttachmentReference(4, VkImageLayout.ColorAttachmentOptimal),
                                         new VkAttachmentReference(5, VkImageLayout.ColorAttachmentOptimal));
            subpass[0].SetDepthReference(1, VkImageLayout.DepthStencilAttachmentOptimal);

            subpass[1].AddColorReference(0, VkImageLayout.ColorAttachmentOptimal);
            subpass[1].AddInputReference(new VkAttachmentReference(2, VkImageLayout.ShaderReadOnlyOptimal),
                                         new VkAttachmentReference(3, VkImageLayout.ShaderReadOnlyOptimal),
                                         new VkAttachmentReference(4, VkImageLayout.ShaderReadOnlyOptimal),
                                         new VkAttachmentReference(5, VkImageLayout.ShaderReadOnlyOptimal));
            renderPass.AddSubpass(subpass);

            renderPass.AddDependency(Vk.SubpassExternal, 0,
                                     VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.ColorAttachmentOutput,
                                     VkAccessFlags.MemoryRead, VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite);
            renderPass.AddDependency(0, 1,
                                     VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.FragmentShader,
                                     VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.ShaderRead);
            renderPass.AddDependency(1, Vk.SubpassExternal,
                                     VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.BottomOfPipe,
                                     VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.MemoryRead);


            descriptorPool = new DescriptorPool(dev, 3,
                                                new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2),
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 3),
                                                new VkDescriptorPoolSize(VkDescriptorType.InputAttachment, 4)
                                                );

            descLayoutMain = new DescriptorSetLayout(dev,
                                                     new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),
                                                     new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));

            descLayoutModelTextures = new DescriptorSetLayout(dev,
                                                              new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                              new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                              new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                              new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                              new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                              );

            descLayoutGBuff = new DescriptorSetLayout(dev,
                                                      new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),
                                                      new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),
                                                      new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),
                                                      new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment));

            dsMain  = descriptorPool.Allocate(descLayoutMain);
            dsGBuff = descriptorPool.Allocate(descLayoutGBuff);

            GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples);

            cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutModelTextures, descLayoutGBuff);
            cfg.Layout.AddPushConstants(
                new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()),
                new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64)
                );
            cfg.RenderPass = renderPass;
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));

            cfg.AddVertexBinding <Model.Vertex> (0);
            cfg.SetVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
            cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv");
            cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/GBuffPbr.frag.spv");

            gBuffPipeline = new GraphicPipeline(cfg);
            cfg.blendAttachments.Clear();
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.ResetShadersAndVerticesInfos();
            cfg.SubpassIndex = 1;
            cfg.Layout       = gBuffPipeline.Layout;
            cfg.depthStencilState.depthTestEnable  = false;
            cfg.depthStencilState.depthWriteEnable = false;
            cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv");
            cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv");
            composePipeline = new GraphicPipeline(cfg);

            envCube = new EnvironmentCube(presentQueue, renderPass);

            uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf <Matrices> () * 2);
            uboMats.Map();             //permanent map

            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain);

            uboUpdate.Write(dev, dsMain, uboMats.Descriptor,
                            envCube.lutBrdf.Descriptor,
                            envCube.irradianceCube.Descriptor,
                            envCube.prefilterCube.Descriptor);
            uboMats.Descriptor.offset = (ulong)Marshal.SizeOf <Matrices> ();
            envCube.WriteDesc(uboMats.Descriptor);
#if DEBUG
            debugDraw = new DebugDrawPipeline(dev, descLayoutMain, swapChain.ColorFormat);
            debugDraw.AddLine(Vector3.Zero, new Vector3(matrices.lightPos.X, matrices.lightPos.Y, matrices.lightPos.Z) * 3, 1, 1, 1);
            debugDraw.AddLine(Vector3.Zero, Vector3.UnitX, 1, 0, 0);
            debugDraw.AddLine(Vector3.Zero, Vector3.UnitY, 0, 1, 0);
            debugDraw.AddLine(Vector3.Zero, Vector3.UnitZ, 0, 0, 1);
#endif


            model = new Model(presentQueue, "../data/models/DamagedHelmet/glTF/DamagedHelmet.gltf");
            //model = new Model (presentQueue, "../data/models/chess.gltf");
            //model = new Model (presentQueue, "../data/models/Sponza/glTF/Sponza.gltf");
            //model = new Model (dev, presentQueue, "../data/models/icosphere.gltf");
            //model = new Model (dev, presentQueue, cmdPool, "../data/models/cube.gltf");
            model.WriteMaterialsDescriptorSets(descLayoutModelTextures,
                                               VK.AttachmentType.Color,
                                               VK.AttachmentType.Normal,
                                               VK.AttachmentType.AmbientOcclusion,
                                               VK.AttachmentType.PhysicalProps,
                                               VK.AttachmentType.Emissive);
        }
コード例 #14
0
 public EnvironmentCube GetAdjacentSouthWest(EnvironmentCube cube, bool unoccupied = false, int distance = 1)
 {
     return(GetAdjacentCube(cube, Axis.SouthWest, unoccupied, distance));
 }
コード例 #15
0
 public EnvironmentCube GetAdjacentNorth(EnvironmentCube cube, bool unoccupied = false, int distance = 1)
 {
     return(GetAdjacentCube(cube, Axis.North, unoccupied, distance));
 }
コード例 #16
0
        void init(float nearPlane, float farPlane)
        {
            init_renderpass();

            descLayoutMain = new DescriptorSetLayout(dev,
                                                     new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),//matrices and params
                                                     new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),  //lights
                                                     new VkDescriptorSetLayoutBinding(5, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); //materials
#if WITH_SHADOWS
            descLayoutMain.Bindings.Add(new VkDescriptorSetLayoutBinding(6, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));
#endif

            if (TEXTURE_ARRAY)
            {
                descLayoutMain.Bindings.Add(new VkDescriptorSetLayoutBinding(7, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));                  //texture array
                //descLayoutMain.Bindings.Add (new VkDescriptorSetLayoutBinding (8, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));//down sampled hdr
            }
            else
            {
                descLayoutTextures = new DescriptorSetLayout(dev,
                                                             new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                             new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                             new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                             new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                             new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                             );
            }

            descLayoutGBuff = new DescriptorSetLayout(dev,
                                                      new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),  //color + roughness
                                                      new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),  //emit + metal
                                                      new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),  //normals + AO
                                                      new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment)); //Pos + depth



            GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, NUM_SAMPLES);
            cfg.rasterizationState.cullMode = VkCullModeFlags.Back;
            if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1)
            {
                cfg.multisampleState.sampleShadingEnable = true;
                cfg.multisampleState.minSampleShading    = 0.5f;
            }
            cfg.Cache = pipelineCache;
            if (TEXTURE_ARRAY)
            {
                cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutGBuff);
            }
            else
            {
                cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutGBuff, descLayoutTextures);
            }

            cfg.Layout.AddPushConstants(
                new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()),
                new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64)
                );
            cfg.RenderPass   = renderPass;
            cfg.SubpassIndex = SP_MODELS;
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            //cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));

            cfg.AddVertex <PbrModelTexArray.Vertex> ();

            using (SpecializationInfo constants = new SpecializationInfo(
                       new SpecializationConstant <float> (0, nearPlane),
                       new SpecializationConstant <float> (1, farPlane),
                       new SpecializationConstant <float> (2, MAX_MATERIAL_COUNT))) {
                cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#shaders.GBuffPbr.vert.spv"));
                if (TEXTURE_ARRAY)
                {
                    cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbrTexArray.frag.spv", constants));
                }
                else
                {
                    cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbr.frag.spv", constants));
                }

                gBuffPipeline = new GraphicPipeline(cfg);
            }
            cfg.rasterizationState.cullMode = VkCullModeFlags.Front;
            //COMPOSE PIPELINE
            cfg.blendAttachments.Clear();
            cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false));
            cfg.ResetShadersAndVerticesInfos();
            cfg.SubpassIndex = SP_COMPOSE;
            cfg.Layout       = gBuffPipeline.Layout;
            cfg.depthStencilState.depthTestEnable  = false;
            cfg.depthStencilState.depthWriteEnable = false;
            using (SpecializationInfo constants = new SpecializationInfo(
                       new SpecializationConstant <uint> (0, (uint)lights.Length))) {
                cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv"));
#if WITH_SHADOWS
                cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.compose_with_shadows.frag.spv", constants));
#else
                cfg.AddShader(VkShaderStageFlags.Fragment, "#shaders.compose.frag.spv", constants);
#endif
                composePipeline = new GraphicPipeline(cfg);
            }
            cfg.Shaders[1].Dispose();
            //DEBUG DRAW use subpass of compose
            cfg.Shaders[1]   = new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.show_gbuff.frag.spv");
            cfg.SubpassIndex = SP_COMPOSE;
            debugPipeline    = new GraphicPipeline(cfg);
            cfg.DisposeShaders();
            ////TONE MAPPING
            //cfg.shaders[1] = new ShaderInfo (VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv");
            //cfg.SubpassIndex = SP_TONE_MAPPING;
            //toneMappingPipeline = new GraphicPipeline (cfg);

            dsMain  = descriptorPool.Allocate(descLayoutMain);
            dsGBuff = descriptorPool.Allocate(descLayoutGBuff);

            envCube = new EnvironmentCube(cubemapPath, gBuffPipeline.Layout, gQueue, renderPass);

            matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels;

            DescriptorSetWrites dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings.GetRange(0, 5).ToArray());
            dsMainWrite.Write(dev,
                              uboMatrices.Descriptor,
                              envCube.irradianceCube.Descriptor,
                              envCube.prefilterCube.Descriptor,
                              envCube.lutBrdf.Descriptor,
                              uboLights.Descriptor);

#if WITH_SHADOWS
            dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings[6]);
            dsMainWrite.Write(dev, shadowMapRenderer.shadowMap.Descriptor);
#endif
        }
コード例 #17
0
    private EnvironmentCube GetAdjacentCube(EnvironmentCube cube, Axis axis, bool unoccupied = false, int distance = 1)
    {
        EnvironmentCube adjacent = null;

        while (adjacent == null)
        {
            GridCoordinates coordinates = cube.GetCoordinates();

            if (axis == Axis.East)
            {
                coordinates.x += distance;
            }
            else if (axis == Axis.West)
            {
                coordinates.x -= distance;
            }
            else if (axis == Axis.North)
            {
                coordinates.z += distance;
            }
            else if (axis == Axis.South)
            {
                coordinates.z -= distance;
            }
            else if (axis == Axis.NorthEast)
            {
                coordinates.x += distance;
                coordinates.z += distance;
            }
            else if (axis == Axis.NorthWest)
            {
                coordinates.x -= distance;
                coordinates.z += distance;
            }
            else if (axis == Axis.SouthEast)
            {
                coordinates.x += distance;
                coordinates.z -= distance;
            }
            else if (axis == Axis.SouthWest)
            {
                coordinates.x -= distance;
                coordinates.z -= distance;
            }

            if (AreValidCoordinates(coordinates))
            {
                adjacent = _grid[coordinates.x, coordinates.z];
            }

            if (adjacent != null && unoccupied && adjacent.IsOccupied())
            {
                adjacent = null;
            }

            if (adjacent == null)
            {
                distance--;
            }
        }

        return(adjacent);
    }