Changeset a00eb06 in opengl-game
- Timestamp:
- Apr 10, 2021, 12:58:17 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 8d92284
- Parents:
- 914bb99
- git-author:
- Dmitry Portnoy <dportnoy@…> (04/10/21 00:49:42)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (04/10/21 00:58:17)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/model.frag
r914bb99 ra00eb06 6 6 layout(location = 0) in vec3 fragColor; 7 7 layout(location = 1) in vec2 fragTexCoord; 8 layout(location = 2) in vec3 normal_eye; 8 9 9 10 layout(location = 0) out vec4 outColor; 10 11 11 12 void main() { 12 outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb, 1.0) ;13 outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb, 1.0) + vec4(normal_eye, 0.0) - vec4(normal_eye, 0.0); 13 14 } -
shaders/model.vert
r914bb99 ra00eb06 15 15 } sbo; 16 16 17 layout (binding = 2) uniform UboInstance { 18 mat4 model; 19 } uboInstance; 20 17 21 layout(location = 0) in vec3 inPosition; 18 22 layout(location = 1) in vec3 inColor; 19 23 layout(location = 2) in vec2 inTexCoord; 20 layout(location = 3) in uint obj_index; 24 layout(location = 3) in vec3 vertex_normal; 25 layout(location = 4) in uint obj_index; 21 26 22 27 layout(location = 0) out vec3 fragColor; 23 28 layout(location = 1) out vec2 fragTexCoord; 29 layout(location = 2) out vec3 normal_eye; 24 30 25 31 void main() { 32 // Using 0.0 instead of 1.0 means translations won't effect the normal 33 normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0))); 34 26 35 fragColor = inColor; 27 36 fragTexCoord = inTexCoord; -
vulkan-game.cpp
r914bb99 ra00eb06 117 117 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color)); 118 118 modelPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&ModelVertex::texCoord)); 119 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::normal)); 119 120 modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 120 121 … … 131 132 132 133 texturedSquare = &addObject(modelObjects, modelPipeline, 133 addObjectIndex<ModelVertex>(modelObjects.size(), { 134 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 135 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 136 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 137 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 138 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 139 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 140 }), { 141 0, 1, 2, 3, 4, 5 142 }, { 143 mat4(1.0f) 144 }, false); 134 addObjectIndex<ModelVertex>(modelObjects.size(), 135 addVertexNormals<ModelVertex>({ 136 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 137 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 138 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 139 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 140 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 141 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 142 })), { 143 0, 1, 2, 3, 4, 5 144 }, { 145 mat4(1.0f) 146 }, false); 145 147 146 148 texturedSquare->model_base = … … 149 151 150 152 texturedSquare = &addObject(modelObjects, modelPipeline, 151 addObjectIndex<ModelVertex>(modelObjects.size(), { 152 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 153 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 154 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 155 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 156 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 157 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 158 }), { 159 0, 1, 2, 3, 4, 5 160 }, { 161 mat4(1.0f) 162 }, false); 153 addObjectIndex<ModelVertex>(modelObjects.size(), 154 addVertexNormals<ModelVertex>({ 155 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 156 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 157 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 158 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 159 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 160 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 161 })), { 162 0, 1, 2, 3, 4, 5 163 }, { 164 mat4(1.0f) 165 }, false); 163 166 164 167 texturedSquare->model_base = … … 534 537 } 535 538 536 window = (SDL_Window*) 539 window = (SDL_Window*)gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN); 537 540 if (window == nullptr) { 538 541 cout << "Window could not be created!" << endl; … … 703 706 SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare = 704 707 addObject(modelObjects, modelPipeline, 705 addObjectIndex<ModelVertex>(modelObjects.size(), { 706 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 707 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 708 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 709 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 710 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 711 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 712 }), { 713 0, 1, 2, 3, 4, 5 714 }, { 715 mat4(1.0f) 716 }, true); 708 addObjectIndex<ModelVertex>(modelObjects.size(), 709 addVertexNormals<ModelVertex>({ 710 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 711 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 712 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 713 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 714 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 715 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 716 })), { 717 0, 1, 2, 3, 4, 5 718 }, { 719 mat4(1.0f) 720 }, true); 717 721 718 722 texturedSquare.model_base = -
vulkan-game.hpp
r914bb99 ra00eb06 47 47 vec3 color; 48 48 vec2 texCoord; 49 vec3 normal; 49 50 unsigned int objIndex; 50 51 };
Note:
See TracChangeset
for help on using the changeset viewer.