start changing parsing of arguments to add settings and start a render with no input

This commit is contained in:
2025-02-06 16:31:28 +01:00
parent 635cadf527
commit cb7eb9346c
16 changed files with 395 additions and 148 deletions

86
.vscode/settings.json vendored
View File

@ -1,86 +0,0 @@
{
"files.associations": {
"*.cs": "csharp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"array": "cpp",
"vector": "cpp",
"deque": "cpp",
"string_view": "cpp",
"span": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"format": "cpp",
"functional": "cpp",
"sstream": "cpp",
"variant": "cpp",
"charconv": "cpp",
"cstdarg": "cpp",
"cwctype": "cpp",
"map": "cpp",
"set": "cpp",
"algorithm": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"iomanip": "cpp",
"numbers": "cpp",
"cinttypes": "cpp",
"fstream": "cpp",
"list": "cpp",
"locale": "cpp",
"xhash": "cpp",
"xlocbuf": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xloctime": "cpp",
"xtree": "cpp",
"forward_list": "cpp"
},
"cmake.ignoreCMakeListsMissing": true
}

View File

@ -56,6 +56,7 @@ ALL_SRCS := $(IMGUI_SRCS) \
class/ObjParser.cpp \ class/ObjParser.cpp \
class/BVH.cpp \ class/BVH.cpp \
class/Renderer.cpp \ class/Renderer.cpp \
class/Arguments.cpp
SRCS := $(ALL_SRCS:%=$(SRCS_DIR)/%) SRCS := $(ALL_SRCS:%=$(SRCS_DIR)/%)
OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o)) OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o))

View File

@ -29,6 +29,6 @@ Pos=1556,610
Size=284,382 Size=284,382
[Window][Settings] [Window][Settings]
Pos=1568,11 Pos=532,13
Size=336,975 Size=336,287

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */ /* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
/* Updated: 2025/02/03 18:17:48 by ycontre ### ########.fr */ /* Updated: 2025/02/04 01:10:20 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -57,6 +57,7 @@ struct Vertex {
# include "objects/Portal.hpp" # include "objects/Portal.hpp"
# include "objects/Cylinder.hpp" # include "objects/Cylinder.hpp"
# include "Arguments.hpp"
# include "Camera.hpp" # include "Camera.hpp"
# include "Renderer.hpp" # include "Renderer.hpp"
# include "Window.hpp" # include "Window.hpp"

50
includes/RT/Arguments.hpp Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Arguments.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/04 01:07:08 by tomoron #+# #+# */
/* Updated: 2025/02/04 03:10:58 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ARGUMENTS_HPP
# define ARGUMENTS_HPP
#include "RT.hpp"
typedef struct s_arg
{
char shortName;
std::string longName;
int isFlag;
} t_arg;
class Arguments
{
public :
Arguments(int argc, char **argv);
bool getHeadless(void) const;
std::string &getSceneName(void);
std::string getRenderPathName(void);
bool error(void) const;
private:
void printUsage();
int handleArg(char **argv, int argc, int *i);
void initArguments(void);
void addArgument(char shortName, std::string longName, int isFlag);
void parseRenderPathName(char * path);
bool _headless;
bool _err;
std::vector<t_arg> _args;
std::map<std::string, std::string> _values;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */ /* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
/* Updated: 2025/01/30 22:15:55 by tomoron ### ########.fr */ /* Updated: 2025/02/04 00:41:10 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,21 +37,28 @@ class Renderer
{ {
public: public:
Renderer(Scene *scene, Window *win); Renderer(Scene *scene, Window *win);
Renderer(Scene *scene, Window *win, std::string filename);
void renderImgui(void); void renderImgui(void);
void update(Shader &shader); void update(Shader &shader);
int rendering(void) const; int rendering(void) const;
bool shouldClose(void) const;
private: private:
void addPoint(float time); void addPoint(float time);
void init(Scene *scene, Window *win);
void savePath(void);
void rawRead(std::ifstream &file, void *buf, size_t len);
void loadPath(std::string filename);
void makeMovement(float timeFromStart, float curSplitTimeReset); void makeMovement(float timeFromStart, float curSplitTimeReset);
void initRender(); void initRender();
void addImageToRender(Shader &shader); void addImageToRender(Shader &shader);
void endRender(void); void endRender(void);
void imguiPathCreation(void); void imguiPathCreation(void);
void imguiRenderInfo(void); void imguiRenderInfo(void);
std::string floatToTime(float timef); void imguiRenderSettings(void);
std::string floatToTime(double timef);
glm::vec2 bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time); glm::vec2 bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time);
void updateAvailableCodecs(void); void updateAvailableCodecs(int mode, AVCodecID id);
void fillGoodCodecList(std::vector<AVCodecID> &lst); void fillGoodCodecList(std::vector<AVCodecID> &lst);
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha); glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
@ -69,6 +76,10 @@ class Renderer
std::vector<const AVCodec *> _codecList; std::vector<const AVCodec *> _codecList;
std::vector<const char *> _codecListStr; std::vector<const char *> _codecListStr;
int _codecIndex; int _codecIndex;
bool _renderSettings;
bool _ignoreUnavailableCodec;
bool _headless;
bool _shouldClose;
int _curPathIndex; int _curPathIndex;
int _destPathIndex; int _destPathIndex;

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */ /* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */
/* Updated: 2025/01/28 19:05:16 by ycontre ### ########.fr */ /* Updated: 2025/02/04 03:11:36 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -105,11 +105,9 @@ class Camera;
class Scene class Scene
{ {
public: public:
Scene(); Scene(std::string &name);
~Scene(); ~Scene();
bool parseScene(char *name);
void addObject(Object *object); void addObject(Object *object);
void addMaterial(Material *material); void addMaterial(Material *material);
void addTexture(std::string path); void addTexture(std::string path);
@ -141,7 +139,11 @@ class Scene
Camera *getCamera(void) const; Camera *getCamera(void) const;
GPUMaterial getMaterial(int material_index); GPUMaterial getMaterial(int material_index);
bool fail(void) const;
private: private:
bool _fail;
std::vector<GPUBvhData> _gpu_bvh_data; std::vector<GPUBvhData> _gpu_bvh_data;
std::vector<GPUBvh> _gpu_bvh; std::vector<GPUBvh> _gpu_bvh;

View File

@ -6,7 +6,7 @@
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */ /* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/26 21:37:37 by TheRed #+# #+# */ /* Created: 2024/12/26 21:37:37 by TheRed #+# #+# */
/* Updated: 2025/01/21 15:15:13 by tomoron ### ########.fr */ /* Updated: 2025/02/04 01:21:28 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@
class SceneParser class SceneParser
{ {
public: public:
SceneParser(Scene *scene, char *filename); SceneParser(Scene *scene, std::string filename);
bool parseLine(const std::string &line); bool parseLine(const std::string &line);

View File

@ -19,7 +19,7 @@ cu 0 10 0 5 5 5 3
sp 0 10 0 1 4 sp 0 10 0 1 4
OBJ scenes/obj/lambo.obj 0 1.5 0 1 0 0 0 OBJ obj/lambo.obj 0 1.5 0 1 0 0 0

View File

@ -15,4 +15,3 @@ OBJ scenes/obj/jinx.obj -10 0 0 1.25 0 0 0
# OBJ scenes/obj/Dragon_800K.obj 0 0 0 35 0 0 0 1 # OBJ scenes/obj/Dragon_800K.obj 0 0 0 35 0 0 0 1
OBJ scenes/obj/whitedragon.obj 0 0 0 1 0 0 0 OBJ scenes/obj/whitedragon.obj 0 0 0 1 0 0 0

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */ /* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
/* Updated: 2025/02/02 19:44:53 by ycontre ### ########.fr */ /* Updated: 2025/02/06 16:30:58 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,15 +14,16 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Scene scene; Arguments args(argc, argv);
if(args.error())
if (argc <= 1 || !scene.parseScene(argv[1])) return(1);
return (1); Scene scene(args.getSceneName());
if(scene.fail())
return(1);
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0); Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl"); Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl"); // Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
GLint max_gpu_size; GLint max_gpu_size;
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size); glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);

141
srcs/class/Arguments.cpp Normal file
View File

@ -0,0 +1,141 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Arguments.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/04 01:05:44 by tomoron #+# #+# */
/* Updated: 2025/02/04 03:16:25 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "RT.hpp"
Arguments::Arguments(int argc, char **argv)
{
initArguments();
_headless = 0;
_err = 0;
if(argc <= 1)
{
_err = 1;
printUsage();
return ;
}
for(int i = 1; i < argc; i++)
{
if(!handleArg(argv, argc, &i))
{
_err = 1;
return ;
}
}
if(_values.find("sceneName") == _values.end())
{
std::cerr << "missing scene name" << std::endl;
_err = 1;
}
}
void Arguments::printUsage(void)
{
std::cerr << "usage : [options] <scene name> [options]" << std::endl;
std::cerr << R""""(options :
-r | --renderpath : filename for the renderer path
-h | --headless : does the program need to start rendering as soon as it starts(and close automatically)
)"""";
}
bool Arguments::error(void) const
{
return(_err);
}
std::string &Arguments::getSceneName(void)
{
return(_values["sceneName"]);
}
void Arguments::addArgument(char shortName, std::string longName, int isFlag)
{
t_arg arg;
arg.shortName = shortName;
arg.longName = longName;
arg.isFlag = isFlag;
_args.push_back(arg);
}
void Arguments::initArguments()
{
addArgument('r', "renderPath", 0);
addArgument('h', "headless", 1);
}
int Arguments::handleArg(char **argv, int argc, int *i)
{
std::string arg(argv[*i]);
(void)i;
if(!arg.size())
return(1);
if(arg.size() >= 2 && arg[0] == '-' && arg[1] == '-')
{
for(std::vector<t_arg>::iterator it = _args.begin(); it != _args.end(); it++)
{
if((*it).longName == arg.substr(2))
{
if((*it).isFlag)
_values[(*it).longName] = "yes";
else if(*i == argc - 1)
{
std::cerr << "missing option" << std::endl;
return(0);
}
else
_values[(*it).longName] = argv[++(*i)];
return(1);
}
}
std::cerr<< "unrecognized option : " << arg << std::endl;
return(0);
}
else if(arg[0] == '-')
{
for(size_t j = 1; j < arg.size(); j++)
{
for(std::vector<t_arg>::iterator it = _args.begin(); it != _args.end(); it++)
{
if((*it).shortName == arg[j])
{
if((*it).isFlag)
_values[(*it).longName] = "yes";
else if(*i == argc - 1)
{
std::cerr << "missing option" << std::endl;
return(0);
}
else
_values[(*it).longName] = argv[++(*i)];
return(1);
}
}
std::cerr << "unrecognized option : -" << arg[j] << std::endl;
return(0);
}
}
else
{
if(_values.find("sceneName") == _values.end())
_values["sceneName"] = arg;
else
{
std::cerr << "unrecognized option : " << arg << std::endl;
return(0);
}
}
return(1);
}

View File

@ -6,25 +6,41 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */ /* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
/* Updated: 2025/01/30 22:22:07 by tomoron ### ########.fr */ /* Updated: 2025/02/04 00:43:18 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "RT.hpp" #include "RT.hpp"
Renderer::Renderer(Scene *scene, Window *win) Renderer::Renderer(Scene *scene, Window *win)
{
init(scene, win);
_headless = 0;
}
Renderer::Renderer(Scene *scene, Window *win, std::string filename)
{
init(scene, win);
_headless = 1;
loadPath(filename);
initRender();
}
void Renderer::init(Scene *scene, Window *win)
{ {
_scene = scene; _scene = scene;
_win = win; _win = win;
_min = 0; _min = 0;
_sec = 0; _sec = 0;
_fps = 30; _fps = 30;
_shouldClose = 0;
_autoTime = 0; _autoTime = 0;
_samples = 1; _samples = 1;
_testSamples = 1; _testSamples = 1;
_curSamples = 0; _curSamples = 0;
_destPathIndex = 0; _destPathIndex = 0;
_frameCount = 0; _frameCount = 0;
_renderSettings = 0;
_outputFilename = "output.avi"; _outputFilename = "output.avi";
memcpy(_filenameBuffer, _outputFilename.c_str(), _outputFilename.length()); memcpy(_filenameBuffer, _outputFilename.c_str(), _outputFilename.length());
_filenameBuffer[_outputFilename.length()] = 0; _filenameBuffer[_outputFilename.length()] = 0;
@ -33,7 +49,87 @@ Renderer::Renderer(Scene *scene, Window *win)
_yuv_frame = 0; _yuv_frame = 0;
_format = 0; _format = 0;
_codec_context = 0; _codec_context = 0;
updateAvailableCodecs(); _ignoreUnavailableCodec = 0;
updateAvailableCodecs(_ignoreUnavailableCodec, (AVCodecID)0);
}
void Renderer::rawRead(std::ifstream &file, void *buf, size_t len)
{
file.read((char *)buf, len);
if(file.fail())
throw std::runtime_error("syntax error in path file");
}
/* path file format (bytes):
* - output file name (terminated by a \0)
* - codec id
* - samples per image
* - fps
* - path nodes (until the end)
*/
void Renderer::savePath(void)
{
std::ofstream outputFile;
const AVCodec *codec;
codec = _codecList[_codecIndex];
outputFile.open("output.path", std::ios::binary);
outputFile.write(_outputFilename.c_str(), _outputFilename.length() + 1);
outputFile.write((char *)&codec->id, sizeof(codec->id));
outputFile.write((char *)&_samples, sizeof(_samples));
outputFile.write((char *)&_fps, sizeof(_fps));
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
outputFile.close();
}
void Renderer::loadPath(std::string filename)
{
std::ifstream file;
AVCodecID codecId;
t_pathPoint pathPoint;
std::vector<t_pathPoint>::iterator pos;
char c;
_outputFilename = "";
_filenameBuffer[0] = 0;
file.open(filename);
c = 1;
while(c)
{
rawRead(file, &c, 1);
if(c && c < 32 && c > 126)
throw std::runtime_error("invalid char in filename");
if(c)
_outputFilename += c;
}
rawRead(file, &codecId, sizeof(codecId));
updateAvailableCodecs(2, codecId);
if(_codecList.size() == 0)
throw std::runtime_error("codec not available");
rawRead(file, &_samples, sizeof(_samples));
rawRead(file, &_fps, sizeof(_fps));
if(_samples < 1 || _fps < 1)
throw std::runtime_error("invalid value provided in fps or samples");
while(!file.eof())
{
rawRead(file, &pathPoint, sizeof(t_pathPoint));
if(pathPoint.time < .0f)
throw std::runtime_error("invalid time provided in path");
pos = _path.begin();
while(pos != _path.end() && pos->time <= pathPoint.time)
pos++;
_path.insert(pos, pathPoint);
}
if(_path.size() < 2)
throw std::runtime_error("not enough path points provided in the path");
file.close();
}
bool Renderer::shouldClose(void) const
{
return(_shouldClose);
} }
void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst) void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst)
@ -46,7 +142,12 @@ void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst)
lst.push_back(AV_CODEC_ID_V210); lst.push_back(AV_CODEC_ID_V210);
} }
void Renderer::updateAvailableCodecs(void) /* modes :
* 0 : adds only supported codecs are showed
* 1 : adds all codecs
* 2 : adds only codec <id>
*/
void Renderer::updateAvailableCodecs(int mode, AVCodecID id)
{ {
const AVCodec *codec; const AVCodec *codec;
AVCodecContext *ctx; AVCodecContext *ctx;
@ -69,6 +170,11 @@ void Renderer::updateAvailableCodecs(void)
codec = avcodec_find_encoder(*it); codec = avcodec_find_encoder(*it);
if(!codec) if(!codec)
continue; continue;
if (mode == 1 || (mode == 2 && codec->id == id))
{
_codecList.push_back(codec);
continue;
}
ctx = avcodec_alloc_context3(codec); ctx = avcodec_alloc_context3(codec);
if(ctx) if(ctx)
{ {
@ -226,6 +332,8 @@ void Renderer::endRender(void)
_rgb_frame = 0; _rgb_frame = 0;
_yuv_frame = 0; _yuv_frame = 0;
_codec_context = 0; _codec_context = 0;
if(_headless)
_shouldClose = 1;
} }
void Renderer::addPoint(float time) void Renderer::addPoint(float time)
@ -442,15 +550,9 @@ void Renderer::imguiPathCreation(void)
prevSpeed = 0; prevSpeed = 0;
ImGui::SliderInt("test spi", &_testSamples, 1, 10); ImGui::SliderInt("test spi", &_testSamples, 1, 10);
ImGui::SliderInt("render spi", &_samples, 1, 1000);
ImGui::SliderInt("render fps", &_fps, 30, 120);
ImGui::Combo("codec", &_codecIndex, _codecListStr.data(), _codecListStr.size()); if(ImGui::Button("render settings"))
if(ImGui::InputText("file name", _filenameBuffer, 512)) _renderSettings = 1;
{
_outputFilename = _filenameBuffer;
updateAvailableCodecs();
}
if(_path.size() > 1 && ImGui::Button("try full path")) if(_path.size() > 1 && ImGui::Button("try full path"))
{ {
_scene->getCamera()->setPosition(_path[0].pos); _scene->getCamera()->setPosition(_path[0].pos);
@ -461,8 +563,6 @@ void Renderer::imguiPathCreation(void)
_destPathIndex = _path.size() - 1; _destPathIndex = _path.size() - 1;
_testMode = 1; _testMode = 1;
} }
if(_path.size() > 1 && _codecList.size() && ImGui::Button("start render"))
initRender();
ImGui::Separator(); ImGui::Separator();
@ -485,6 +585,7 @@ void Renderer::imguiPathCreation(void)
if(ImGui::Button("add step")) if(ImGui::Button("add step"))
addPoint(time); addPoint(time);
ImGui::Separator(); ImGui::Separator();
for(unsigned long i = 0; i < _path.size(); i++) for(unsigned long i = 0; i < _path.size(); i++)
@ -529,7 +630,7 @@ void Renderer::imguiPathCreation(void)
} }
} }
std::string Renderer::floatToTime(float timef) std::string Renderer::floatToTime(double timef)
{ {
std::string res; std::string res;
uint64_t time; uint64_t time;
@ -537,13 +638,13 @@ std::string Renderer::floatToTime(float timef)
int firstValue; int firstValue;
time = timef; time = timef;
values[0] = time / 3600 * 24 * 365; values[0] = time / (3600 * 24 * 365);
time = time % (3600 * 24 * 365); time = time % (3600 * 24 * 365);
values[1] = time / 3600 * 24 * 30; values[1] = time / (3600 * 24 * 30);
time = time % (3600 * 24 * 30); time = time % (3600 * 24 * 30);
values[2] = time / 3600 * 24 * 7; values[2] = time / (3600 * 24 * 7);
time = time % (3600 * 24 * 7); time = time % (3600 * 24 * 7);
values[3] = time / 3600 * 24; values[3] = time / (3600 * 24);
time = time % (3600 * 24); time = time % (3600 * 24);
values[4] = time / 3600; values[4] = time / 3600;
time = time % 3600; time = time % 3600;
@ -619,6 +720,28 @@ void Renderer::imguiRenderInfo(void)
} }
} }
void Renderer::imguiRenderSettings(void)
{
ImGui::SliderInt("render spi", &_samples, 1, 1000);
ImGui::SliderInt("render fps", &_fps, 30, 120);
ImGui::Combo("codec", &_codecIndex, _codecListStr.data(), _codecListStr.size());
if(ImGui::InputText("file name", _filenameBuffer, 512))
{
_outputFilename = _filenameBuffer;
updateAvailableCodecs(_ignoreUnavailableCodec, (AVCodecID)0);
}
if(_path.size() > 1 && _codecList.size())
{
if(ImGui::Button("start render"))
initRender();
ImGui::SameLine();
if(ImGui::Button("save path"))
savePath();
}
if(ImGui::Button("go back"))
_renderSettings = 0;
}
void Renderer::renderImgui(void) void Renderer::renderImgui(void)
{ {
// ImGui::Begin("Renderer"); // ImGui::Begin("Renderer");
@ -626,6 +749,8 @@ void Renderer::renderImgui(void)
{ {
if(rendering()) if(rendering())
imguiRenderInfo(); imguiRenderInfo();
else if(_renderSettings)
imguiRenderSettings();
else else
imguiPathCreation(); imguiPathCreation();
} }

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */ /* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */
/* Updated: 2025/01/28 19:17:39 by ycontre ### ########.fr */ /* Updated: 2025/02/04 03:11:24 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,15 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
Scene::Scene() Scene::Scene(std::string &name)
{ {
std::cout << "name : " << name << std::endl;
std::ifstream file(name);
std::string line;
_camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f); _camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f);
_gpu_volume.enabled = 0; _gpu_volume.enabled = 0;
_fail = 0;
_gpu_volume.sigma_a = glm::vec3(0.0000f); _gpu_volume.sigma_a = glm::vec3(0.0000f);
_gpu_volume.sigma_s = glm::vec3(0.0800f); _gpu_volume.sigma_s = glm::vec3(0.0800f);
_gpu_volume.sigma_t = _gpu_volume.sigma_a + _gpu_volume.sigma_s; _gpu_volume.sigma_t = _gpu_volume.sigma_a + _gpu_volume.sigma_s;
@ -29,23 +33,13 @@ Scene::Scene()
_gpu_debug.mode = 0; _gpu_debug.mode = 0;
_gpu_debug.triangle_treshold = 1; _gpu_debug.triangle_treshold = 1;
_gpu_debug.box_treshold = 1; _gpu_debug.box_treshold = 1;
}
Scene::~Scene()
{
delete (_camera);
}
bool Scene::parseScene(char *name)
{
std::ifstream file(name);
std::string line;
if (!file.is_open()) if (!file.is_open())
{ {
std::cout << "Error opening the file" << std::endl; std::cerr << "Can't open scene file" << std::endl;
file.close(); _fail = 1;
return (false); return ;
} }
SceneParser scene_parser(this, name); SceneParser scene_parser(this, name);
@ -54,19 +48,22 @@ bool Scene::parseScene(char *name)
{ {
if (!scene_parser.parseLine(line)) if (!scene_parser.parseLine(line))
{ {
std::cerr << line << std::endl;
file.close(); file.close();
return (false); std::cerr << line << std::endl;
_fail = 1;
return ;
} }
} }
file.close(); file.close();
std::cout << "Parsing done" << std::endl; std::cout << "Parsing done" << std::endl;
return (true);
} }
Scene::~Scene()
{
delete (_camera);
}
void Scene::addObject(Object *obj) void Scene::addObject(Object *obj)
{ {
@ -313,6 +310,11 @@ void Scene::updateLightAndObjects(int mat_id)
} }
} }
bool Scene::fail(void) const
{
return(_fail);
}
std::set<int> Scene::getGPULights() std::set<int> Scene::getGPULights()
{ {
return (_gpu_lights); return (_gpu_lights);

View File

@ -6,13 +6,13 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/26 21:43:51 by TheRed #+# #+# */ /* Created: 2024/12/26 21:43:51 by TheRed #+# #+# */
/* Updated: 2025/01/30 22:29:15 by tomoron ### ########.fr */ /* Updated: 2025/02/04 01:21:11 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "SceneParser.hpp" #include "SceneParser.hpp"
SceneParser::SceneParser(Scene *scene, char *filename) : _scene(scene), _filename(filename) SceneParser::SceneParser(Scene *scene, std::string filename) : _scene(scene), _filename(filename)
{ {
object_parsers["sp"] = [](std::stringstream &ss) -> Object * { return (new Sphere(ss)); }; object_parsers["sp"] = [](std::stringstream &ss) -> Object * { return (new Sphere(ss)); };
object_parsers["pl"] = [](std::stringstream &ss) -> Object * { return (new Plane(ss)); }; object_parsers["pl"] = [](std::stringstream &ss) -> Object * { return (new Plane(ss)); };

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
/* Updated: 2025/01/28 15:15:53 by tomoron ### ########.fr */ /* Updated: 2025/02/04 00:42:01 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -161,7 +161,7 @@ void Window::pollEvents()
} }
bool Window::shouldClose() bool Window::shouldClose()
{ {
return glfwWindowShouldClose(_window); return glfwWindowShouldClose(_window) || _renderer->shouldClose();
} }
void Window::rendererUpdate(Shader &shader) void Window::rendererUpdate(Shader &shader)