Update homework1.cpp
							parent
							
								
									463ac6fe59
								
							
						
					
					
						commit
						11610c6a6b
					
				| 
						 | 
				
			
			@ -838,11 +838,6 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
 | 
			
		||||
		this->device = device;
 | 
			
		||||
 | 
			
		||||
#if defined(__ANDROID__)
 | 
			
		||||
		// On Android all assets are packed with the apk in a compressed form, so we need to open them using the asset manager
 | 
			
		||||
		// We let tinygltf handle this, by passing the asset manager of our app
 | 
			
		||||
		tinygltf::asset_manager = androidApp->activity->assetManager;
 | 
			
		||||
#endif
 | 
			
		||||
		bool fileLoaded = gltfContext.LoadASCIIFromFile(&glTFInput, &error, &warning, filename);
 | 
			
		||||
 | 
			
		||||
		// Pass some Vulkan resources required for setup and rendering to the glTF model loading class
 | 
			
		||||
| 
						 | 
				
			
			@ -858,7 +853,7 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
			glTFModel.loadImages(glTFInput);
 | 
			
		||||
			glTFModel.loadMaterials(glTFInput);
 | 
			
		||||
			glTFModel.loadTextures(glTFInput);
 | 
			
		||||
			glTFModel.loadSkins(glTFInput);
 | 
			
		||||
			//glTFModel.loadSkins(glTFInput);
 | 
			
		||||
			const tinygltf::Scene& scene = glTFInput.scenes[0];
 | 
			
		||||
			for (size_t i = 0; i < scene.nodes.size(); i++) {
 | 
			
		||||
				const tinygltf::Node node = glTFInput.nodes[scene.nodes[i]];
 | 
			
		||||
| 
						 | 
				
			
			@ -873,7 +868,7 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
			{
 | 
			
		||||
				
 | 
			
		||||
				glTFModel.updateJoints(node);
 | 
			
		||||
			}*/
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			for (size_t i = 0; i < glTFModel.nodes.size(); i++)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -885,7 +880,7 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
				{
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			}*/
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			vks::tools::exitFatal("Could not open the glTF file.\n\nThe file is part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.", -1);
 | 
			
		||||
| 
						 | 
				
			
			@ -969,6 +964,7 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
		loadglTFFile(getAssetPath() + "buster_drone/busterDrone.gltf",glTFModel);
 | 
			
		||||
		loadglTFFile(getAssetPath() + "models/cube.gltf", skyboxModel, true);
 | 
			
		||||
		ibltextures.skyboxCube.loadFromFile(getAssetPath() + "textures/hdr/pisa_cube.ktx", VK_FORMAT_R16G16B16A16_SFLOAT, vulkanDevice, queue);
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void VulkanExample::setupDescriptors()
 | 
			
		||||
| 
						 | 
				
			
			@ -982,15 +978,16 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
		// One combined image sampler per material image/texture
 | 
			
		||||
		vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast<uint32_t>(glTFModel.images.size())),
 | 
			
		||||
		// One ssbo per skin
 | 
			
		||||
		vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, static_cast<uint32_t>(glTFModel.skins.size())),
 | 
			
		||||
		//vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, static_cast<uint32_t>(glTFModel.skins.size())),
 | 
			
		||||
		// sampler descriptor
 | 
			
		||||
		vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,4),
 | 
			
		||||
		//animation storage buffer
 | 
			
		||||
		vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,1)
 | 
			
		||||
 | 
			
		||||
		};
 | 
			
		||||
		const uint32_t             maxSetCount = static_cast<uint32_t>(glTFModel.images.size()) + 6;
 | 
			
		||||
		// Number of descriptor sets = One for the scene ubo + one per image + one per skin
 | 
			
		||||
		const uint32_t             maxSetCount = static_cast<uint32_t>(glTFModel.images.size()) + static_cast<uint32_t>(glTFModel.skins.size()) + 1;
 | 
			
		||||
		//const uint32_t             maxSetCount = static_cast<uint32_t>(glTFModel.images.size()) + static_cast<uint32_t>(glTFModel.skins.size()) + 1+ 6 ;
 | 
			
		||||
		VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, maxSetCount);
 | 
			
		||||
		VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1018,16 +1015,16 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
		VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.ssbo));
 | 
			
		||||
		// Descriptor set layout for passing skin joint matrices
 | 
			
		||||
		
 | 
			
		||||
		setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0);
 | 
			
		||||
		VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.jointMatrices));
 | 
			
		||||
		//setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0);
 | 
			
		||||
		//VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.jointMatrices));
 | 
			
		||||
 | 
			
		||||
		// The pipeline layout uses three sets:
 | 
			
		||||
		// Set 0 = Scene matrices (VS)
 | 
			
		||||
		// Set 1 = Joint matrices (VS)
 | 
			
		||||
		// Set 2 = Material texture (FS)
 | 
			
		||||
		std::array<VkDescriptorSetLayout, 8> setLayouts = {
 | 
			
		||||
		std::array<VkDescriptorSetLayout, 7> setLayouts = {
 | 
			
		||||
			descriptorSetLayouts.matrices,
 | 
			
		||||
			descriptorSetLayouts.jointMatrices,
 | 
			
		||||
			//descriptorSetLayouts.jointMatrices,
 | 
			
		||||
			descriptorSetLayouts.textures,
 | 
			
		||||
			descriptorSetLayouts.textures,
 | 
			
		||||
			descriptorSetLayouts.textures,
 | 
			
		||||
| 
						 | 
				
			
			@ -1127,14 +1124,14 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
			vks::initializers::vertexInputBindingDescription(0, sizeof(VulkanglTFModel::Vertex), VK_VERTEX_INPUT_RATE_VERTEX),
 | 
			
		||||
		};
 | 
			
		||||
		const std::vector<VkVertexInputAttributeDescription> vertexInputAttributes = {
 | 
			
		||||
		{0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, pos)},
 | 
			
		||||
		{1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, normal)},
 | 
			
		||||
		{2, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, uv)},
 | 
			
		||||
		{3, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, color)},
 | 
			
		||||
		{4, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, tangent)},
 | 
			
		||||
			vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, pos)),	// Location 0: Position
 | 
			
		||||
			vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, normal)),// Location 1: Normal
 | 
			
		||||
			vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, uv)),	// Location 2: Texture coordinates
 | 
			
		||||
			vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, color)),	// Location 3: Color
 | 
			
		||||
			vks::initializers::vertexInputAttributeDescription(0, 4, VK_FORMAT_R32G32B32_SFLOAT, offsetof(VulkanglTFModel::Vertex, tangent)), // Location 4 : Tangent
 | 
			
		||||
		// POI: Per-Vertex Joint indices and weights are passed to the vertex shader
 | 
			
		||||
		{5, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(VulkanglTFModel::Vertex, jointIndices)},
 | 
			
		||||
		{6, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(VulkanglTFModel::Vertex, jointWeights)},
 | 
			
		||||
		//{5, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(VulkanglTFModel::Vertex, jointIndices)},
 | 
			
		||||
		//{6, 0, VK_FORMAT_R32G32B32A32_SFLOAT, offsetof(VulkanglTFModel::Vertex, jointWeights)},
 | 
			
		||||
		};
 | 
			
		||||
		VkPipelineVertexInputStateCreateInfo vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo();
 | 
			
		||||
		vertexInputStateCI.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexInputBindings.size());
 | 
			
		||||
| 
						 | 
				
			
			@ -1147,7 +1144,7 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
			loadShader(getHomeworkShadersPath() + "homework1/mesh.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT)
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0);
 | 
			
		||||
		VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayouts.pbrLayout, pbrFrameBuffer.fbo.renderPass, 0);
 | 
			
		||||
		pipelineCI.pVertexInputState = &vertexInputStateCI;
 | 
			
		||||
		pipelineCI.pInputAssemblyState = &inputAssemblyStateCI;
 | 
			
		||||
		pipelineCI.pRasterizationState = &rasterizationStateCI;
 | 
			
		||||
| 
						 | 
				
			
			@ -1168,7 +1165,9 @@ void VulkanExample::getEnabledFeatures()
 | 
			
		|||
			rasterizationStateCI.lineWidth = 1.0f;
 | 
			
		||||
			VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.wireframe));
 | 
			
		||||
		}
 | 
			
		||||
		prepareToneMappingPipeline();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void VulkanExample::prepareToneMappingPipeline()
 | 
			
		||||
	{
 | 
			
		||||
		if (pipelines.toneMapping != VK_NULL_HANDLE)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue