Changeset b8efa56 in opengl-game


Ignore:
Timestamp:
Apr 10, 2021, 1:46:51 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
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)
Message:

In VulkanGame, change the asteroid pipeline to use ModelVertex

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • shaders/asteroid.frag

    r8d92284 rb8efa56  
    44layout(location = 0) in vec3 position_eye;
    55layout(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;
     6layout(location = 2) in vec2 fragTexCoord;
     7layout(location = 3) in vec3 normal_eye;
     8layout(location = 4) in vec3 light_position_eye;
     9layout(location = 5) in vec3 light2_position_eye;
    910
    1011layout(location = 0) out vec4 frag_color;
     
    5253   // specular intensity
    5354   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);
    5556
    5657   frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0);
  • shaders/asteroid.vert

    r8d92284 rb8efa56  
    1919layout(location = 0) in vec3 vertex_position;
    2020layout(location = 1) in vec3 vertex_color;
    21 layout(location = 2) in vec3 vertex_normal;
    22 layout(location = 3) in uint obj_index;
     21layout(location = 2) in vec2 inTexCoord;
     22layout(location = 3) in vec3 vertex_normal;
     23layout(location = 4) in uint obj_index;
    2324
    2425layout(location = 0) out vec3 position_eye;
    2526layout(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;
     27layout(location = 2) out vec2 fragTexCoord;
     28layout(location = 3) out vec3 normal_eye;
     29layout(location = 4) out vec3 light_position_eye;
     30layout(location = 5) out vec3 light2_position_eye;
    2931
    3032// fixed point light position
     
    4042   color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent));
    4143
     44   fragTexCoord = inTexCoord;
     45
    4246   light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
    4347   light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0));
  • vulkan-game.cpp

    r8d92284 rb8efa56  
    1111
    1212#include "logger.hpp"
    13 #include "utils.hpp"
    1413
    1514#include "gui/imgui/button-imgui.hpp"
     
    433432   shipPipeline.createDescriptorSets(swapChainImages);
    434433
    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));
    439439
    440440   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     
    590590      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138, 10);
    591591
    592    asteroidPipeline = GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid>(
     592   asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_Asteroid>(
    593593      VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass,
    594594      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36, 10);
     
    898898   }
    899899
    900    for (SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) {
     900   for (SceneObject<ModelVertex, SSBO_Asteroid>& asteroid : this->asteroidObjects) {
    901901      if (!asteroid.ssbo.deleted) {
    902902         vec3 objCenter = vec3(viewMat * vec4(asteroid.center, 1.0f));
     
    929929      this->lastSpawn_asteroid = curTime;
    930930
    931       SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid = addObject(
    932          asteroidObjects, asteroidPipeline,
    933          addObjectIndex<AsteroidVertex>(asteroidObjects.size(),
    934          addVertexNormals<AsteroidVertex>({
    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);
     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);
    995995
    996996      // This accounts for the scaling in model_base.
     
    10701070
    10711071   VulkanUtils::destroyVulkanImage(device, floorTextureImage);
     1072   // START UNREVIEWED SECTION
    10721073   VulkanUtils::destroyVulkanImage(device, laserTextureImage);
    10731074
     
    10791080   laserPipeline.cleanupBuffers();
    10801081   explosionPipeline.cleanupBuffers();
     1082
     1083   // END UNREVIEWED SECTION
    10811084
    10821085   vkDestroyCommandPool(device, resourceCommandPool, nullptr);
     
    19081911
    19091912   vec3 intersection(0.0f), closestIntersection(0.0f);
    1910    SceneObject<AsteroidVertex, SSBO_Asteroid>* closestAsteroid = nullptr;
     1913   SceneObject<ModelVertex, SSBO_Asteroid>* closestAsteroid = nullptr;
    19111914   unsigned int closestAsteroidIndex = -1;
    19121915
     
    19371940      }
    19381941
    1939       EffectOverTime<AsteroidVertex, SSBO_Asteroid>* eot = nullptr;
     1942      EffectOverTime<ModelVertex, SSBO_Asteroid>* eot = nullptr;
    19401943
    19411944      if (closestAsteroid != nullptr) {
    19421945         // 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,
    19441947            offset_of(&SSBO_Asteroid::hp), curTime, -20.0f);
    19451948         effects.push_back(eot);
     
    19691972// TODO: Determine if I should pass start and end by reference or value since they don't get changed
    19701973// Probably use const reference
    1971 bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid,
     1974bool VulkanGame::getLaserAndAsteroidIntersection(SceneObject<ModelVertex, SSBO_Asteroid>& asteroid,
    19721975      vec3& start, vec3& end, vec3& intersection) {
    19731976   /*
  • vulkan-game.hpp

    r8d92284 rb8efa56  
    2222
    2323#include "consts.hpp"
    24 #include "vulkan-utils.hpp"
    2524#include "graphics-pipeline_vulkan.hpp"
    2625#include "game-gui-sdl.hpp"
     26#include "utils.hpp"
     27#include "vulkan-utils.hpp"
    2728
    2829using namespace glm;
     
    4748   vec3 color;
    4849   vec2 texCoord;
    49    vec3 normal;
    50    unsigned int objIndex;
    51 };
    52 
    53 struct AsteroidVertex {
    54    vec3 pos;
    55    vec3 color;
    5650   vec3 normal;
    5751   unsigned int objIndex;
     
    122116   vec3 center; // currently only matters for asteroids
    123117   float radius; // currently only matters for asteroids
    124    SceneObject<AsteroidVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers
     118   SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers
    125119};
    126120
     
    303297      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
    304298      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> shipPipeline;
    305       GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
     299      GraphicsPipeline_Vulkan<ModelVertex, SSBO_Asteroid> asteroidPipeline;
    306300      GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
    307301      GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion> explosionPipeline;
     
    331325      UBO_VP_mats ship_VP_mats;
    332326
    333       vector<SceneObject<AsteroidVertex, SSBO_Asteroid>> asteroidObjects;
     327      vector<SceneObject<ModelVertex, SSBO_Asteroid>> asteroidObjects;
    334328
    335329      vector<VkBuffer> uniformBuffers_asteroidPipeline;
     
    364358
    365359      unsigned int leftLaserIdx = -1;
    366       EffectOverTime<AsteroidVertex, SSBO_Asteroid>* leftLaserEffect = nullptr;
     360      EffectOverTime<ModelVertex, SSBO_Asteroid>* leftLaserEffect = nullptr;
    367361
    368362      unsigned int rightLaserIdx = -1;
    369       EffectOverTime<AsteroidVertex, SSBO_Asteroid>* rightLaserEffect = nullptr;
     363      EffectOverTime<ModelVertex, SSBO_Asteroid>* rightLaserEffect = nullptr;
    370364
    371365      /*** High-level vars ***/
     
    453447      void translateLaser(size_t index, const vec3& translation);
    454448      void updateLaserTarget(size_t index);
    455       bool getLaserAndAsteroidIntersection(SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid,
     449      bool getLaserAndAsteroidIntersection(SceneObject<ModelVertex, SSBO_Asteroid>& asteroid,
    456450            vec3& start, vec3& end, vec3& intersection);
    457451
Note: See TracChangeset for help on using the changeset viewer.