Changeset b8efa56 in opengl-game
- Timestamp:
- Apr 10, 2021, 1:46:51 AM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 4a777d2
- Parents:
- 8d92284
- git-author:
- Dmitry Portnoy <dportnoy@…> (04/10/21 01:46:46)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (04/10/21 01:46:51)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/asteroid.frag
r8d92284 rb8efa56 4 4 layout(location = 0) in vec3 position_eye; 5 5 layout(location = 1) in vec3 color; 6 layout(location = 2) in vec3 normal_eye; 7 layout(location = 3) in vec3 light_position_eye; 8 layout(location = 4) in vec3 light2_position_eye; 6 layout(location = 2) in vec2 fragTexCoord; 7 layout(location = 3) in vec3 normal_eye; 8 layout(location = 4) in vec3 light_position_eye; 9 layout(location = 5) in vec3 light2_position_eye; 9 10 10 11 layout(location = 0) out vec4 frag_color; … … 52 53 // specular intensity 53 54 vec3 Is = Ls * Ks * specular_factor; 54 vec3 Is2 = Ls * Ks * specular_factor2 ;55 vec3 Is2 = Ls * Ks * specular_factor2 + vec3(fragTexCoord, 0.0) - vec3(fragTexCoord, 0.0); 55 56 56 57 frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0); -
shaders/asteroid.vert
r8d92284 rb8efa56 19 19 layout(location = 0) in vec3 vertex_position; 20 20 layout(location = 1) in vec3 vertex_color; 21 layout(location = 2) in vec3 vertex_normal; 22 layout(location = 3) in uint obj_index; 21 layout(location = 2) in vec2 inTexCoord; 22 layout(location = 3) in vec3 vertex_normal; 23 layout(location = 4) in uint obj_index; 23 24 24 25 layout(location = 0) out vec3 position_eye; 25 26 layout(location = 1) out vec3 color; 26 layout(location = 2) out vec3 normal_eye; 27 layout(location = 3) out vec3 light_position_eye; 28 layout(location = 4) out vec3 light2_position_eye; 27 layout(location = 2) out vec2 fragTexCoord; 28 layout(location = 3) out vec3 normal_eye; 29 layout(location = 4) out vec3 light_position_eye; 30 layout(location = 5) out vec3 light2_position_eye; 29 31 30 32 // fixed point light position … … 40 42 color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent)); 41 43 44 fragTexCoord = inTexCoord; 45 42 46 light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0)); 43 47 light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0)); -
vulkan-game.cpp
r8d92284 rb8efa56 11 11 12 12 #include "logger.hpp" 13 #include "utils.hpp"14 13 15 14 #include "gui/imgui/button-imgui.hpp" … … 433 432 shipPipeline.createDescriptorSets(swapChainImages); 434 433 435 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::pos)); 436 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::color)); 437 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::normal)); 438 asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&AsteroidVertex::objIndex)); 434 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos)); 435 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color)); 436 asteroidPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord)); 437 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::normal)); 438 asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 439 439 440 440 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, … … 590 590 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138, 10); 591 591 592 asteroidPipeline = GraphicsPipeline_Vulkan< AsteroidVertex, SSBO_Asteroid>(592 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_Asteroid>( 593 593 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 594 594 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36, 10); … … 898 898 } 899 899 900 for (SceneObject< AsteroidVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) {900 for (SceneObject<ModelVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) { 901 901 if (!asteroid.ssbo.deleted) { 902 902 vec3 objCenter = vec3(viewMat * vec4(asteroid.center, 1.0f)); … … 929 929 this->lastSpawn_asteroid = curTime; 930 930 931 SceneObject< AsteroidVertex, SSBO_Asteroid>& asteroid = addObject(932 a steroidObjects, asteroidPipeline,933 addObjectIndex<AsteroidVertex>(asteroidObjects.size(),934 addVertexNormals<AsteroidVertex>({935 936 // front937 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},938 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},939 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},940 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},941 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},942 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},943 944 // top945 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},946 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},947 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},948 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},949 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},950 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},951 952 // bottom953 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},954 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},955 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},956 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},957 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},958 {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}},959 960 // back961 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},962 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},963 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},964 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},965 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},966 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},967 968 // right969 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},970 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},971 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},972 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},973 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},974 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},975 976 // left977 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},978 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},979 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},980 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},981 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},982 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}},983 })), {984 0, 1, 2, 3, 4, 5,985 6, 7, 8, 9, 10, 11,986 12, 13, 14, 15, 16, 17,987 18, 19, 20, 21, 22, 23,988 24, 25, 26, 27, 28, 29,989 30, 31, 32, 33, 34, 35,990 }, {991 mat4(1.0f),992 10.0f,993 false994 }, true);931 SceneObject<ModelVertex, SSBO_Asteroid>& asteroid = 932 addObject(asteroidObjects, asteroidPipeline, 933 addObjectIndex<ModelVertex>(asteroidObjects.size(), 934 addVertexNormals<ModelVertex>({ 935 936 // front 937 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 938 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 939 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 940 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 941 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 942 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 943 944 // top 945 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 946 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 947 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 948 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 949 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 950 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 951 952 // bottom 953 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 954 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 955 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 956 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 957 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 958 {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}}, 959 960 // back 961 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 962 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 963 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 964 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 965 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 966 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 967 968 // right 969 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 970 {{ 1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 971 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 972 {{ 1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 973 {{ 1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 974 {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 975 976 // left 977 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 978 {{-1.0f, 1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 979 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 980 {{-1.0f, 1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 981 {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}}, 982 {{-1.0f, -1.0f, 1.0f}, {0.4f, 0.4f, 0.4f}}, 983 })), { 984 0, 1, 2, 3, 4, 5, 985 6, 7, 8, 9, 10, 11, 986 12, 13, 14, 15, 16, 17, 987 18, 19, 20, 21, 22, 23, 988 24, 25, 26, 27, 28, 29, 989 30, 31, 32, 33, 34, 35, 990 }, { 991 mat4(1.0f), 992 10.0f, 993 false 994 }, true); 995 995 996 996 // This accounts for the scaling in model_base. … … 1070 1070 1071 1071 VulkanUtils::destroyVulkanImage(device, floorTextureImage); 1072 // START UNREVIEWED SECTION 1072 1073 VulkanUtils::destroyVulkanImage(device, laserTextureImage); 1073 1074 … … 1079 1080 laserPipeline.cleanupBuffers(); 1080 1081 explosionPipeline.cleanupBuffers(); 1082 1083 // END UNREVIEWED SECTION 1081 1084 1082 1085 vkDestroyCommandPool(device, resourceCommandPool, nullptr); … … 1908 1911 1909 1912 vec3 intersection(0.0f), closestIntersection(0.0f); 1910 SceneObject< AsteroidVertex, SSBO_Asteroid>* closestAsteroid = nullptr;1913 SceneObject<ModelVertex, SSBO_Asteroid>* closestAsteroid = nullptr; 1911 1914 unsigned int closestAsteroidIndex = -1; 1912 1915 … … 1937 1940 } 1938 1941 1939 EffectOverTime< AsteroidVertex, SSBO_Asteroid>* eot = nullptr;1942 EffectOverTime<ModelVertex, SSBO_Asteroid>* eot = nullptr; 1940 1943 1941 1944 if (closestAsteroid != nullptr) { 1942 1945 // TODO: Use some sort of smart pointer instead 1943 eot = new EffectOverTime< AsteroidVertex, SSBO_Asteroid>(asteroidPipeline, asteroidObjects, closestAsteroidIndex,1946 eot = new EffectOverTime<ModelVertex, SSBO_Asteroid>(asteroidPipeline, asteroidObjects, closestAsteroidIndex, 1944 1947 offset_of(&SSBO_Asteroid::hp), curTime, -20.0f); 1945 1948 effects.push_back(eot); … … 1969 1972 // TODO: Determine if I should pass start and end by reference or value since they don't get changed 1970 1973 // Probably use const reference 1971 bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject< AsteroidVertex, SSBO_Asteroid>& asteroid,1974 bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject<ModelVertex, SSBO_Asteroid>& asteroid, 1972 1975 vec3& start, vec3& end, vec3& intersection) { 1973 1976 /* -
vulkan-game.hpp
r8d92284 rb8efa56 22 22 23 23 #include "consts.hpp" 24 #include "vulkan-utils.hpp"25 24 #include "graphics-pipeline_vulkan.hpp" 26 25 #include "game-gui-sdl.hpp" 26 #include "utils.hpp" 27 #include "vulkan-utils.hpp" 27 28 28 29 using namespace glm; … … 47 48 vec3 color; 48 49 vec2 texCoord; 49 vec3 normal;50 unsigned int objIndex;51 };52 53 struct AsteroidVertex {54 vec3 pos;55 vec3 color;56 50 vec3 normal; 57 51 unsigned int objIndex; … … 122 116 vec3 center; // currently only matters for asteroids 123 117 float radius; // currently only matters for asteroids 124 SceneObject< AsteroidVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers118 SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers 125 119 }; 126 120 … … 303 297 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline; 304 298 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> shipPipeline; 305 GraphicsPipeline_Vulkan< AsteroidVertex, SSBO_Asteroid> asteroidPipeline;299 GraphicsPipeline_Vulkan<ModelVertex, SSBO_Asteroid> asteroidPipeline; 306 300 GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline; 307 301 GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline; … … 331 325 UBO_VP_mats ship_VP_mats; 332 326 333 vector<SceneObject< AsteroidVertex, SSBO_Asteroid>> asteroidObjects;327 vector<SceneObject<ModelVertex, SSBO_Asteroid>> asteroidObjects; 334 328 335 329 vector<VkBuffer> uniformBuffers_asteroidPipeline; … … 364 358 365 359 unsigned int leftLaserIdx = -1; 366 EffectOverTime< AsteroidVertex, SSBO_Asteroid>* leftLaserEffect = nullptr;360 EffectOverTime<ModelVertex, SSBO_Asteroid>* leftLaserEffect = nullptr; 367 361 368 362 unsigned int rightLaserIdx = -1; 369 EffectOverTime< AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr;363 EffectOverTime<ModelVertex, SSBO_Asteroid>* rightLaserEffect = nullptr; 370 364 371 365 /*** High-level vars ***/ … … 453 447 void translateLaser(size_t index, const vec3& translation); 454 448 void updateLaserTarget(size_t index); 455 bool getLaserAndAsteroidIntersection(SceneObject< AsteroidVertex, SSBO_Asteroid>& asteroid,449 bool getLaserAndAsteroidIntersection(SceneObject<ModelVertex, SSBO_Asteroid>& asteroid, 456 450 vec3& start, vec3& end, vec3& intersection); 457 451
Note:
See TracChangeset
for help on using the changeset viewer.