Add jitter to area light and example render of it.

This commit is contained in:
Godzil
2020-03-02 14:03:31 +00:00
parent 1fbe682572
commit 21749695b6
12 changed files with 186 additions and 24 deletions

View File

@@ -12,6 +12,7 @@
#include <tuple.h>
#include <colour.h>
#include <renderstat.h>
#include <sequence.h>
#include <stdio.h>
class World;
@@ -37,6 +38,8 @@ public:
uint32_t samples;
uint32_t uSteps;
uint32_t vSteps;
bool jitter;
Sequence jitterBy;
public:
Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
@@ -44,7 +47,7 @@ public:
{ stats.addLight(); };
Light(LightType type, Tuple corner, Tuple fullUVec, uint32_t uSteps, Tuple fullVVec, uint32_t vSteps,
Colour intensity, bool jitter = false): type(type), corner(corner), uVec(fullUVec / uSteps), uSteps(uSteps),
vVec(fullVVec / vSteps), vSteps(vSteps), intensity(intensity)
vVec(fullVVec / vSteps), vSteps(vSteps), intensity(intensity), jitter(jitter)
{
this->samples = this->vSteps * this->uSteps;
this->position = this->corner + ((fullUVec + fullVVec) / 2);

50
source/include/sequence.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Sequence header
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#ifndef DORAYME_SEQUENCE_H
#define DORAYME_SEQUENCE_H
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
class Sequence
{
private:
double *list;
uint32_t listPos;
uint32_t listSize;
public:
Sequence() : list(nullptr), listPos(0), listSize(0) {
/* Need to bootstrap rand here */
srand(time(NULL));
}
Sequence(double *list, uint32_t listSize) : list(list), listPos(0), listSize(listSize) { };
static double frand(void)
{
return rand() / ((double) RAND_MAX);
}
double next() {
if (this->listSize == 0)
{
return frand();
}
else
{
uint32_t pos = this->listPos;
this->listPos = (this->listPos + 1) % this->listSize;
return this->list[pos];
}
}
};
#endif /* DORAYME_SEQUENCE_H */