Updated to work with newer version of shaderc
This commit is contained in:
@@ -34,6 +34,7 @@ include(HandleLLVMOptions)
|
|||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/vendor/shaderc/CMakeLists.txt")
|
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/vendor/shaderc/CMakeLists.txt")
|
||||||
set(SHADERC_SKIP_TESTS ON)
|
set(SHADERC_SKIP_TESTS ON)
|
||||||
|
set(SHADERC_ENABLE_WERROR_COMPILE OFF)
|
||||||
add_subdirectory(vendor/shaderc)
|
add_subdirectory(vendor/shaderc)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|||||||
12
README.md
12
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 \
|
apt install llvm-14-tools clang build-essential cmake git \
|
||||||
llvm-14-dev libboost-log-dev spirv-headers spirv-tools
|
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
|
||||||
|
```
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ std::shared_ptr<std::vector<uint32_t>> pre_compile_shader(const std::string &src
|
|||||||
// options.SetOptimizationLevel(shaderc_optimization_level_performance);
|
// options.SetOptimizationLevel(shaderc_optimization_level_performance);
|
||||||
options.SetTargetSpirv(shaderc_spirv_version_1_0);
|
options.SetTargetSpirv(shaderc_spirv_version_1_0);
|
||||||
options.SetTargetEnvironment(
|
options.SetTargetEnvironment(
|
||||||
shaderc_target_env_opengl_compat,
|
shaderc_target_env_opengl,
|
||||||
shaderc_env_version::shaderc_env_version_opengl_4_5);
|
shaderc_env_version::shaderc_env_version_opengl_4_5);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
#ifndef FRAME_COUNT
|
#ifndef FRAME_COUNT
|
||||||
#define FRAME_COUNT 100
|
#define FRAME_COUNT 100
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef MSAA
|
||||||
|
// Multisample anti-aliasing count (will actually sample MSAA^2 points)
|
||||||
|
#define MSAA 1
|
||||||
|
#endif
|
||||||
|
|
||||||
// render API:
|
// render API:
|
||||||
struct Uniforms {
|
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 frame_buf[FRAME_DIM][FRAME_DIM][3];
|
||||||
|
|
||||||
unsigned char linear_to_srgb(float lin) {
|
unsigned char linear_to_srgb(float lin) {
|
||||||
float srgb;
|
|
||||||
if (lin < 0) {
|
if (lin < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (lin > 1) {
|
} else if (lin > 1) {
|
||||||
@@ -64,7 +67,7 @@ unsigned char linear_to_srgb(float lin) {
|
|||||||
} else if (lin < 0.0031308) {
|
} else if (lin < 0.0031308) {
|
||||||
return (unsigned char)(lin * 12.92);
|
return (unsigned char)(lin * 12.92);
|
||||||
} else {
|
} 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) {
|
if (srgb > 255.f) {
|
||||||
return 255;
|
return 255;
|
||||||
} else {
|
} 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) {
|
int main(int argc, char** argv) {
|
||||||
unsigned header_len = strlen(PPM_HDR);
|
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 y = 0; y < FRAME_DIM; y++) {
|
||||||
for (int x = 0; x < FRAME_DIM; x++) {
|
for (int x = 0; x < FRAME_DIM; x++) {
|
||||||
float pixel[3];
|
float pixel[3];
|
||||||
|
float pixel_accum[3] = {0.f,0.f,0.f};
|
||||||
unsigned char *pxl_dst = frame_buf[y][x];
|
unsigned char *pxl_dst = frame_buf[y][x];
|
||||||
// printf("-- pixel %f,%f\n", (x+0.5f), (y+0.5f));
|
for (int ss_x = 0; ss_x < MSAA; ss_x++) {
|
||||||
render_pixel(ctx, (x + 0.5f), (y + 0.5f), pixel);
|
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++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
pixel[i] *= 256;
|
// pixel_accum[i] *= 256;
|
||||||
if (pixel[i] < 0) { pixel[i] = 0; }
|
// if (pixel_accum[i] < 0) { pixel_accum[i] = 0; }
|
||||||
if (pixel[i] > 255) { pixel[i] = 255; }
|
// if (pixel_accum[i] > 255) { pixel_accum[i] = 255; }
|
||||||
pxl_dst[i] = (unsigned char) pixel[i];
|
pxl_dst[i] = linear_to_srgb(pixel_accum[i]/(float)(MSAA*MSAA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user