diff --git a/CMakeLists.txt b/CMakeLists.txt index 006f32a..2867228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ include(HandleLLVMOptions) if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/vendor/shaderc/CMakeLists.txt") set(SHADERC_SKIP_TESTS ON) + set(SHADERC_ENABLE_WERROR_COMPILE OFF) add_subdirectory(vendor/shaderc) else() diff --git a/README.md b/README.md index 77ae4ef..ee34bf5 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,15 @@ echo deb https://apt.llvm.org/bullseye llvm-toolchain-bullseye-14 main >/etc/apt apt install llvm-14-tools clang build-essential cmake git \ llvm-14-dev libboost-log-dev spirv-headers spirv-tools ``` + +Clone the source, then in the source dir: + +```shell +git submodule update --init vendor/shaderc +vendor/shaderc/utils/git-sync-deps +mkdir build +cd build +cmake -DCMAKE_BUILD_PROFILE=Release .. +# Note: just running `make` will fail with a link error in render_stub.c; ignore this. +make bluebell +``` diff --git a/src/pre-compiler.cpp b/src/pre-compiler.cpp index c92900e..fce3828 100644 --- a/src/pre-compiler.cpp +++ b/src/pre-compiler.cpp @@ -16,7 +16,7 @@ std::shared_ptr> pre_compile_shader(const std::string &src // options.SetOptimizationLevel(shaderc_optimization_level_performance); options.SetTargetSpirv(shaderc_spirv_version_1_0); options.SetTargetEnvironment( - shaderc_target_env_opengl_compat, + shaderc_target_env_opengl, shaderc_env_version::shaderc_env_version_opengl_4_5); diff --git a/src/render_frame/render_stub.c b/src/render_frame/render_stub.c index 414b2dd..d004f6e 100644 --- a/src/render_frame/render_stub.c +++ b/src/render_frame/render_stub.c @@ -18,6 +18,10 @@ #ifndef FRAME_COUNT #define FRAME_COUNT 100 #endif +#ifndef MSAA +// Multisample anti-aliasing count (will actually sample MSAA^2 points) +#define MSAA 1 +#endif // render API: struct Uniforms { @@ -56,7 +60,6 @@ const char* PPM_HDR = "P6\n" STRINGIFY(FRAME_DIM) " " STRINGIFY(FRAME_DIM) "\n25 unsigned char frame_buf[FRAME_DIM][FRAME_DIM][3]; unsigned char linear_to_srgb(float lin) { - float srgb; if (lin < 0) { return 0; } else if (lin > 1) { @@ -64,7 +67,7 @@ unsigned char linear_to_srgb(float lin) { } else if (lin < 0.0031308) { return (unsigned char)(lin * 12.92); } else { - float srgb = (powf(lin, 1.0f/2.4f) * 1.055f - 0.055f) * 256; + float srgb = (powf(lin, 1.0f/2.4f) * 1.055f - 0.055f) * 256.f; if (srgb > 255.f) { return 255; } else { @@ -72,6 +75,13 @@ unsigned char linear_to_srgb(float lin) { } } } +float srgb_to_linear(float srgb) { + if (srgb < 0.04045f) { + return srgb/12.92f; + } else { + return powf((srgb+0.055f)/1.055f, 2.4f); + } +} int main(int argc, char** argv) { unsigned header_len = strlen(PPM_HDR); @@ -87,14 +97,23 @@ int main(int argc, char** argv) { for (int y = 0; y < FRAME_DIM; y++) { for (int x = 0; x < FRAME_DIM; x++) { float pixel[3]; + float pixel_accum[3] = {0.f,0.f,0.f}; unsigned char *pxl_dst = frame_buf[y][x]; -// printf("-- pixel %f,%f\n", (x+0.5f), (y+0.5f)); - render_pixel(ctx, (x + 0.5f), (y + 0.5f), pixel); + for (int ss_x = 0; ss_x < MSAA; ss_x++) { + for (int ss_y = 0; ss_y < MSAA; ss_y++) { + float rx = (0.5f + (float)ss_x) / (float)MSAA + (float)x; + float ry = (0.5f + (float)ss_y) / (float)MSAA + (float)y; + render_pixel(ctx, rx, ry, pixel); + for (int i = 0; i < 3; i++) { + pixel_accum[i] += srgb_to_linear(pixel[i]); + } + } + } for (int i = 0; i < 3; i++) { - pixel[i] *= 256; - if (pixel[i] < 0) { pixel[i] = 0; } - if (pixel[i] > 255) { pixel[i] = 255; } - pxl_dst[i] = (unsigned char) pixel[i]; +// pixel_accum[i] *= 256; +// if (pixel_accum[i] < 0) { pixel_accum[i] = 0; } +// if (pixel_accum[i] > 255) { pixel_accum[i] = 255; } + pxl_dst[i] = linear_to_srgb(pixel_accum[i]/(float)(MSAA*MSAA)); } } }