Improved terrain ray walking test

This commit is contained in:
Michaël Lemaire 2016-03-18 00:27:01 +01:00
parent 6ac1e899f8
commit 2b02215566

View file

@ -586,7 +586,6 @@ static void testTerrainRayMarching() {
int width = 2000; int width = 2000;
int height = 600; int height = 600;
Texture2D result(width, height); Texture2D result(width, height);
result.fill(COLOR_WHITE);
Scenery scenery; Scenery scenery;
SoftwareRenderer renderer(&scenery); SoftwareRenderer renderer(&scenery);
@ -601,44 +600,54 @@ static void testTerrainRayMarching() {
terrain->validate(); terrain->validate();
int multisample = 8; for (int i = 0; i < 6; i++) {
int multisample = 8;
// Draw terrain shape result.fill(COLOR_WHITE);
for (int x = 0; x < width * multisample; x++) {
double altitude = terrain->getInterpolatedHeight(to_double(x) / to_double(multisample), 0.0, true, false); // Draw terrain shape
int y = height / 2 + round_to_int(altitude); for (int x = 0; x < width * multisample; x++) {
if (y >= 0 && y < height) { double altitude = terrain->getInterpolatedHeight(to_double(x) / to_double(multisample), 0.0, true, false);
result.setPixel(x / multisample, y, COLOR_GREY); int y = height / 2 + round_to_int(altitude);
if (y >= 0 && y < height) {
result.setPixel(x / multisample, y, COLOR_GREY);
}
Vector3 displaced = renderer.getTerrainRenderer()->getDisplaced(to_double(x) / to_double(multisample), 0.0, true);
int hx = round_to_int(displaced.x);
int hy = height / 2 + round_to_int(displaced.y);
if (hx >= 0 && hx < width && hy >= 0 && hy < height) {
result.setPixel(hx, hy, COLOR_BLACK);
}
result.setPixel(x / multisample, height / 2 + round_to_int(terrain->propWaterHeight()->getValue()), COLOR_BLUE);
} }
Vector3 displaced = renderer.getTerrainRenderer()->getDisplaced(to_double(x) / to_double(multisample), 0.0, true);
int hx = round_to_int(displaced.x); // Draw direction hint
int hy = height / 2 + round_to_int(displaced.y); double offset = to_double(i) * 0.2;
if (hx >= 0 && hx < width && hy >= 0 && hy < height) { Vector3 direction = Vector3(offset, -1.0, 0.0).normalize();
result.setPixel(hx, hy, COLOR_BLACK); for (int y = 0; y < height; y++) {
result.setPixel(height / 4 + round_to_int(to_double(y) * direction.x), height - 1 - y, COLOR_GREEN);
} }
result.setPixel(x / multisample, height / 2 + round_to_int(terrain->propWaterHeight()->getValue()), COLOR_BLUE); // Draw ray marcher hits
TerrainRayWalker walker(&renderer);
walker.setQuality(1.0, 0.1, 5.0, 1.0, to_double(height), 0.1);
walker.update();
for (int x = 0; x < width * multisample; x++) {
TerrainRayWalker::TerrainHitResult hit;
double max_height = terrain->getHeightInfo().max_height;
walker.startWalking(Vector3(to_double(x) / to_double(multisample) - to_double(max_height) * offset, to_double(max_height), 0.0), direction, 0.0, hit);
int hx = round_to_int(hit.hit_location.x);
int hy = height / 2 + round_to_int(hit.hit_location.y);
if (hx >= 0 && hx < width && hy >= 0 && hy < height) {
result.setPixel(hx, hy, COLOR_RED);
}
}
result.saveToFile(getFileName("terrain_ray_marching", i));
} }
// Draw ray marcher iterations
TerrainRayWalker walker(&renderer);
walker.setQuality(1.0, 0.1, 5.0, 1.0, to_double(height), 0.1);
walker.update();
double offset = 0.0;
Vector3 direction = Vector3(offset, -1.0, 0.0).normalize();
for (int x = 0; x < width * multisample; x++) {
TerrainRayWalker::TerrainHitResult hit;
double max_height = terrain->getHeightInfo().max_height;
walker.startWalking(Vector3(to_double(x) / to_double(multisample) - to_double(max_height) * offset, to_double(max_height), 0.0), direction, 0.0, hit);
int hx = round_to_int(hit.hit_location.x);
int hy = height / 2 + round_to_int(hit.hit_location.y);
if (hx >= 0 && hx < width && hy >= 0 && hy < height) {
result.setPixel(hx, hy, COLOR_RED);
}
}
result.saveToFile(getFileName("terrain_ray_marching"));
} }
void runTestSuite() { void runTestSuite() {