Added quick unit test for perspective correction
This commit is contained in:
parent
b793259554
commit
2c340f0e43
6 changed files with 45 additions and 7 deletions
|
@ -584,6 +584,17 @@ void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector
|
|||
mutexRelease(area->lock);
|
||||
}
|
||||
|
||||
Color renderGetPixel(RenderArea* area, int x, int y)
|
||||
{
|
||||
Color result;
|
||||
|
||||
mutexAcquire(area->lock);
|
||||
result = _getFinalPixel(area, x, y);
|
||||
mutexRelease(area->lock);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void* _renderPostProcessChunk(void* data)
|
||||
{
|
||||
int x, y;
|
||||
|
|
|
@ -39,6 +39,8 @@ void renderUpdate(RenderArea* area);
|
|||
|
||||
void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data);
|
||||
|
||||
Color renderGetPixel(RenderArea* area, int x, int y);
|
||||
|
||||
void renderPostProcess(RenderArea* area, int nbchunks);
|
||||
int renderSaveToFile(RenderArea* area, const char* path);
|
||||
void renderSetPreviewCallbacks(RenderArea* area, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update);
|
||||
|
|
|
@ -257,15 +257,27 @@ static Color _toneMappingReinhard(Color pixel, double exposure)
|
|||
return pixel;
|
||||
}
|
||||
|
||||
static Color _toneMappingClamp(Color pixel, double exposure)
|
||||
{
|
||||
UNUSED(exposure);
|
||||
|
||||
pixel.r = pixel.r > 1.0 ? 1.0 : pixel.r;
|
||||
pixel.g = pixel.g > 1.0 ? 1.0 : pixel.g;
|
||||
pixel.b = pixel.b > 1.0 ? 1.0 : pixel.b;
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
void colorProfileSetToneMapping(ColorProfile* profile, ToneMappingOperator tonemapper, double exposure)
|
||||
{
|
||||
if (tonemapper == TONE_MAPPING_REIHNARD)
|
||||
switch (tonemapper)
|
||||
{
|
||||
profile->mapper = _toneMappingReinhard;
|
||||
}
|
||||
else
|
||||
{
|
||||
profile->mapper = _toneMappingUncharted;
|
||||
case TONE_MAPPING_REIHNARD:
|
||||
profile->mapper = _toneMappingReinhard;
|
||||
case TONE_MAPPING_UNCHARTED:
|
||||
profile->mapper = _toneMappingUncharted;
|
||||
default:
|
||||
profile->mapper = _toneMappingClamp;
|
||||
}
|
||||
profile->exposure = exposure;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ typedef struct ColorProfile ColorProfile;
|
|||
typedef enum
|
||||
{
|
||||
TONE_MAPPING_UNCHARTED,
|
||||
TONE_MAPPING_REIHNARD
|
||||
TONE_MAPPING_REIHNARD,
|
||||
TONE_MAPPING_CLAMP
|
||||
} ToneMappingOperator;
|
||||
|
||||
ColorProfile* colorProfileCreate();
|
||||
|
|
|
@ -87,5 +87,6 @@ static char _ck_gen_strbuf2[101];
|
|||
/***** Some builtin comparisons *****/
|
||||
#define ck_assert_double_in_range(_double_, _x_, _y_) ck_assert_double_gte(_double_, _x_);ck_assert_double_lte(_double_, _y_)
|
||||
#define ck_assert_vector_values(_vector_, _x_, _y_, _z_) ck_assert_double_eq(_vector_.x, _x_);ck_assert_double_eq(_vector_.y, _y_);ck_assert_double_eq(_vector_.z, _z_)
|
||||
#define ck_assert_color_values(_color_, _r_, _g_, _b_, _a_) ck_assert_double_eq(_color_.r, _r_);ck_assert_double_eq(_color_.g, _g_);ck_assert_double_eq(_color_.b, _b_);ck_assert_double_eq(_color_.a, _a_)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,11 +32,13 @@ static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* da
|
|||
|
||||
START_TEST(test_render_quad)
|
||||
{
|
||||
Color col;
|
||||
Renderer* renderer = rendererCreate();
|
||||
|
||||
renderer->render_width = 800;
|
||||
renderer->render_height = 600;
|
||||
renderer->render_quality = 1;
|
||||
renderSetToneMapping(renderer->render_area, TONE_MAPPING_CLAMP, 0.0);
|
||||
|
||||
cameraSetLocationCoords(renderer->render_camera, 0.0, 0.5, 2.0);
|
||||
cameraSetTargetCoords(renderer->render_camera, 0.0, 0.5, 0.0);
|
||||
|
@ -51,6 +53,15 @@ START_TEST(test_render_quad)
|
|||
renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
|
||||
renderPostProcess(renderer->render_area, tests_cpu_count);
|
||||
|
||||
col = renderGetPixel(renderer->render_area, 399, 599 - 435);
|
||||
ck_assert_color_values(col, 1.0, 1.0, 1.0, 1.0);
|
||||
col = renderGetPixel(renderer->render_area, 399, 599 - 436);
|
||||
ck_assert_color_values(col, 0.0, 0.0, 0.0, 1.0);
|
||||
col = renderGetPixel(renderer->render_area, 400, 599 - 435);
|
||||
ck_assert_color_values(col, 0.0, 0.0, 0.0, 1.0);
|
||||
col = renderGetPixel(renderer->render_area, 400, 599 - 436);
|
||||
ck_assert_color_values(col, 1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
renderSaveToFile(renderer->render_area, "./output/test_render_quad.png");
|
||||
|
||||
rendererDelete(renderer);
|
||||
|
|
Loading…
Reference in a new issue