mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
do stuiff
This commit is contained in:
parent
544fc78416
commit
52009da6fa
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -22,6 +22,3 @@
|
||||
[submodule "dependencies/VulkanMemoryAllocator"]
|
||||
path = dependencies/VulkanMemoryAllocator
|
||||
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
|
||||
[submodule "dependencies/shaderc"]
|
||||
path = dependencies/shaderc
|
||||
url = https://github.com/google/shaderc
|
||||
|
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
# options
|
||||
option(ENGINE_BUILD_TEST "Compile the test program" ON)
|
||||
@ -147,6 +147,9 @@ endif()
|
||||
|
||||
if(ENGINE_BUILD_VULKAN)
|
||||
|
||||
include(FindVulkan)
|
||||
find_package(Vulkan COMPONENTS shaderc_combined)
|
||||
|
||||
# Volk
|
||||
set(VOLK_STATIC_DEFINES "")
|
||||
set(VOLK_PULL_IN_VULKAN ON)
|
||||
@ -158,6 +161,10 @@ if(ENGINE_BUILD_VULKAN)
|
||||
# Vulkan Memory Allocator
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE dependencies/VulkanMemoryAllocator/include)
|
||||
|
||||
# shaderc
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Vulkan::shaderc_combined)
|
||||
|
||||
endif()
|
||||
|
||||
# SDL2:
|
||||
|
1
dependencies/shaderc
vendored
1
dependencies/shaderc
vendored
@ -1 +0,0 @@
|
||||
Subproject commit dc9d28ae95594edaef725012acd9de15a7342048
|
@ -30,6 +30,7 @@
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
namespace engine {
|
||||
|
||||
@ -153,7 +154,12 @@ namespace engine {
|
||||
shaderc::Compiler compiler;
|
||||
shaderc::CompileOptions options;
|
||||
|
||||
options.SetOptimizationLevel(shaderc_optimization_level_performance);
|
||||
options.SetSourceLanguage(shaderc_source_language_glsl);
|
||||
options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3);
|
||||
options.SetOptimizationLevel(shaderc_optimization_level_size);
|
||||
options.SetTargetSpirv(shaderc_spirv_version_1_6);
|
||||
options.SetAutoBindUniforms(false);
|
||||
options.SetInvertY(false);
|
||||
|
||||
// preprocess
|
||||
shaderc::PreprocessedSourceCompilationResult preprocessed = compiler.PreprocessGlsl(source, kind, filename, options);
|
||||
@ -163,10 +169,12 @@ namespace engine {
|
||||
throw std::runtime_error(preprocessed.GetErrorMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string shaderStr = { preprocessed.cbegin(), preprocessed.cend() };
|
||||
|
||||
// compile
|
||||
shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(shaderStr, kind, filename, options);
|
||||
shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(shaderStr.data(), kind, filename, options);
|
||||
|
||||
if (module.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
{
|
||||
@ -177,8 +185,8 @@ namespace engine {
|
||||
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = shaderBytecode.size();
|
||||
createInfo.pCode = shaderBytecode.data();
|
||||
createInfo.codeSize = shaderBytecode.size() * sizeof(uint32_t);
|
||||
createInfo.pCode = module.cbegin();
|
||||
|
||||
VkShaderModule shaderModule;
|
||||
if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
||||
@ -189,9 +197,9 @@ namespace engine {
|
||||
|
||||
}
|
||||
|
||||
static std::vector<char> readFile(const std::string& filename)
|
||||
static std::vector<char> readTextFile(const std::string& filename)
|
||||
{
|
||||
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
||||
std::ifstream file(filename, std::ios::ate);
|
||||
if (file.is_open() == false) {
|
||||
throw std::runtime_error("Unable to open file " + filename);
|
||||
}
|
||||
@ -463,7 +471,7 @@ namespace engine {
|
||||
|
||||
for (const auto& presMode : presentModes) {
|
||||
if (presMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
||||
// swapchain->presentMode = presMode; // this mode allows uncapped FPS while also avoiding screen tearing
|
||||
swapchain->presentMode = presMode; // this mode allows uncapped FPS while also avoiding screen tearing
|
||||
}
|
||||
}
|
||||
|
||||
@ -790,8 +798,6 @@ namespace engine {
|
||||
useValidation = true; // debug mode
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// get the both the engine and application versions
|
||||
int appVersionMajor = 0, appVersionMinor = 0, appVersionPatch = 0;
|
||||
assert(versionFromCharArray(appVersion, &appVersionMajor, &appVersionMinor, &appVersionPatch));
|
||||
@ -1368,6 +1374,13 @@ namespace engine {
|
||||
|
||||
gfx::Pipeline* pipeline = new gfx::Pipeline;
|
||||
|
||||
auto vertShaderCode = readTextFile(vertShaderPath);
|
||||
auto fragShaderCode = readTextFile(fragShaderPath);
|
||||
INFO("Opened shader: {}", std::filesystem::path(vertShaderPath).filename().string());
|
||||
|
||||
VkShaderModule vertShaderModule = compileShader(pimpl->device, shaderc_vertex_shader, vertShaderCode.data(), vertShaderPath);
|
||||
VkShaderModule fragShaderModule = compileShader(pimpl->device, shaderc_fragment_shader, fragShaderCode.data(), fragShaderPath);
|
||||
|
||||
// create uniform buffers
|
||||
pipeline->uniformBuffers.resize(FRAMES_IN_FLIGHT);
|
||||
for (int i = 0; i < FRAMES_IN_FLIGHT; i++) {
|
||||
@ -1448,13 +1461,6 @@ namespace engine {
|
||||
attribDescs.push_back(vulkanAttribDesc);
|
||||
}
|
||||
|
||||
auto vertShaderCode = readFile(vertShaderPath);
|
||||
auto fragShaderCode = readFile(fragShaderPath);
|
||||
INFO("Opened shader: {}", std::filesystem::path(vertShaderPath).filename().string());
|
||||
|
||||
VkShaderModule vertShaderModule = compileShader(pimpl->device, shaderc_vertex_shader, vertShaderCode.data(), vertShaderPath);
|
||||
VkShaderModule fragShaderModule = compileShader(pimpl->device, shaderc_fragment_shader, fragShaderCode.data(), fragShaderPath);
|
||||
|
||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO };
|
||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
vertShaderStageInfo.module = vertShaderModule;
|
||||
|
@ -291,7 +291,7 @@ namespace engine {
|
||||
|
||||
void Window::toggleFullscreen()
|
||||
{
|
||||
setFullscreen(!m_fullscreen);
|
||||
setFullscreen(!m_fullscreen, true);
|
||||
}
|
||||
|
||||
bool Window::isFullscreen() const
|
||||
|
@ -23,6 +23,9 @@ set(GAME_SOURCES
|
||||
|
||||
if (WIN32)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${GAME_SOURCES} "game.rc")
|
||||
|
||||
file(GLOB_RECURSE RES_FILES "${PROJECT_SOURCE_DIR}/res/*")
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/res" PREFIX "Resources" FILES ${RES_FILES})
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} ${GAME_SOURCES})
|
||||
endif()
|
||||
|
@ -8,13 +8,15 @@ layout(location = 4) in vec3 fragColor;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
float snoise(vec2 v);
|
||||
|
||||
void main() {
|
||||
|
||||
// constants
|
||||
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||
vec3 ambientColor = vec3(1.0, 1.0, 1.0);
|
||||
float ambientStrength = 0.1;
|
||||
vec3 baseColor = fragColor;
|
||||
vec3 baseColor = vec3(fragColor.x * snoise(fragUV * 10.0), fragColor.yz);
|
||||
vec3 emission = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
// code
|
||||
@ -34,3 +36,36 @@ void main() {
|
||||
vec3 lighting = min(diffuse + ambient + specular, 1.0);
|
||||
outColor = min( ( vec4(baseColor, 1.0) ) * vec4(lighting + emission, 1.0), vec4(1.0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Simplex 2D noise
|
||||
//
|
||||
vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
|
||||
|
||||
float snoise(vec2 v){
|
||||
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
|
||||
-0.577350269189626, 0.024390243902439);
|
||||
vec2 i = floor(v + dot(v, C.yy) );
|
||||
vec2 x0 = v - i + dot(i, C.xx);
|
||||
vec2 i1;
|
||||
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
||||
vec4 x12 = x0.xyxy + C.xxzz;
|
||||
x12.xy -= i1;
|
||||
i = mod(i, 289.0);
|
||||
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
|
||||
+ i.x + vec3(0.0, i1.x, 1.0 ));
|
||||
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),
|
||||
dot(x12.zw,x12.zw)), 0.0);
|
||||
m = m*m ;
|
||||
m = m*m ;
|
||||
vec3 x = 2.0 * fract(p * C.www) - 1.0;
|
||||
vec3 h = abs(x) - 0.5;
|
||||
vec3 ox = floor(x + 0.5);
|
||||
vec3 a0 = x - ox;
|
||||
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
|
||||
vec3 g;
|
||||
g.x = a0.x * x0.x + h.x * x0.y;
|
||||
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
|
||||
return 130.0 * dot(m, g);
|
||||
}
|
BIN
test/res/shader.frag.spv
Normal file
BIN
test/res/shader.frag.spv
Normal file
Binary file not shown.
BIN
test/res/shader.vert.spv
Normal file
BIN
test/res/shader.vert.spv
Normal file
Binary file not shown.
@ -20,9 +20,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
CRITICAL("{}", e.what());
|
||||
|
||||
#ifdef NDEBUG
|
||||
engine::Window::errorBox(e.what());
|
||||
#else
|
||||
#ifndef NDEBUG
|
||||
fputs(e.what(), stderr);
|
||||
fputc('\n', stderr);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user