Changeset 8d92284 in opengl-game


Ignore:
Timestamp:
Apr 10, 2021, 1:31:20 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
b8efa56
Parents:
a00eb06
Message:

In VulkanGame, change the ship pipeline to use ModelVertex

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • shaders/ship.frag

    ra00eb06 r8d92284  
    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;
     
    5556
    5657   // specular intensity
    57    vec3 Is2 = Ls * Ks * specular_factor2;
     58   vec3 Is2 = Ls * Ks * specular_factor2 + vec3(fragTexCoord, 0.0) - vec3(fragTexCoord, 0.0);
    5859
    5960   frag_color = vec4((Is + Id + Ia + Is2 + Id2 + Ia2) / 2.0, 1.0);
  • shaders/ship.vert

    ra00eb06 r8d92284  
    1717layout(location = 0) in vec3 vertex_position;
    1818layout(location = 1) in vec3 vertex_color;
    19 layout(location = 2) in vec3 vertex_normal;
    20 layout(location = 3) in uint obj_index;
     19layout(location = 2) in vec2 inTexCoord;
     20layout(location = 3) in vec3 vertex_normal;
     21layout(location = 4) in uint obj_index;
    2122
    2223layout(location = 0) out vec3 position_eye;
    2324layout(location = 1) out vec3 color;
    24 layout(location = 2) out vec3 normal_eye;
    25 layout(location = 3) out vec3 light_position_eye;
    26 layout(location = 4) out vec3 light2_position_eye;
     25layout(location = 2) out vec2 fragTexCoord;
     26layout(location = 3) out vec3 normal_eye;
     27layout(location = 4) out vec3 light_position_eye;
     28layout(location = 5) out vec3 light2_position_eye;
    2729
    2830// fixed point light positions
     
    4042   color = vertex_color;
    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

    ra00eb06 r8d92284  
    174174   modelPipeline.createDescriptorSets(swapChainImages);
    175175
    176    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos));
    177    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color));
    178    shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::normal));
    179    shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ShipVertex::objIndex));
     176   // START UNREVIEWED SECTION
     177   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));
     178   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color));
     179   shipPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord));
     180   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::normal));
     181   shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    180182
    181183   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
     
    188190   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
    189191   // the same data. Add an option to make some pipelines not use indexing
    190    SceneObject<ShipVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,
    191       addObjectIndex<ShipVertex>(shipObjects.size(),
    192          addVertexNormals<ShipVertex>({
     192   SceneObject<ModelVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,
     193      addObjectIndex<ModelVertex>(shipObjects.size(),
     194         addVertexNormals<ModelVertex>({
    193195
    194196            //back
     
    482484   explosionPipeline.createDescriptorSets(swapChainImages);
    483485
     486   // END UNREVIEWED SECTION
     487
    484488   currentRenderScreenFn = &VulkanGame::renderMainScreen;
    485489
     
    582586      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 24, 10);
    583587
    584    shipPipeline = GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject>(
     588   shipPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject>(
    585589      VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass,
    586590      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138, 10);
     
    723727                     translate(mat4(1.0f), vec3(0.0f, 0.0f, zOffset));
    724728                  texturedSquare.modified = true;
     729               // START UNREVIEWED SECTION
    725730               } else if (e.key.keycode == SDL_SCANCODE_Z && leftLaserIdx == -1) {
    726731                  // TODO: When I start actually removing objects from the object vectors,
     
    745750
    746751                  rightLaserIdx = laserObjects.size() - 1;
     752               // END UNREVIEWED SECTION
    747753               } else {
    748754                  cout << "Key event detected" << endl;
     
    750756               break;
    751757            case UI_EVENT_KEYUP:
     758               // START UNREVIEWED SECTION
    752759               if (e.key.keycode == SDL_SCANCODE_Z && leftLaserIdx != -1) {
    753760                  laserObjects[leftLaserIdx].ssbo.deleted = true;
     
    769776                  }
    770777               }
     778               // END UNREVIEWED SECTION
    771779               break;
    772780            case UI_EVENT_WINDOW:
     
    792800      // Check which keys are held down
    793801
    794       SceneObject<ShipVertex, SSBO_ModelObject>& ship = shipObjects[0];
     802      SceneObject<ModelVertex, SSBO_ModelObject>& ship = shipObjects[0];
    795803
    796804      if (gui->keyPressed(SDL_SCANCODE_LEFT)) {
     
    836844            shouldRecreateSwapChain = false;
    837845         }
    838       }
     846      }// REVIEWED TO THIS POINT
    839847
    840848      updateScene();
  • vulkan-game.hpp

    ra00eb06 r8d92284  
    4747   vec3 color;
    4848   vec2 texCoord;
    49    vec3 normal;
    50    unsigned int objIndex;
    51 };
    52 
    53 struct ShipVertex {
    54    vec3 pos;
    55    vec3 color;
    5649   vec3 normal;
    5750   unsigned int objIndex;
     
    309302      // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures
    310303      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
    311       GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject> shipPipeline;
     304      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> shipPipeline;
    312305      GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid> asteroidPipeline;
    313306      GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser> laserPipeline;
     
    330323      UBO_VP_mats object_VP_mats;
    331324
    332       vector<SceneObject<ShipVertex, SSBO_ModelObject>> shipObjects;
     325      vector<SceneObject<ModelVertex, SSBO_ModelObject>> shipObjects;
    333326
    334327      vector<VkBuffer> uniformBuffers_shipPipeline;
Note: See TracChangeset for help on using the changeset viewer.