ray coagulation

This commit is contained in:
benkyd
2022-11-27 10:37:22 +00:00
parent f35a6013da
commit 63d520df9c
5 changed files with 44 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ public:
private:
glm::vec2 mViewport = { 100.0f, 100.0f };
glm::vec2 mRayViewport = { 100.0f, 100.0f };
glm::vec2 mRayViewport = { 300.0f, 300.0f };
glm::mat4 mViewMatrix = {};
glm::mat4 mProjMatrix = {};
bool mDidUpdate;

11
src/maths.hpp Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
namespace inferno::helpers {
const float DEG2RAD = 0.01745329251994329576923690768f;
const float RAD2DEG = 57.2957795130823208767981548141f;
const float PI = 3.14159265358979323846264338327f;
const float EPSILON = 0.00000100000000000000000000000f;
}

View File

@@ -8,9 +8,9 @@
// TODO: compile time precomputed random numbers
namespace inferno {
namespace inferno::helpers {
class Random : public helpers::Singleton<Random>
class Random : public Singleton<Random>
{
public:
inline Random()

View File

@@ -1,5 +1,9 @@
#include "ray_source.hpp"
#include <iostream>
#include <maths.hpp>
#include <scene/camera.hpp>
#include <tracing/ray.hpp>
@@ -19,7 +23,8 @@ RaySource::~RaySource()
void RaySource::generate()
{
// const float aspect = mReferenceCamera->getRayViewport().x / mReferenceCamera->getRayViewport().y;
// float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
}
RayField RaySource::getInitialRays(bool MSAA)
@@ -29,8 +34,27 @@ RayField RaySource::getInitialRays(bool MSAA)
this->generate();
}
RayField field;
field.reserve(mReferenceCamera->getRayViewport().x * mReferenceCamera->getRayViewport().y);
const float aspect = mReferenceCamera->getRayViewport().x / mReferenceCamera->getRayViewport().y;
float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
glm::mat4 cameraToWorld = mReferenceCamera->getViewMatrix();
glm::vec3 origin = mReferenceCamera->Position;
for (int x = 0; x < mReferenceCamera->getRayViewport().x; x++)
for (int y = 0; y < mReferenceCamera->getRayViewport().y; y++)
{
float Px = (2.0f * ((x + 0.5f) / mReferenceCamera->getRayViewport().x) - 1.0f) * scale * aspect;
float Py = (1.0f - 2.0f * ((y + 0.5f) / mReferenceCamera->getRayViewport().y) * scale);
return RayField{};
}
Ray* ray = new Ray;
ray->Origin = origin;
ray->Direction = glm::normalize(glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld);
field.push_back(ray);
}
return field;
}

View File

@@ -1,5 +1,7 @@
#include "renderer.hpp"
#include <iostream>
#include <scene/camera.hpp>
#include <scene/scene.hpp>
@@ -72,7 +74,7 @@ void RayRenderer::draw()
for (int x = 0; x < mRenderTargetSize.x; x++)
for (int y = 0; y < mRenderTargetSize.y; y++)
{
mTarget[y * mRenderTargetSize.x + x] = { 0.0f + ((float)x / (float)mRenderTargetSize.x), 0.0f + ((float)y / (float)mRenderTargetSize.y), 1.0f, 1.0f };
mTarget[y * mRenderTargetSize.x + x] = { startRays[y * mRenderTargetSize.x + x]->Direction, 1.0f };
}
glBindTexture(GL_TEXTURE_2D, mRenderTargetTexture);