more set features and a color noise

This commit is contained in:
Yggdrasil75
2026-01-05 14:10:27 -05:00
parent 264f5d9496
commit f347637b77
2 changed files with 53 additions and 11 deletions

View File

@@ -72,7 +72,7 @@ private:
float tmax = INF; float tmax = INF;
Vec3f invDir = direction.safeInverse(); Vec3f invDir = direction.safeInverse();
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (abs(direction[i] < EPSILON)) { if (abs(direction[i]) < EPSILON) {
if (origin[i] < tBMin[i] || origin[i] > tBMax[i]) return std::make_pair(0.0f, 0.0f); if (origin[i] < tBMin[i] || origin[i] > tBMax[i]) return std::make_pair(0.0f, 0.0f);
float t1 = tBMin[i] - origin[i] * invDir[i]; float t1 = tBMin[i] - origin[i] * invDir[i];
float t2 = tBMax[i] - origin[i] * invDir[i]; float t2 = tBMax[i] - origin[i] * invDir[i];
@@ -127,33 +127,40 @@ public:
} }
void set(size_t x, size_t y, size_t z, float active, Vec3ui8 color) { void set(size_t x, size_t y, size_t z, float active, Vec3ui8 color) {
//expand grid if needed. set(Vec3T(x,y,z), active, color);
if (x >= 0 || y >= 0 || z >= 0) { }
if (!(x < width)) {
void set(Vec3T pos, float active, Vec3ui8 color) {
if (pos.x >= 0 || pos.y >= 0 || pos.z >= 0) {
if (!(pos.x < width)) {
//until resizing added: //until resizing added:
return; return;
width = x; width = pos.x;
resize(); resize();
} }
else if (!(y < height)) { else if (!(pos.y < height)) {
//until resizing added: //until resizing added:
return; return;
height = y; height = pos.y;
resize(); resize();
} }
else if (!(z < depth)) { else if (!(pos.z < depth)) {
//until resizing added: //until resizing added:
return; return;
depth = z; depth = pos.z;
resize(); resize();
} }
Voxel& v = get(x, y, z); Voxel& v = get(pos);
v.active = std::clamp(active, 0.0f, 1.0f); v.active = std::clamp(active, 0.0f, 1.0f);
v.color = color; v.color = color;
} }
} }
void set(Vec3T pos, Vec4ui8 rgbaval) {
set(pos, static_cast<float>(rgbaval.a / 255), rgbaval.toVec3());
}
template<typename T> template<typename T>
bool inGrid(Vec3<T> voxl) { bool inGrid(Vec3<T> voxl) {
return (voxl >= 0 && voxl.x < width && voxl.y < height && voxl.z < depth); return (voxl >= 0 && voxl.x < width && voxl.y < height && voxl.z < depth);
@@ -233,6 +240,42 @@ public:
} }
} }
Vec3f tDelta = invDir.abs(); Vec3f tDelta = invDir.abs();
// Vec3f dir = direction.normalized();
// if (abs(dir.length()) < EPSILON) return false;
// Vec3f invDir = dir.safeInverse();
// Vec3T currentVoxel = origin.floorToT();
// if (dir.x == 0 || dir.y == 0 || dir.z == 0) {
// return specialCases(origin, dir, maxDist, hitColor);
// }
// //if (!inGrid(currentVoxel)) {
// std::pair<float,float> re = rayBoxIntersect(origin, dir);
// float tEntry = re.first;
// float tExit = re.second;
// float tStart = std::max(0.0f, tEntry);
// if (tEntry < EPSILON || tExit < EPSILON || tStart > maxDist) return false;
// Vec3f gridOrig = origin + dir * tStart;
// currentVoxel = gridOrig.floorToT();
// //}
// Vec3i8 step = Vec3i8(direction.x >= 0 ? 1 : -1, direction.y >= 0 ? 1 : -1, direction.z >= 0 ? 1 : -1);
// Vec3f tMax;
// Vec3f tDelta = invDir.abs();
// for (int i = 0; i < 3; i++) {
// //if (step[i] != 0) {
// if (step[i] > 0) {
// tMax[i] = ((currentVoxel[i] + 1) - origin[i]) * invDir[i];
// } else {
// tMax[i] = (currentVoxel[i] - origin[i]) * invDir[i];
// }
// //tDelta[i] = fabs(1.0f / dir[i]);
// //} else {
// //tMax[i] = INF;
// //tDelta[i] = INF;
// //}
// }
float aalpha = 0; float aalpha = 0;

View File

@@ -166,7 +166,6 @@ public:
Vec4ui8 permuteColor(const Vec3<float>& point) { Vec4ui8 permuteColor(const Vec3<float>& point) {
TIME_FUNCTION; TIME_FUNCTION;
float noiseR = permute(point); float noiseR = permute(point);
float noiseG = permute(point + Vec3<float>(100.0f, 100.0f, 100.0f)); float noiseG = permute(point + Vec3<float>(100.0f, 100.0f, 100.0f));
float noiseB = permute(point + Vec3<float>(200.0f, 200.0f, 200.0f)); float noiseB = permute(point + Vec3<float>(200.0f, 200.0f, 200.0f));