Commit 6a32b809 authored by Florian Oetke's avatar Florian Oetke
Browse files

hopefully the largest commit I will ever push: complete project structure...

hopefully the largest commit I will ever push: complete project structure refactoring and mesh converter (kind of couldn't implement one without the other)
parent 07edb0e8
......@@ -37,6 +37,7 @@ CMakeLists.txt.user
assets/*.log
assets/assets_ext
assets/extensions
assets/ImageTool.jar
......
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
project(mirrage LANGUAGES C CXX)
if(WIN32)
SET(PHYSFS_INTERNAL_ZLIB TRUE)
SET(PHYSFS_ARCHIVE_7Z FALSE)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
set(BUILD_SHARED_LIBS OFF)
set(ASSIMP_BUILD_ASSIMP_TOOLS OFF)
set(ASSIMP_BUILD_TESTS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# required at top-level
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024 -fno-strict-aliasing")
set(ROOT_DIR ${CMAKE_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROOT_DIR}/modules")
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
option(USE_LIBCPP "Uses libc++ instead of libstdc++. " ON)
if(USE_LIBCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -ftemplate-depth=1024 -fno-strict-aliasing")
include_directories(BEFORE "${ROOT_DIR}/dependencies")
include_directories(BEFORE "${ROOT_DIR}/dependencies/gsl/include")
include_directories(BEFORE "${ROOT_DIR}/dependencies/sf2/include")
include_directories(BEFORE "${ROOT_DIR}/dependencies/range-v3/include")
include_directories(BEFORE "${ROOT_DIR}/dependencies/sdl_vulkan/include")
include_directories(BEFORE "${ROOT_DIR}/dependencies/glm")
include_directories(BEFORE "${ROOT_DIR}/dependencies/stb_image")
include_directories(BEFORE SYSTEM "${ROOT_DIR}/dependencies/assimp")
include_directories(BEFORE SYSTEM "${ROOT_DIR}/dependencies/nuklear")
add_definitions(-DGLM_FORCE_RADIANS)
add_definitions(-DGLM_FORCE_DEPTH_ZERO_TO_ONE)
add_definitions(-DENABLE_SF2_ASSETS)
add_definitions(-DSTACKTRACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-pie")
add_subdirectory(dependencies/physfs)
add_subdirectory(dependencies/stb_image)
add_subdirectory(dependencies/sf2)
add_subdirectory(dependencies/sdl_vulkan)
add_subdirectory(dependencies/assimp)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -pedantic -Werror -Wno-unused-parameter -Wno-unused-private-field -Wno-missing-braces")
add_subdirectory(dependencies)
add_subdirectory(src)
# custom target that does nothing but references all files so they show up in QtCreator
file(GLOB_RECURSE ALL_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/*.*)
add_custom_target(all_project_files SOURCES ${ALL_FILES})
assets
assets_ext
extensions/*
tex: = textures/
tex:black = textures/default_black.png
tex:white = textures/default_white.png
tex:white = textures/default_white.ktx
tex:normal = textures/default_normal.png
tex:placeholder = textures/default_placeholder.png
tex:placeholder = textures/default_placeholder.ktx
tex:x_font = textures/x.template_regular_48.tga
tex:satisfy_font = textures/satisfy_regular_20.tga
......
......@@ -2,6 +2,6 @@
"Transform":{
},
"Model": {
"aid": "model:cube.obj"
"aid": "model:cube"
}
}
......@@ -2,7 +2,7 @@
"Transform":{
},
"Model": {
"aid": "model:sponza.obj"
"aid": "model:sponza.mmf"
},
"Shadowcaster": {}
}
{
"substance_id": "emissive",
"albedo_aid": "default_white.ktx"
}
......@@ -46,5 +46,8 @@ void main() {
out_color = vec4(textureLod(mat_data_sampler, vertex_out.tex_coords, pcs.prev_projection[2][3]).rgb, 1.0);
}
out_color = vec4(decode_normal(textureLod(mat_data_sampler, vertex_out.tex_coords, 0).rg), 1.0);
out_color = vec4(textureLod(albedo_sampler, vertex_out.tex_coords, 0).rgb, 1.0);
// out_color = vec4(texture(ao_sampler, vertex_out.tex_coords).rrr, 1.0);
}
......@@ -13,13 +13,11 @@ layout(location = 0) in Vertex_data {
} vertex_out;
layout(location = 0) out vec4 depth_out;
layout(location = 1) out vec4 albedo_mat_id;
layout(location = 2) out vec4 mat_data;
layout(location = 1) out vec4 albedo_mat_id_out;
layout(location = 2) out vec4 mat_data_out;
layout(set=1, binding = 0) uniform sampler2D albedo_sampler;
layout(set=1, binding = 1) uniform sampler2D metallic_sampler;
layout(set=1, binding = 2) uniform sampler2D normal_sampler;
layout(set=1, binding = 3) uniform sampler2D roughness_sampler;
layout(set=1, binding = 1) uniform sampler2D mat_data_sampler;
layout(push_constant) uniform Per_model_uniforms {
mat4 model;
......@@ -30,30 +28,43 @@ layout(push_constant) uniform Per_model_uniforms {
const float PI = 3.14159265359;
vec3 decode_tangent_normal(vec2 tn);
vec3 tangent_space_to_world(vec3 N);
void main() {
vec4 albedo = texture(albedo_sampler, vertex_out.tex_coords);
vec4 albedo = textureLod(albedo_sampler, vertex_out.tex_coords, 3);
if(albedo.a < 0.5)
discard;
// if(albedo.a < 0.1)
// discard;
vec4 mat_data = texture(mat_data_sampler, vertex_out.tex_coords); // TODO: LOD bias?
float metallic = texture(metallic_sampler, vertex_out.tex_coords).r;
float roughness = texture(roughness_sampler, vertex_out.tex_coords).r;
vec3 normal = tangent_space_to_world(texture(normal_sampler, vertex_out.tex_coords, -0.5).xyz);
normal.z = abs(normal.z);
vec3 normal = tangent_space_to_world(decode_tangent_normal(mat_data.rg));
//normal.z = abs(normal.z); // TODO: remove?
float roughness = mat_data.b;
float metallic = mat_data.a;
roughness = mix(0.05, 0.99, roughness*roughness);
depth_out = vec4(-vertex_out.view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id = vec4(albedo.rgb, 0.0);
mat_data = vec4(encode_normal(normal), roughness, metallic);
depth_out = vec4(-vertex_out.view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id_out = vec4(albedo.rgb, 0.0);
mat_data_out = vec4(encode_normal(normal), roughness, metallic);
float disect = model_uniforms.options.x;
if(disect>0 && vertex_out.world_pos.z>=disect)
discard;
}
vec3 decode_tangent_normal(vec2 tn) {
if(dot(tn,tn)<0.00001)
return vec3(0,0,1);
vec3 N = vec3(tn*2-1, 0);
N.z = sqrt(1 - dot(N.xy, N.xy));
return N;
}
vec3 tangent_space_to_world(vec3 N) {
vec3 VN = normalize(vertex_out.normal);
......@@ -63,17 +74,28 @@ vec3 tangent_space_to_world(vec3 N) {
vec2 tc_dx = dFdx(vertex_out.tex_coords);
vec2 tc_dy = dFdy(vertex_out.tex_coords);
// TODO: check alternativ
vec3 p_dy_N = cross(p_dy, VN);
vec3 p_dx_N = cross(VN, p_dx);
vec3 T = p_dy_N * tc_dx.x + p_dx_N * tc_dy.x;
vec3 B = p_dy_N * tc_dx.y + p_dx_N * tc_dy.y;
float inv_max = inversesqrt(max(dot(T,T), dot(B,B)));
mat3 TBN = mat3(T*inv_max, B*inv_max, VN);
return normalize(TBN * N);
/*
vec3 VT = normalize( tc_dy.y * p_dx - tc_dx.y * p_dy );
VT = normalize(VT - dot(VT, VN) * VN);
vec3 VB = cross(VT, VN);
mat3 TBN = mat3(VT, VB, VN);
if(length(N)<0.00001)
N = vec3(0,0,1);
else {
N = normalize(N*2.0 - 1.0);
}
return normalize(TBN * N);
return normalize(TBN * N);*/
}
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
execute_process(COMMAND git submodule update --init --recursive --remote
WORKING_DIRECTORY ${ROOT_DIR})
find_package(assimp 3.3.1)
if(NOT assimp_FOUND)
add_subdirectory(assimp)
endif()
add_subdirectory(gli)
add_subdirectory(glm)
include(gsl_interface.cmake)
add_subdirectory(moodycamel)
include(nuklear_interface.cmake)
SET(PHYSFS_INTERNAL_ZLIB TRUE)
SET(PHYSFS_ARCHIVE_7Z FALSE)
SET(PHYSFS_BUILD_SHARED FALSE)
add_subdirectory(physfs)
include(range-v3_interface.cmake)
add_subdirectory(sdl_vulkan)
add_subdirectory(sf2)
add_subdirectory(stb_image)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(gsl)
add_library(gsl INTERFACE)
target_include_directories(gsl INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gsl/include>
$<INSTALL_INTERFACE:include>)
install(TARGETS gsl EXPORT gslTargets)
export(
EXPORT gslTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/gslTargets.cmake"
)
install(
EXPORT gslTargets FILE gslTargets.cmake
NAMESPACE gsl::
DESTINATION lib/cmake
)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(moodycamel LANGUAGES CXX)
add_library(moodycamel INTERFACE)
target_include_directories(moodycamel INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
install(TARGETS moodycamel EXPORT moodycamel_targets INCLUDES DESTINATION include)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h*")
install(EXPORT moodycamel_targets
FILE moodycamel.cmake
NAMESPACE moodycamel::
DESTINATION lib/cmake
)
This diff is collapsed.
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(nuklear)
add_library(nuklear INTERFACE)
target_include_directories(nuklear INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/nuklear>
$<INSTALL_INTERFACE:include>
)
install(TARGETS nuklear EXPORT nuklearTargets)
export(
EXPORT nuklearTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/nuklearTargets.cmake"
)
install(
EXPORT nuklearTargets FILE nuklearTargets.cmake
NAMESPACE nuklear::
DESTINATION lib/cmake
)
......@@ -298,12 +298,20 @@ IF(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
SET_TARGET_PROPERTIES(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
INSTALL(TARGETS ${PHYSFS_INSTALL_TARGETS}
target_include_directories(physfs-static INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
set_target_properties(physfs-static PROPERTIES PUBLIC_HEADER "physfs.h")
INSTALL(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT physfs-static
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX})
INSTALL(FILES physfs.h DESTINATION include)
INSTALL(EXPORT physfs-static
FILE physfs-static.cmake
DESTINATION lib/cmake
)
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment