Started tests on pespective correct mapping
This commit is contained in:
parent
fbc64abb81
commit
a6ab7f7146
6 changed files with 79 additions and 33 deletions
|
@ -382,12 +382,16 @@ static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
|
||||||
|
|
||||||
static void _scanInterpolate(ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
|
static void _scanInterpolate(ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
|
||||||
{
|
{
|
||||||
|
double v1depth = v1->pixel.z;
|
||||||
|
double v2depth = (v1->pixel.z + diff->pixel.z);
|
||||||
|
double factor = ((1.0 - value) / v1depth + value / v2depth);
|
||||||
|
|
||||||
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
|
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
|
||||||
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
|
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
|
||||||
result->pixel.z = v1->pixel.z + diff->pixel.z * value;
|
result->pixel.z = ((1.0 - value) * (v1->pixel.z / v1depth) + value * (v1->pixel.z + diff->pixel.z) / v2depth) / factor;
|
||||||
result->location.x = v1->location.x + diff->location.x * value;
|
result->location.x = ((1.0 - value) * (v1->location.x / v1depth) + value * (v1->location.x + diff->location.x) / v2depth) / factor;
|
||||||
result->location.y = v1->location.y + diff->location.y * value;
|
result->location.y = ((1.0 - value) * (v1->location.y / v1depth) + value * (v1->location.y + diff->location.y) / v2depth) / factor;
|
||||||
result->location.z = v1->location.z + diff->location.z * value;
|
result->location.z = ((1.0 - value) * (v1->location.z / v1depth) + value * (v1->location.z + diff->location.z) / v2depth) / factor;
|
||||||
result->callback = v1->callback;
|
result->callback = v1->callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
|
||||||
|
|
||||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
{
|
{
|
||||||
|
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
UNUSED(location);
|
UNUSED(location);
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
@ -48,21 +47,16 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
|
|
||||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
|
return cameraProject(renderer->render_camera, point);
|
||||||
UNUSED(renderer);
|
|
||||||
return point;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
||||||
{
|
{
|
||||||
|
return cameraUnproject(renderer->render_camera, point);
|
||||||
UNUSED(renderer);
|
|
||||||
return point;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3 p1, p2, p3;
|
Vector3 p1, p2, p3;
|
||||||
|
|
||||||
p1 = renderer->projectPoint(renderer, v1);
|
p1 = renderer->projectPoint(renderer, v1);
|
||||||
|
@ -74,14 +68,12 @@ static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3
|
||||||
|
|
||||||
static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
|
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
|
||||||
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
|
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3 p1, p2, p3;
|
Vector3 p1, p2, p3;
|
||||||
|
|
||||||
p1 = renderer->projectPoint(renderer, v1);
|
p1 = renderer->projectPoint(renderer, v1);
|
||||||
|
@ -93,20 +85,17 @@ static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, V
|
||||||
|
|
||||||
static void _pushDisplacedQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, f_RenderFragmentCallback callback, void* callback_data)
|
static void _pushDisplacedQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, f_RenderFragmentCallback callback, void* callback_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
|
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
|
||||||
renderer->pushDisplacedTriangle(renderer, v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
|
renderer->pushDisplacedTriangle(renderer, v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
||||||
{
|
{
|
||||||
|
|
||||||
return _RAYCASTING_NULL;
|
return _RAYCASTING_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
|
||||||
{
|
{
|
||||||
|
|
||||||
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
|
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
|
||||||
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
|
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
|
||||||
Color result = lightingApplyStatus(light, normal, material);
|
Color result = lightingApplyStatus(light, normal, material);
|
||||||
|
@ -116,7 +105,6 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto
|
||||||
|
|
||||||
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
|
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
|
||||||
{
|
{
|
||||||
|
|
||||||
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
|
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
|
||||||
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
|
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
|
||||||
return color;
|
return color;
|
||||||
|
@ -124,7 +112,6 @@ static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color c
|
||||||
|
|
||||||
Renderer* rendererCreate()
|
Renderer* rendererCreate()
|
||||||
{
|
{
|
||||||
|
|
||||||
Renderer* result = malloc(sizeof (Renderer));
|
Renderer* result = malloc(sizeof (Renderer));
|
||||||
RenderParams params = {1, 1, 1, 5};
|
RenderParams params = {1, 1, 1, 5};
|
||||||
|
|
||||||
|
@ -168,7 +155,6 @@ Renderer* rendererCreate()
|
||||||
|
|
||||||
void rendererDelete(Renderer* renderer)
|
void rendererDelete(Renderer* renderer)
|
||||||
{
|
{
|
||||||
|
|
||||||
cameraDeleteDefinition(renderer->render_camera);
|
cameraDeleteDefinition(renderer->render_camera);
|
||||||
lightingManagerDelete(renderer->lighting);
|
lightingManagerDelete(renderer->lighting);
|
||||||
|
|
||||||
|
@ -185,7 +171,6 @@ void rendererDelete(Renderer* renderer)
|
||||||
|
|
||||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
||||||
{
|
{
|
||||||
|
|
||||||
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,16 +186,6 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
|
||||||
{
|
|
||||||
return cameraProject(renderer->render_camera, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
|
||||||
{
|
|
||||||
return cameraUnproject(renderer->render_camera, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
static double _getPrecision(Renderer* renderer, Vector3 location)
|
static double _getPrecision(Renderer* renderer, Vector3 location)
|
||||||
{
|
{
|
||||||
Vector3 projected;
|
Vector3 projected;
|
||||||
|
@ -216,8 +206,6 @@ Renderer* sceneryCreateStandardRenderer()
|
||||||
cameraCopyDefinition(_camera, result->render_camera);
|
cameraCopyDefinition(_camera, result->render_camera);
|
||||||
|
|
||||||
result->rayWalking = _rayWalking;
|
result->rayWalking = _rayWalking;
|
||||||
result->projectPoint = _projectPoint;
|
|
||||||
result->unprojectPoint = _unprojectPoint;
|
|
||||||
result->getPrecision = _getPrecision;
|
result->getPrecision = _getPrecision;
|
||||||
|
|
||||||
sceneryBindRenderer(result);
|
sceneryBindRenderer(result);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int tests_cpu_count;
|
||||||
|
|
||||||
static inline void _add_methods_to_case(TCase* tc, ...)
|
static inline void _add_methods_to_case(TCase* tc, ...)
|
||||||
{
|
{
|
||||||
void* method;
|
void* method;
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "rendering/main.h"
|
#include "rendering/main.h"
|
||||||
|
#include "rendering/system.h"
|
||||||
|
|
||||||
|
int tests_cpu_count;
|
||||||
extern void test_euclid_case(Suite* s);
|
extern void test_euclid_case(Suite* s);
|
||||||
extern void test_camera_case(Suite* s);
|
extern void test_camera_case(Suite* s);
|
||||||
extern void test_clouds_case(Suite* s);
|
extern void test_clouds_case(Suite* s);
|
||||||
|
extern void test_render_case(Suite* s);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -14,10 +17,13 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
paysagesInit();
|
paysagesInit();
|
||||||
|
|
||||||
|
tests_cpu_count = systemGetCoreCount();
|
||||||
|
|
||||||
/* TODO Find a way to automate this */
|
/* TODO Find a way to automate this */
|
||||||
test_euclid_case(s);
|
test_euclid_case(s);
|
||||||
test_camera_case(s);
|
test_camera_case(s);
|
||||||
test_clouds_case(s);
|
test_clouds_case(s);
|
||||||
|
test_render_case(s);
|
||||||
|
|
||||||
SRunner *sr = srunner_create(s);
|
SRunner *sr = srunner_create(s);
|
||||||
srunner_run_all(sr, CK_NORMAL);
|
srunner_run_all(sr, CK_NORMAL);
|
||||||
|
|
61
src/testing/test_render.c
Normal file
61
src/testing/test_render.c
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#include "testing/common.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "rendering/renderer.h"
|
||||||
|
#include "rendering/tools.h"
|
||||||
|
|
||||||
|
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
|
||||||
|
{
|
||||||
|
UNUSED(renderer);
|
||||||
|
UNUSED(data);
|
||||||
|
|
||||||
|
/* Checker-board */
|
||||||
|
double x = fmod(location.x, 0.2);
|
||||||
|
double z = fmod(location.z, 0.2);
|
||||||
|
if (x < 0.0)
|
||||||
|
{
|
||||||
|
x = 0.2 + x;
|
||||||
|
}
|
||||||
|
if (z < 0.0)
|
||||||
|
{
|
||||||
|
z = 0.2 + z;
|
||||||
|
}
|
||||||
|
if (x > 0.1 ^ z > 0.1)
|
||||||
|
{
|
||||||
|
return COLOR_WHITE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return COLOR_BLACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST(test_render_quad)
|
||||||
|
{
|
||||||
|
Renderer* renderer = rendererCreate();
|
||||||
|
|
||||||
|
renderer->render_width = 800;
|
||||||
|
renderer->render_height = 600;
|
||||||
|
renderer->render_quality = 1;
|
||||||
|
|
||||||
|
cameraSetLocationCoords(renderer->render_camera, 0.0, 0.5, 2.0);
|
||||||
|
cameraSetTargetCoords(renderer->render_camera, 0.0, 0.5, 0.0);
|
||||||
|
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
|
||||||
|
|
||||||
|
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
||||||
|
renderSetParams(renderer->render_area, params);
|
||||||
|
|
||||||
|
renderSetBackgroundColor(renderer->render_area, &COLOR_BLUE);
|
||||||
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
|
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, renderer, tests_cpu_count);
|
||||||
|
|
||||||
|
renderSaveToFile(renderer->render_area, "./output/test_render_quad.png");
|
||||||
|
|
||||||
|
rendererDelete(renderer);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
TEST_CASE(render, test_render_quad)
|
||||||
|
|
Loading…
Reference in a new issue