Texturing and commenting all code

This commit is contained in:
Ben Kyd
2019-09-13 17:22:16 +01:00
parent 1fbb093dd4
commit 31230ecad9
7 changed files with 72 additions and 15 deletions

View File

@@ -18,15 +18,14 @@ if (UNIX)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
#find_package(SDL2_image REQUIRED) #find_package(SDL2_image REQUIRED)
#find_package(PNG REQUIRED) #find_package(PNG REQUIRED)
#find_package(JPEG REQUIRED)
endif(UNIX) endif(UNIX)
if (WIN32) if (WIN32)
include_directories(${executable} include_directories(${executable}
"C:/dev/glm" "C:/dev/glm"
"C:/dev/SDL2/include/" "C:/dev/SDL2/include/"
"C:/dev/oidn/include"
#"C:/dev/SDL2_image/include/" #"C:/dev/SDL2_image/include/"
"C:/dev/oidn/include"
) )
endif (WIN32) endif (WIN32)
@@ -44,6 +43,7 @@ if (UNIX)
include_directories(${executable} include_directories(${executable}
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
#${SDL2_IMAGE_INCLUDE_DIR} #${SDL2_IMAGE_INCLUDE_DIR}
"/home/ben/dev/oidn/include/"
) )
endif (UNIX) endif (UNIX)
@@ -82,6 +82,9 @@ if (UNIX)
#PNG::PNG #PNG::PNG
#JPEG::JPEG #JPEG::JPEG
Threads::Threads Threads::Threads
"/home/ben/dev/oidn/lib/libOpenImageDenoise.so"
"/home/ben/dev/oidn/lib/libtbb.so.2"
"/home/ben/dev/oidn/lib/libtbbmalloc.so.2"
) )
endif (UNIX) endif (UNIX)

View File

@@ -2,7 +2,7 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "../../util/stb_image.hpp" #include "../../util/stb_image.hpp"
#include "../../util/stb_image_Write.hpp" #include "../../util/stb_image_write.hpp"
#include "../../common.hpp" #include "../../common.hpp"
@@ -15,21 +15,23 @@ Texture::Texture(std::string texturePath) {
} }
void Texture::Load(std::string texturePath) { void Texture::Load(std::string texturePath) {
struct P {
unsigned char r, g, b, a;
};
Width = 0; Height = 0; Width = 0; Height = 0;
int channels = 0; int channels = 0;
uint32_t* imageData = (uint32_t*)stbi_load(texturePath.c_str(), &Width, &Height, &channels, 4);
P* imageData = (P*)stbi_load(texturePath.c_str(), &Width, &Height, &channels, 4);
Data = new glm::vec3[Width * Height]; Data = new glm::vec3[Width * Height];
for (int x = 0; x < Width; x++) for (int x = 0; x < Width; x++)
for (int y = 0; y < Height; y++) { for (int y = 0; y < Height; y++) {
uint32_t p = imageData[y * Width + x]; P p = imageData[y * Width + x];
uint8_t r = (uint8_t)(p); // 0x000000FF Data[y * Width + x] = {(float)p.r / 255.0f,
uint8_t g = (uint8_t)(p >> 8); // 0x0000FF00 (float)p.g / 255.0f,
uint8_t b = (uint8_t)(p >> 16); // 0x00FF0000 (float)p.b / 255.0f };
Data[y * Width + x] = {(float)r / 255.0f,
(float)g / 255.0f,
(float)b / 255.0f };
} }
} }

View File

@@ -55,6 +55,7 @@ public:
virtual bool Intersect(Ray& ray, float& t) = 0; virtual bool Intersect(Ray& ray, float& t) = 0;
virtual glm::vec3 SurfaceNormal(glm::vec3 hitPoint) = 0; virtual glm::vec3 SurfaceNormal(glm::vec3 hitPoint) = 0;
virtual glm::vec3 SurfaceTangent(glm::vec3 normal) = 0;
virtual glm::vec2 TexCoords(glm::vec3 hitPoint) = 0; virtual glm::vec2 TexCoords(glm::vec3 hitPoint) = 0;
virtual void Translate(glm::vec3 trans) = 0; virtual void Translate(glm::vec3 trans) = 0;
@@ -65,6 +66,8 @@ public:
return material->NormalTexture->SampleNormal(TexCoords(hitPoint)); return material->NormalTexture->SampleNormal(TexCoords(hitPoint));
// combine with surface normal // combine with surface normal
} }
}; };

View File

@@ -1,3 +1,18 @@
#include "denoise.hpp" #include "denoise.hpp"
Denoiser::Denoiser() {
}
void Denoiser::SetAlbedo(glm::vec3* albedoBuffer) {
m_albedoBuffer = albedoBuffer;
}
void Denoiser::SetNormals(glm::vec3* normalBuffer) {
m_normalBuffer = normalBuffer;
}
void Denoiser::Denoise(glm::vec3* target, bool hdr) {
m_targetBuffer = target; m_hdr = hdr;
}

View File

@@ -5,14 +5,16 @@
class Denoiser { class Denoiser {
public: public:
Denoiser();
void SetAlbedo(glm::vec3* albedoBuffer); void SetAlbedo(glm::vec3* albedoBuffer);
void SetNormals(glm::vec3* normalBuffer); void SetNormals(glm::vec3* normalBuffer);
void Denoise(glm::vec3* target, bool hdr); void Denoise(glm::vec3* target, bool hdr);
private:
private:
bool m_hdr; bool m_hdr;
glm::vec3* m_albedoBuffer; glm::vec3* m_albedoBuffer;

View File

@@ -17,21 +17,41 @@ class Ray;
class ProgressiveRenderer { class ProgressiveRenderer {
public: public:
// Default constructor (unused)
ProgressiveRenderer(); ProgressiveRenderer();
// Initializes the renderer, takes the display interface
// that it will be rendering too, this manages windows and
// that and based on that it will decide if it is going
// to use imgui or not, and based on user preferance
void Init(DisplayInterface* interface, Scene* scene); void Init(DisplayInterface* interface, Scene* scene);
// Takes program input and updates imgui if it is active
// can manipulate scene based on input but im going to
// give a way for the end user to do that as well as a
// much broader imgui interface
void Input(); void Input();
// Starts the rendering process. This function does not return
// until program end / window close and it calls input every frame
void Render(); void Render();
// Indicates to the threadpool if the progressive renderer is ready
// and will tell them to start the render
bool Ready = false; bool Ready = false;
// Last 10 frame times to calculate average from
std::vector<float> FrameTimes = { }; std::vector<float> FrameTimes = { };
// All frame times since program start
std::vector<float> AllFrameTimes = { }; std::vector<float> AllFrameTimes = { };
// Average time of the last 10 frames for a more accurate fps
float AverageFrameTime = 0.0f; float AverageFrameTime = 0.0f;
// If MXAA is enabled
bool MXAA = true; bool MXAA = true;
public: public:
// Pointers to
RenderThreadPool* m_threadPool = nullptr; RenderThreadPool* m_threadPool = nullptr;
DisplayInterface* m_interface = nullptr; DisplayInterface* m_interface = nullptr;
RenderEngine* m_engine = nullptr; RenderEngine* m_engine = nullptr;
@@ -41,16 +61,23 @@ public:
private: private:
std::mutex m_mutex; std::mutex m_mutex;
// Calculates the frametime and updates the frametime clocks
void m_calculateTimes(std::chrono::high_resolution_clock::time_point& frameStartTime, void m_calculateTimes(std::chrono::high_resolution_clock::time_point& frameStartTime,
std::chrono::high_resolution_clock::time_point& frameEndTime); std::chrono::high_resolution_clock::time_point& frameEndTime);
// ints that map directly to RenderMode and ToneMapMode
// and are used to set them, must be indexed correctly
// according to the enums
int m_renderModeSelected = 0; int m_renderModeSelected = 0;
int m_toneMapModeSelected = 0; int m_toneMapModeSelected = 0;
int m_framesRendererd = 0; int m_framesRendererd = 0;
// Gamma to pass to the framebuffer
float m_gamma = 2.3f; float m_gamma = 2.3f;
// Image save path to pass to the framebuffer
std::string m_imageSavePath = "image.png"; std::string m_imageSavePath = "image.png";
RenderMode m_mode = (RenderMode)m_renderModeSelected; RenderMode m_mode = (RenderMode)m_renderModeSelected;

View File

@@ -2,8 +2,8 @@
#include "../src/inferno.hpp" #include "../src/inferno.hpp"
static const int width = 1010; static const int width = 600;
static const int height = 1010; static const int height = 600;
int main(int argc, char** argv) { int main(int argc, char** argv) {
InfernoEngine inferno; InfernoEngine inferno;
@@ -19,14 +19,19 @@ int main(int argc, char** argv) {
Scene* scene = new Scene(width, height); Scene* scene = new Scene(width, height);
scene->camera = new Camera(width, height); scene->camera = new Camera(width, height);
Sphere sphere1({ 1.3f, -0.8f, -5.0f }, 0.2f, new Material({ 0.817f, 0.374, 0.574 }));
scene->objects.push_back(&sphere1);
Sphere sphere({ 0.0f, 0.0f, -5.0f }, 1.0f, new Material({ 0.817f, 0.374, 0.574 })); Sphere sphere({ 0.0f, 0.0f, -5.0f }, 1.0f, new Material({ 0.817f, 0.374, 0.574 }));
sphere.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/dirt-normal.jpg");
scene->objects.push_back(&sphere); scene->objects.push_back(&sphere);
Sphere light({ 35.0f, 56.0f, 25.0f }, 35.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 5.0f)); Sphere light({ 35.0f, 56.0f, 25.0f }, 35.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 5.0f));
scene->objects.push_back(&light); scene->objects.push_back(&light);
Plane plane({ 0.0f,-1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.9f, 0.9f, 0.9f }, 0.2f)); Plane plane({ 0.0f,-1.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, new Material({ 0.9f, 0.9f, 0.9f }, 0.2f));
plane.material->NormalTexture = new Texture("E:/Projects/Inferno/resources/textures/normals.png"); // plane.material->NormalTexture = new Texture("E:/Projects/Inferno/resources/textures/normals.png");
plane.material->NormalTexture = new Texture("/home/ben/programming/inferno/resources/textures/normals.png");
scene->objects.push_back(&plane); scene->objects.push_back(&plane);
//scene->objects.push_back(new Sphere({ 35.0f, 26.0f, 25.0f }, 15.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 5.0f))); //scene->objects.push_back(new Sphere({ 35.0f, 26.0f, 25.0f }, 15.0f, new Material({ 1.0f, 1.0f, 1.0f }, 0.0f, 5.0f)));