broken wip

This commit is contained in:
Michaël Lemaire 2016-07-29 13:57:55 +02:00
parent fb16682876
commit 10d2b755e0
6 changed files with 63 additions and 2 deletions

View file

@ -99,8 +99,12 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config) {
delete renderer;
}
// renderer = new SoftwareCanvasRenderer(scenery);
auto raytracing = window->findQmlObject("tool_render_raytracing");
if (raytracing->property("checked").toBool()) {
renderer = new SoftwareRayRenderer(scenery);
} else {
renderer = new SoftwareCanvasRenderer(scenery);
}
renderer->setConfig(config);
destination->setCanvas(renderer->getCanvas());

View file

@ -112,6 +112,13 @@ OpenGLView {
hovertext: qsTr("Show last rendered image")
shortcut: "F6"
}
ToolbarButton {
id: tool_render_raytracing
toggle: true
objectName: "tool_render_raytracing"
hovertext: qsTr("Use raytracing instead of rasterization")
}
}
BaseSecondaryToolbar {

View file

@ -9,6 +9,7 @@
#include "SkyIntersector.h"
#include "TerrainIntersector.h"
#include "Vector3.h"
#include "WaterIntersector.h"
class SoftwareRayRenderer::pimpl {
public:
@ -30,6 +31,7 @@ void SoftwareRayRenderer::registerStandardIntersectors() {
impl->manager.registerIntersector(make_shared<SkyIntersector>(getAtmosphereRenderer()));
impl->manager.registerIntersector(make_shared<TerrainIntersector>(getTerrainRenderer()));
impl->manager.registerIntersector(make_shared<WaterIntersector>(getWaterRenderer()));
}
void SoftwareRayRenderer::renderPortion(CanvasPortion *portion, RenderProgress *progress, bool *interrupt) {

View file

@ -0,0 +1,22 @@
#include "WaterIntersector.h"
#include "InfinitePlane.h"
#include "InfiniteRay.h"
#include "WaterRenderer.h"
WaterIntersector::WaterIntersector(WaterRenderer *renderer): renderer(renderer) {
}
int WaterIntersector::getPriority() const {
return 10;
}
bool WaterIntersector::findIntersection(const Vector3 &eye, const Vector3 &direction, double, Vector3 *out_hit) const {
InfinitePlane water(Vector3(0.0, renderer->getHeightInfo().base_height, 0.0), VECTOR_UP);
int intersect = water.checkRayIntersection(InfiniteRay(eye, direction), out_hit);
return intersect == 1 && direction.dotProduct(out_hit->sub(eye)) > 0.0;
}
Color WaterIntersector::getColorAtHit(const Vector3 &, const Vector3 &location) const {
return renderer->getResult(location.x, location.z).final;
}

View file

@ -0,0 +1,25 @@
#pragma once
#include "software_global.h"
#include "RayIntersector.h"
namespace paysages {
namespace software {
/**
* Ray intersector with water.
*/
class SOFTWARESHARED_EXPORT WaterIntersector : public RayIntersector {
public:
WaterIntersector(WaterRenderer *renderer);
virtual int getPriority() const override;
virtual bool findIntersection(const Vector3 &eye, const Vector3 &direction, double limit,
Vector3 *out_hit) const override;
virtual Color getColorAtHit(const Vector3 &eye, const Vector3 &location) const override;
private:
WaterRenderer *renderer;
};
}
}

View file

@ -49,6 +49,7 @@ class RayCastingManager;
class RayCastingResult;
class RayIntersector;
class SkyIntersector;
class WaterIntersector;
class NightSky;
class MoonRenderer;