Skip to content

Commit

Permalink
Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
LeandroSQ committed Feb 17, 2024
1 parent 07b84fc commit 11814dc
Show file tree
Hide file tree
Showing 53 changed files with 2,026 additions and 666 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"configurations": [
{
"name": "Debug (lldb)",
"preLaunchTask": "CMake: build",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
Expand All @@ -18,5 +19,6 @@
"console": "externalTerminal",
"MIMode": "lldb"
},

]
}
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
"__availability": "cpp"
},
"cSpell.words": [
"Cooldown",
"cpptrace",
"emscripten",
"Emscripten",
"EMSDK",
Expand All @@ -93,7 +95,9 @@
"SMPTE",
"substeps"
],
"cmake.configureOnOpen": false,
"cmake.configureOnOpen": true,
"cmake.buildBeforeRun": true,
"cmake.parseBuildDiagnostics": true,
"C_Cpp.intelliSenseEngine": "disabled",
"clangd.path": "/usr/bin/clangd",
"clangd.arguments": [
Expand Down
25 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake: launch current target",
"type": "shell",
"command": "${command:cmake.launchTargetPath}",
"args": [],
"group": "build",
"dependsOn": "CMake: build",
},
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"targets": [
"asteroids"
],
"preset": "${command:cmake.activeBuildPresetName}",
"group": "build",
"problemMatcher": [],
"detail": "CMake template build task"
}
]
}
57 changes: 54 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,34 @@ function(define_project_variables)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()

if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_C_STANDARD 11)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_STANDARD 23)

# Set colors for ninja
if(CMAKE_GENERATOR STREQUAL "Ninja")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
endif()

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
endif()
endif()

# For clang use -std=c++23
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23")

Expand Down Expand Up @@ -138,15 +158,46 @@ add_subdirectory(lib)
add_executable(${PROJECT_NAME} ${SOURCES})
define_target_properties(${PROJECT_NAME})

# region dSYM
if(APPLE)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND dsymutil $<TARGET_FILE:${PROJECT_NAME}>
)
endif()
# endregion

# # region Run assets.sh after build
# add_custom_command(
# TARGET ${PROJECT_NAME}
# PRE_BUILD
# COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/assets.sh
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# )
# # endregion

# region Format
file(GLOB_RECURSE FORMAT_SOURCES "src/core/*.cpp" "src/core/*.hpp")
add_custom_target(${PROJECT_NAME}_format
COMMAND clang-format -i ${FORMAT_SOURCES}
COMMENT "Running clang-format"
DEPENDS ${FORMAT_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# endregion

# region Linter
file(GLOB_RECURSE LINT_SOURCES "src/core/*.cpp" "src/core/*.hpp")
add_custom_target(${PROJECT_NAME}_lint
COMMAND clang-tidy ${LINT_SOURCES}
COMMENT "Running clang-tidy"
DEPENDS ${LINT_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)# endregion
# region Clean
)
# endregion

# endregion# region Clean
add_custom_target(${PROJECT_NAME}_clean
COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/clean.sh
COMMENT "Running clean.sh"
Expand Down
Binary file added assets/audio/explosion.wav
Binary file not shown.
Binary file added assets/audio/hit.wav
Binary file not shown.
Binary file added assets/audio/original/explosion.rfx
Binary file not shown.
29 changes: 29 additions & 0 deletions assets/audio/original/hit.sfxr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"oldParams": true,
"wave_type": 3,
"p_env_attack": 0,
"p_env_sustain": 0.3400512095246295,
"p_env_punch": 0.48519889379528036,
"p_env_decay": 0.3972516406875707,
"p_base_freq": 0.05054721600947243,
"p_freq_limit": 0,
"p_freq_ramp": -0.008087208760721859,
"p_freq_dramp": 0,
"p_vib_strength": 0,
"p_vib_speed": 0,
"p_arp_mod": 0,
"p_arp_speed": 0,
"p_duty": 0,
"p_duty_ramp": 0,
"p_repeat_speed": 0.5865777415692228,
"p_pha_offset": 0,
"p_pha_ramp": 0,
"p_lpf_freq": 1,
"p_lpf_ramp": 0,
"p_lpf_resonance": 0,
"p_hpf_freq": 0,
"p_hpf_ramp": 0,
"sound_vol": 0.25,
"sample_rate": 44100,
"sample_size": 16
}
29 changes: 29 additions & 0 deletions assets/audio/original/shoot.sfxr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"oldParams": true,
"wave_type": 0,
"p_env_attack": 0,
"p_env_sustain": 0.186,
"p_env_punch": 0.14416162357904438,
"p_env_decay": 0.359,
"p_base_freq": 0.515,
"p_freq_limit": 0.134,
"p_freq_ramp": -0.2619783169500224,
"p_freq_dramp": 0,
"p_vib_strength": 0.283,
"p_vib_speed": 1,
"p_arp_mod": -0.053,
"p_arp_speed": 0,
"p_duty": 0.718,
"p_duty_ramp": -0.158,
"p_repeat_speed": 0,
"p_pha_offset": 0.189,
"p_pha_ramp": -0.234,
"p_lpf_freq": 1,
"p_lpf_ramp": 0,
"p_lpf_resonance": 0,
"p_hpf_freq": 0.126,
"p_hpf_ramp": 0,
"sound_vol": 0.25,
"sample_rate": 44100,
"sample_size": 16
}
29 changes: 29 additions & 0 deletions assets/audio/original/shoot2.sfxr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"oldParams": true,
"wave_type": 1,
"p_env_attack": 0,
"p_env_sustain": 0.103,
"p_env_punch": 0.254,
"p_env_decay": 0.76,
"p_base_freq": 0.605,
"p_freq_limit": 0.185,
"p_freq_ramp": -0.285,
"p_freq_dramp": 0.06,
"p_vib_strength": 0.361,
"p_vib_speed": 0,
"p_arp_mod": -0.712,
"p_arp_speed": 0,
"p_duty": 0.26,
"p_duty_ramp": 0.647,
"p_repeat_speed": 0,
"p_pha_offset": -0.007,
"p_pha_ramp": -0.024,
"p_lpf_freq": 1,
"p_lpf_ramp": 0,
"p_lpf_resonance": 0,
"p_hpf_freq": 0.021623842742273,
"p_hpf_ramp": 0,
"sound_vol": 0.25,
"sample_rate": 44100,
"sample_size": 16
}
Binary file added assets/audio/original/spawn.rfx
Binary file not shown.
Binary file added assets/audio/shoot.wav
Binary file not shown.
Binary file added assets/audio/spawn.wav
Binary file not shown.
Binary file added assets/audio/thrust.wav
Binary file not shown.
Binary file added assets/audio/thrust2.wav
Binary file not shown.
114 changes: 114 additions & 0 deletions assets/shaders/all.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#version 330

precision mediump float;

in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 finalColor;
uniform sampler2D texture0;
uniform vec4 colDiffuse;

uniform float aberration;

#define USE_CHROMATIC_ABERRATION
#define USE_BLOOM
#define USE_GAMMA_CORRECTION
#define USE_SATURATION
#define USE_CONTRAST
#define USE_BRIGHTNESS
#define USE_PIXELATION

void applyPixelation(inout vec2 normalizedFragTexCoord) {
#ifdef USE_PIXELATION
float pixelation = 0.005;
float pixelationIntensity = pow(aberration, 1.0 / 2.0) * 0.5;

vec2 pixelatedFragTexCoord = floor(normalizedFragTexCoord / pixelation) * pixelation;
normalizedFragTexCoord = mix(normalizedFragTexCoord, pixelatedFragTexCoord, pixelationIntensity);
#endif
}

void applyChromaticAberration(inout vec4 texelColor, in vec2 normalizedFragTexCoord, in vec2 texelSize) {
#ifdef USE_CHROMATIC_ABERRATION
float edgeFactor = max(length(normalizedFragTexCoord - 0.5) * 2.0, 0.35);
float aberrationIntensity = edgeFactor * aberration * 1.5;
vec2 aberrationOffset = vec2(aberrationIntensity, -aberrationIntensity);
float red = texture(texture0, normalizedFragTexCoord + aberrationOffset * texelSize).r;
float green = texture(texture0, normalizedFragTexCoord).g;
float blue = texture(texture0, normalizedFragTexCoord - aberrationOffset * texelSize).b;
texelColor.rgb = vec3(red, green, blue);
#endif
}

void applyGammaCorrection(inout vec4 texelColor) {
#ifdef USE_GAMMA_CORRECTION
float gammmaCorrectionIntensity = 0.25;
texelColor.rgb = mix(texelColor.rgb, pow(texelColor.rgb, vec3(1.0 / 2.2)), gammmaCorrectionIntensity);
#endif
}

void applyBloom(inout vec4 texelColor, in vec2 normalizedFragTexCoord, in vec2 texelSize) {
#ifdef USE_BLOOM
float bloomIntensity = 0.95;
float bloomThreshold = 0.60;
int bloomRadius = 4;
vec4 bloomColor = vec4(0.0);
for (int i = -bloomRadius; i <= bloomRadius; i++) {
for (int j = -bloomRadius; j <= bloomRadius; j++) {
vec2 offset = vec2(i, j) * texelSize;
vec4 bloomTexelColor = texture(texture0, normalizedFragTexCoord + offset);
if (length(bloomTexelColor.rgb) > bloomThreshold) {
bloomColor += bloomTexelColor;
}
}
}
bloomColor /= float((bloomRadius * 2 + 1) * (bloomRadius * 2 + 1));
// Tint the bloom color
vec4 tint = vec4(1.0, 0.9, 0.7, 1.0);
bloomColor *= tint;

texelColor.rgb += bloomColor.rgb * bloomIntensity;
#endif
}

void applySaturation(inout vec4 texelColor) {
#ifdef USE_SATURATION
float saturation = 1.25;
float luminance = dot(texelColor.rgb, vec3(0.2126, 0.7152, 0.0722));
texelColor.rgb = mix(vec3(luminance), texelColor.rgb, saturation);
#endif
}

void applyContrast(inout vec4 texelColor) {
#ifdef USE_CONTRAST
float contrast = 0.98;
texelColor.rgb = (texelColor.rgb - 0.5) * pow(contrast, 2.0) + 0.5;
#endif
}

void applyBrightness(inout vec4 texelColor) {
#ifdef USE_BRIGHTNESS
float brightness = 1.05;
texelColor.rgb *= pow(brightness, 2.0);
#endif
}

void main() {
vec2 texelSize = 1.0 / textureSize(texture0, 0);
// Flip vertically to match OpenGL's texture coordinate system
vec2 normalizedFragTexCoord = vec2(fragTexCoord.x, 1.0 - fragTexCoord.y);

applyPixelation(normalizedFragTexCoord);

vec4 texelColor = texture(texture0, normalizedFragTexCoord);

applyChromaticAberration(texelColor, normalizedFragTexCoord, texelSize);
applyGammaCorrection(texelColor);
applyBloom(texelColor, normalizedFragTexCoord, texelSize);

applySaturation(texelColor);
applyContrast(texelColor);
applyBrightness(texelColor);

finalColor = texelColor * colDiffuse * fragColor;
}
35 changes: 35 additions & 0 deletions assets/shaders/background.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#version 330

precision mediump float;

in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 finalColor;
uniform sampler2D texture0;
uniform vec4 colDiffuse;

uniform vec2 resolution;

vec3 applyVignetteLinear(vec3 color) {
// Apply vignette
float radius = 0.95;
float softness = 0.9999;
float intensity = 0.6;
vec2 position = gl_FragCoord.xy / resolution.xy;

float vignette = smoothstep(radius, radius - softness, length(position - 0.5));
return mix(color, color * vignette, intensity);
}

void main() {
// DEBUG: Render gl_FragCoord gradient
// finalColor = vec4(gl_FragCoord.x / resolution.x, gl_FragCoord.y / resolution.y, 0.0, 1.0); return;

finalColor = vec4(0.0, 0.06, 0.1, 1.0);

// DEBUG: Apply gamma correction
// finalColor.rgb = pow(finalColor.rgb, vec3(1.0 / 2.2));

// Apply vignette
finalColor.rgb = applyVignetteLinear(finalColor.rgb);
}
Loading

0 comments on commit 11814dc

Please sign in to comment.