RT Multisampling
This commit is contained in:
parent
97a99f84f5
commit
e9daedd6ea
7 changed files with 120 additions and 37 deletions
|
|
@ -78,6 +78,17 @@ int readRenderSettings(lua_State* L, tp::RayTracer::RenderSettings& settings) {
|
||||||
}
|
}
|
||||||
lua_pop(L, 1); // Pop the 'spray' field
|
lua_pop(L, 1); // Pop the 'spray' field
|
||||||
|
|
||||||
|
// Read depth field
|
||||||
|
lua_getfield(L, -1, "multisampling");
|
||||||
|
if (lua_isnumber(L, -1)) {
|
||||||
|
settings.multisampling = (int) lua_tonumber(L, -1);
|
||||||
|
} else {
|
||||||
|
printf("RenderSettings 'depth' field is missing or not a number.\n");
|
||||||
|
lua_pop(L, 1); // Pop the 'depth' field
|
||||||
|
return 0; // Error
|
||||||
|
}
|
||||||
|
lua_pop(L, 1); // Pop the 'depth' field
|
||||||
|
|
||||||
return 1; // Success
|
return 1; // Success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,17 @@ Camera = {
|
||||||
|
|
||||||
Lights = {
|
Lights = {
|
||||||
{
|
{
|
||||||
pos = { 4, 2, 3 },
|
pos = { -0.5, 3.5, 1 },
|
||||||
intensity = 5
|
intensity = 1
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
pos = { 0, 0, 1 },
|
||||||
|
intensity = 0.5
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSettings = {
|
||||||
|
depth = 1,
|
||||||
|
spray = 10,
|
||||||
|
multisampling = 1,
|
||||||
}
|
}
|
||||||
|
|
@ -6,3 +6,21 @@ Camera = {
|
||||||
size_x = 400,
|
size_x = 400,
|
||||||
size_y = 600,
|
size_y = 600,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Lights = {
|
||||||
|
{
|
||||||
|
pos = { -0.5, 3.5, 1 },
|
||||||
|
intensity = 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos = { 0, 0, 1 },
|
||||||
|
intensity = 0.5
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSettings = {
|
||||||
|
depth = 1,
|
||||||
|
spray = 10,
|
||||||
|
multisampling = 1,
|
||||||
|
}
|
||||||
|
|
@ -20,5 +20,6 @@ Lights = {
|
||||||
|
|
||||||
RenderSettings = {
|
RenderSettings = {
|
||||||
depth = 1,
|
depth = 1,
|
||||||
spray = 10,
|
spray = 3,
|
||||||
|
multisampling = 16,
|
||||||
}
|
}
|
||||||
|
|
@ -156,50 +156,80 @@ void RayTracer::render(const Scene& scene, OutputBuffers& out, const RenderSetti
|
||||||
ualni currIter = 0;
|
ualni currIter = 0;
|
||||||
|
|
||||||
halnf maxDepth = 0;
|
halnf maxDepth = 0;
|
||||||
halnf minDepth = mScene->mCamera.getFar();
|
halnf minDepth = mScene->mCamera.getFar() * mSettings.multisampling;
|
||||||
|
|
||||||
|
auto accumulateColor = [](RGBA& col, const RGBA& in) {
|
||||||
|
col.r += in.r;
|
||||||
|
col.g += in.g;
|
||||||
|
col.b += in.b;
|
||||||
|
col.a = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto divideColor = [](RGBA& col, const halnf num) {
|
||||||
|
col.r /= num;
|
||||||
|
col.g /= num;
|
||||||
|
col.b /= num;
|
||||||
|
};
|
||||||
|
|
||||||
for (auto i = 0; i < mSettings.size.x; i++) {
|
for (auto i = 0; i < mSettings.size.x; i++) {
|
||||||
for (auto j = 0; j < mSettings.size.y; j++) {
|
for (auto j = 0; j < mSettings.size.y; j++) {
|
||||||
iterPoint = planeLeftTop + ((deltaX * (halnf) i) + (deltaY * (halnf) j));
|
for (auto sample = 0; sample < mSettings.multisampling; sample++) {
|
||||||
ray.dir = (iterPoint - pos).unitV();
|
auto randX = randomFloat();
|
||||||
|
auto randY = randomFloat();
|
||||||
|
|
||||||
castRay(ray, castData, mScene->mCamera.getFar());
|
iterPoint = planeLeftTop + ((deltaX * (halnf) (i + randX)) + (deltaY * (halnf) (j + randY)));
|
||||||
|
ray.dir = (iterPoint - pos).unitV();
|
||||||
|
|
||||||
if (castData.hit) {
|
castRay(ray, castData, mScene->mCamera.getFar());
|
||||||
LightData lightData;
|
|
||||||
cycle(castData, lightData, mSettings.depth);
|
|
||||||
|
|
||||||
const auto normal = castData.trig->getNormal();
|
if (castData.hit) {
|
||||||
const auto depth = (halnf) (castData.hitPos - ray.pos).length();
|
LightData lightData;
|
||||||
|
cycle(castData, lightData, mSettings.depth);
|
||||||
|
|
||||||
lightData.intensity = clamp(lightData.intensity, 0.f, 1.f);
|
const auto normal = castData.trig->getNormal();
|
||||||
RGBA col = {lightData.intensity, lightData.intensity, lightData.intensity, 1.f};
|
const auto depth = (halnf) (castData.hitPos - ray.pos).length();
|
||||||
|
|
||||||
out.color.set({i, j}, col);
|
lightData.intensity = clamp(lightData.intensity, 0.f, 1.f);
|
||||||
out.normals.set({i, j}, {normal.x * 0.5f + 0.5f, normal.y * 0.5f + 0.5f, normal.z * 0.5f + 0.5f, 1.f});
|
RGBA col = {lightData.intensity, lightData.intensity, lightData.intensity, 1.f};
|
||||||
out.depth.set({i, j}, {depth, depth, depth, 1.f});
|
|
||||||
|
|
||||||
if (maxDepth < depth) {
|
accumulateColor(out.color.get({i, j}), col);
|
||||||
maxDepth = depth;
|
accumulateColor(out.normals.get({i, j}), {normal.x * 0.5f + 0.5f, normal.y * 0.5f + 0.5f, normal.z * 0.5f + 0.5f, 1.f});
|
||||||
}
|
accumulateColor(out.depth.get({i, j}), {depth, depth, depth, 1.f});
|
||||||
if (minDepth > depth) {
|
|
||||||
minDepth = depth;
|
} else {
|
||||||
|
out.color.set({i, j}, 0.f);
|
||||||
|
out.normals.set({i, j}, 0.f);
|
||||||
|
out.depth.set({i, j}, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
// auto tmp = buff.get({i, j});
|
||||||
out.color.set({i, j}, 0.f);
|
// printf(" %f, %f, %f, %f, ", tmp.r, tmp.g, tmp.b, tmp.a);
|
||||||
out.normals.set({i, j}, 0.f);
|
|
||||||
out.depth.set({i, j}, 0.f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto tmp = buff.get({i, j});
|
|
||||||
// printf(" %f, %f, %f, %f, ", tmp.r, tmp.g, tmp.b, tmp.a);
|
|
||||||
|
|
||||||
mProgress.percentage = (halnf) currIter / (halnf) maxIterations;
|
mProgress.percentage = (halnf) currIter / (halnf) maxIterations;
|
||||||
currIter++;
|
currIter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto i = 0; i < mSettings.size.x * mSettings.size.y; i++) {
|
||||||
|
divideColor(out.color.getBuff()[i], (halnf) mSettings.multisampling);
|
||||||
|
divideColor(out.normals.getBuff()[i], (halnf) mSettings.multisampling);
|
||||||
|
divideColor(out.depth.getBuff()[i], (halnf) mSettings.multisampling);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = 0; i < mSettings.size.x * mSettings.size.y; i++) {
|
||||||
|
if (!out.depth.getBuff()[i].a) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto depth = out.depth.getBuff()[i].r;
|
||||||
|
if (maxDepth < depth) {
|
||||||
|
maxDepth = depth;
|
||||||
|
}
|
||||||
|
if (minDepth > depth) {
|
||||||
|
minDepth = depth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < mSettings.size.x * mSettings.size.y; i++) {
|
for (auto i = 0; i < mSettings.size.x * mSettings.size.y; i++) {
|
||||||
auto& col = out.depth.getBuff()[i];
|
auto& col = out.depth.getBuff()[i];
|
||||||
if (col.a == 1.f) {
|
if (col.a == 1.f) {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ namespace tp {
|
||||||
struct RenderSettings {
|
struct RenderSettings {
|
||||||
uhalni depth = 2;
|
uhalni depth = 2;
|
||||||
uhalni spray = 1;
|
uhalni spray = 1;
|
||||||
|
ualni multisampling = 1;
|
||||||
Vec2I size;
|
Vec2I size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
26
TODO
26
TODO
|
|
@ -9,14 +9,26 @@ Make two grammars Regular and Context-free
|
||||||
For each grammar make grammar rules parser, example sentence generation and sentence parsing
|
For each grammar make grammar rules parser, example sentence generation and sentence parsing
|
||||||
Make automations itself a universal tool - NFA DFA conversions
|
Make automations itself a universal tool - NFA DFA conversions
|
||||||
|
|
||||||
RayTracer:
|
Math:
|
||||||
Core:
|
FFT
|
||||||
Normals
|
|
||||||
Lua:
|
|
||||||
Camera Settings
|
|
||||||
Light Sources Settings (Point, Direction, Spot)
|
|
||||||
|
|
||||||
|
|
||||||
|
RayTracer:
|
||||||
|
Features:
|
||||||
|
Normals flag
|
||||||
|
Material, Normals per trig info
|
||||||
|
|
||||||
|
Quality:
|
||||||
|
Render eq
|
||||||
|
Materials
|
||||||
|
Lenses
|
||||||
|
Exposure
|
||||||
|
|
||||||
|
Efficiency:
|
||||||
|
Casting Accelerators
|
||||||
|
Important sampling
|
||||||
|
Threading
|
||||||
|
|
||||||
Parser:
|
Parser:
|
||||||
CF Grammar:
|
CF Grammar:
|
||||||
optimize generation of sentences
|
optimize generation of sentences
|
||||||
|
|
@ -72,4 +84,4 @@ Utils:
|
||||||
Save leaks and then use in debugging to break when the same call occurs?
|
Save leaks and then use in debugging to break when the same call occurs?
|
||||||
|
|
||||||
TextEditor:
|
TextEditor:
|
||||||
Implement
|
Implement
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue