mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
clean up renderer
This commit is contained in:
@ -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/02/04 23:19:37 by tomoron ### ########.fr */
|
/* Updated: 2025/02/05 17:24:37 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,50 +37,46 @@ class Renderer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Renderer(Scene *scene, Window *win, Arguments &args);
|
Renderer(Scene *scene, Window *win, Arguments &args);
|
||||||
void renderImgui(void);
|
|
||||||
void update(Shader &shader);
|
void update(Shader &shader);
|
||||||
|
void renderImgui(void);
|
||||||
|
|
||||||
int rendering(void) const;
|
int rendering(void) const;
|
||||||
bool shouldClose(void) const;
|
bool shouldClose(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addPoint(float time);
|
|
||||||
void init(Scene *scene, Window *win);
|
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 initRender();
|
|
||||||
void addImageToRender(Shader &shader);
|
|
||||||
void endRender(void);
|
|
||||||
void imguiPathCreation(void);
|
|
||||||
void showRenderInfo(int isImgui);
|
void showRenderInfo(int isImgui);
|
||||||
void imguiRenderSettings(void);
|
|
||||||
std::string floatToTime(double timef);
|
std::string floatToTime(double timef);
|
||||||
|
float calcTime(void);
|
||||||
|
|
||||||
|
void addPoint(float time);
|
||||||
|
void imguiPathCreation(void);
|
||||||
|
void imguiRenderSettings(void);
|
||||||
|
|
||||||
|
void rawRead(std::ifstream &file, void *buf, size_t len);
|
||||||
|
void savePath(void);
|
||||||
|
void loadPath(std::string filename);
|
||||||
|
|
||||||
|
void makeMovement(float timeFromStart, float curSplitTimeReset);
|
||||||
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(int mode, AVCodecID id);
|
|
||||||
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
|
||||||
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
|
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
|
||||||
|
|
||||||
int _min;
|
void initRender();
|
||||||
int _sec;
|
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
||||||
int _samples;
|
void updateAvailableCodecs(int mode, AVCodecID id);
|
||||||
int _testSamples;
|
void addImageToRender(Shader &shader);
|
||||||
bool _autoTime;
|
void endRender(void);
|
||||||
int _fps;
|
|
||||||
char _filenameBuffer[512];
|
|
||||||
std::vector<t_pathPoint> _path;
|
|
||||||
std::string _outputFilename;
|
|
||||||
Scene *_scene;
|
Scene *_scene;
|
||||||
Window *_win;
|
Window *_win;
|
||||||
std::vector<const AVCodec *> _codecList;
|
|
||||||
std::vector<const char *> _codecListStr;
|
|
||||||
int _codecIndex;
|
|
||||||
bool _renderSettings;
|
|
||||||
bool _ignoreUnavailableCodec;
|
|
||||||
bool _headless;
|
|
||||||
bool _tp;
|
|
||||||
bool _shouldClose;
|
bool _shouldClose;
|
||||||
|
bool _headless;
|
||||||
|
std::string _outputFilename;
|
||||||
|
|
||||||
|
std::vector<t_pathPoint> _path;
|
||||||
int _curPathIndex;
|
int _curPathIndex;
|
||||||
int _destPathIndex;
|
int _destPathIndex;
|
||||||
double _curSplitStart;
|
double _curSplitStart;
|
||||||
@ -89,6 +85,22 @@ class Renderer
|
|||||||
long int _frameCount;
|
long int _frameCount;
|
||||||
float _renderStartTime;
|
float _renderStartTime;
|
||||||
|
|
||||||
|
|
||||||
|
int _samples;
|
||||||
|
int _testSamples;
|
||||||
|
int _min;
|
||||||
|
int _sec;
|
||||||
|
int _fps;
|
||||||
|
char _filenameBuffer[512];
|
||||||
|
bool _ignoreUnavailableCodec;
|
||||||
|
bool _tp;
|
||||||
|
bool _autoTime;
|
||||||
|
std::vector<const char *> _codecListStr;
|
||||||
|
int _codecIndex;
|
||||||
|
|
||||||
|
bool _renderSettings;
|
||||||
|
|
||||||
|
|
||||||
AVFormatContext *_format;
|
AVFormatContext *_format;
|
||||||
AVCodecContext *_codec_context;
|
AVCodecContext *_codec_context;
|
||||||
AVFrame *_rgb_frame;
|
AVFrame *_rgb_frame;
|
||||||
@ -96,7 +108,7 @@ class Renderer
|
|||||||
SwsContext *_sws_context;
|
SwsContext *_sws_context;
|
||||||
AVStream *_stream;
|
AVStream *_stream;
|
||||||
AVDictionary *_codecOptions;
|
AVDictionary *_codecOptions;
|
||||||
|
std::vector<const AVCodec *> _codecList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* 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/02/04 23:42:00 by tomoron ### ########.fr */
|
/* Updated: 2025/02/05 17:21:00 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
|
|||||||
init(scene, win);
|
init(scene, win);
|
||||||
_headless = args.getHeadless();
|
_headless = args.getHeadless();
|
||||||
renderPath = args.getRenderPath();
|
renderPath = args.getRenderPath();
|
||||||
|
|
||||||
if(renderPath)
|
if(renderPath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -101,9 +102,7 @@ void Renderer::savePath(void)
|
|||||||
outputFile.write((char *)&_samples, sizeof(_samples));
|
outputFile.write((char *)&_samples, sizeof(_samples));
|
||||||
outputFile.write((char *)&_fps, sizeof(_fps));
|
outputFile.write((char *)&_fps, sizeof(_fps));
|
||||||
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
|
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
|
||||||
{
|
|
||||||
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
|
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
|
||||||
}
|
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +154,6 @@ void Renderer::loadPath(std::string filename)
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::shouldClose(void) const
|
|
||||||
{
|
|
||||||
return(_shouldClose);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst)
|
void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst)
|
||||||
{
|
{
|
||||||
lst.push_back(AV_CODEC_ID_FFV1);
|
lst.push_back(AV_CODEC_ID_FFV1);
|
||||||
@ -462,37 +456,6 @@ glm::vec3 Renderer::hermiteInterpolate(glm::vec3 points[4], double alpha)
|
|||||||
return(coef[0] * points[1] + coef[1] * tang[0] + coef[2] * tang[1] + coef[3] * points[2]);
|
return(coef[0] * points[1] + coef[1] * tang[0] + coef[2] * tang[1] + coef[3] * points[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//glm::quat eulerToQuaternion(float pitch, float yaw)
|
|
||||||
//{
|
|
||||||
// glm::quat qPitch = glm::angleAxis(glm::radians(pitch), glm::vec3(1, 0, 0));
|
|
||||||
// glm::quat qYaw = glm::angleAxis(glm::radians(yaw), glm::vec3(0, 1, 0));
|
|
||||||
//
|
|
||||||
// glm::quat result = qYaw* qPitch;
|
|
||||||
// return(result);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//glm::vec2 Renderer::sphereInterpolate(glm::vec2 from, glm::vec2 to, float time) // gud but bad
|
|
||||||
//{
|
|
||||||
// glm::vec3 eulerRes;
|
|
||||||
// glm::quat qFrom;
|
|
||||||
// glm::quat qTo;
|
|
||||||
// glm::quat res;
|
|
||||||
// float angle;
|
|
||||||
// float dot;
|
|
||||||
//
|
|
||||||
// qFrom = glm::normalize(eulerToQuaternion(from.y, from.x));
|
|
||||||
// qTo = glm::normalize(eulerToQuaternion(to.y, to.x));
|
|
||||||
//
|
|
||||||
// dot = glm::dot(qFrom, qTo);
|
|
||||||
// if(dot < 0)
|
|
||||||
// to = -to;
|
|
||||||
// angle = 2 * glm::acos(dot);
|
|
||||||
// res = (glm::sin((1 - time) * angle / glm::sin(angle)) * qFrom) + ((glm::sin(time * angle) / glm::sin(angle)) * qTo);
|
|
||||||
// eulerRes = glm::degrees(glm::eulerAngles(res));
|
|
||||||
// return(glm::vec2(eulerRes.y, eulerRes.x));
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
glm::vec2 Renderer::bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time)
|
glm::vec2 Renderer::bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time)
|
||||||
{
|
{
|
||||||
glm::vec2 delta;
|
glm::vec2 delta;
|
||||||
@ -570,6 +533,7 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
|||||||
bezierControl.y = !_curPathIndex || smallDistPrev ? .1f : .0f;
|
bezierControl.y = !_curPathIndex || smallDistPrev ? .1f : .0f;
|
||||||
bezierControl.z = 0.8f;
|
bezierControl.z = 0.8f;
|
||||||
bezierControl.w = (size_t)_curPathIndex + 2 >= _path.size() || smallDistNext ? .9f : 1.0f;
|
bezierControl.w = (size_t)_curPathIndex + 2 >= _path.size() || smallDistNext ? .9f : 1.0f;
|
||||||
|
|
||||||
dir = bezierSphereInterpolate(bezierControl, from.dir, to.dir, normalTime);
|
dir = bezierSphereInterpolate(bezierControl, from.dir, to.dir, normalTime);
|
||||||
if(std::isnan(dir.x) || std::isnan(dir.y))
|
if(std::isnan(dir.x) || std::isnan(dir.y))
|
||||||
dir = from.dir;
|
dir = from.dir;
|
||||||
@ -591,12 +555,7 @@ void Renderer::makeMovement(float timeFromStart, float curSplitTimeReset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Renderer::rendering(void) const
|
float Renderer::calcTime(void)
|
||||||
{
|
|
||||||
return(_destPathIndex != 0 && !_testMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::imguiPathCreation(void)
|
|
||||||
{
|
{
|
||||||
float prevSpeed;
|
float prevSpeed;
|
||||||
float time;
|
float time;
|
||||||
@ -606,6 +565,37 @@ void Renderer::imguiPathCreation(void)
|
|||||||
else
|
else
|
||||||
prevSpeed = 0;
|
prevSpeed = 0;
|
||||||
|
|
||||||
|
if(_autoTime)
|
||||||
|
{
|
||||||
|
_tp = 0;
|
||||||
|
if(_path.size() > 1)
|
||||||
|
time = _path[_path.size() - 1].time + (glm::distance(_path[_path.size() - 1].pos, _scene->getCamera()->getPosition()) / prevSpeed);
|
||||||
|
else
|
||||||
|
time = (float)_path.size() / 60;
|
||||||
|
if(std::isnan(time))
|
||||||
|
time = _path[_path.size() - 1].time + (1.0f / 60);
|
||||||
|
_min = time;
|
||||||
|
_sec = (time - (int)time) * 60;
|
||||||
|
}
|
||||||
|
else if(_tp)
|
||||||
|
{
|
||||||
|
_autoTime = 0;
|
||||||
|
if(!_path.size())
|
||||||
|
time = 0;
|
||||||
|
else
|
||||||
|
time = _path[_path.size() - 1].time;
|
||||||
|
_min = time;
|
||||||
|
_sec = (time - (int)time) * 60;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
time = (float)_min + ((float)_sec / 60);
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::imguiPathCreation(void)
|
||||||
|
{
|
||||||
|
float time;
|
||||||
|
|
||||||
ImGui::SliderInt("test spi", &_testSamples, 1, 10);
|
ImGui::SliderInt("test spi", &_testSamples, 1, 10);
|
||||||
|
|
||||||
if(ImGui::Button("render settings"))
|
if(ImGui::Button("render settings"))
|
||||||
@ -633,35 +623,10 @@ void Renderer::imguiPathCreation(void)
|
|||||||
_autoTime = 0;
|
_autoTime = 0;
|
||||||
_tp = 0;
|
_tp = 0;
|
||||||
}
|
}
|
||||||
if(_autoTime)
|
time = calcTime();
|
||||||
{
|
|
||||||
if(_path.size() > 1)
|
|
||||||
time = _path[_path.size() - 1].time + (glm::distance(_path[_path.size() - 1].pos, _scene->getCamera()->getPosition()) / prevSpeed);
|
|
||||||
else
|
|
||||||
time = (float)_path.size() / 60;
|
|
||||||
if(std::isnan(time))
|
|
||||||
time = _path[_path.size() - 1].time + (1.0f / 60);
|
|
||||||
_min = time;
|
|
||||||
_sec = (time - (int)time) * 60;
|
|
||||||
}
|
|
||||||
else if(_tp)
|
|
||||||
{
|
|
||||||
if(!_path.size())
|
|
||||||
time = 0;
|
|
||||||
else
|
|
||||||
time = _path[_path.size() - 1].time;
|
|
||||||
_min = time;
|
|
||||||
_sec = (time - (int)time) * 60;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
time = (float)_min + ((float)_sec / 60);
|
|
||||||
|
|
||||||
ImGui::Checkbox("guess time automatically", &_autoTime);
|
ImGui::Checkbox("guess time automatically", &_autoTime);
|
||||||
if(_autoTime)
|
|
||||||
_tp = 0;
|
|
||||||
ImGui::Checkbox("tp", &_tp);
|
ImGui::Checkbox("tp", &_tp);
|
||||||
if(_tp)
|
|
||||||
_autoTime = 0;
|
|
||||||
if(ImGui::Button("add step"))
|
if(ImGui::Button("add step"))
|
||||||
addPoint(time);
|
addPoint(time);
|
||||||
|
|
||||||
@ -718,7 +683,7 @@ std::string Renderer::floatToTime(double 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);
|
||||||
@ -740,26 +705,19 @@ std::string Renderer::floatToTime(double timef)
|
|||||||
switch(firstValue)
|
switch(firstValue)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
res += std::to_string(values[0]);
|
res += std::to_string(values[0]) + "Y";
|
||||||
res += "Y";
|
|
||||||
case 1:
|
case 1:
|
||||||
res += std::to_string(values[1]);
|
res += std::to_string(values[1]) + "M";
|
||||||
res += "M";
|
|
||||||
case 2:
|
case 2:
|
||||||
res += std::to_string(values[2]);
|
res += std::to_string(values[2]) + "W";
|
||||||
res += "W";
|
|
||||||
case 3:
|
case 3:
|
||||||
res += std::to_string(values[3]);
|
res += std::to_string(values[3]) + "d";
|
||||||
res += "d";
|
|
||||||
case 4:
|
case 4:
|
||||||
res += std::to_string(values[4]);
|
res += std::to_string(values[4]) + "h";
|
||||||
res += "h";
|
|
||||||
case 5:
|
case 5:
|
||||||
res += std::to_string(values[5]);
|
res += std::to_string(values[5]) + "m";
|
||||||
res += "m";
|
|
||||||
case 6:
|
case 6:
|
||||||
res += std::to_string(values[6]);
|
res += std::to_string(values[6]) + "s";
|
||||||
res += "s";
|
|
||||||
}
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
@ -865,7 +823,6 @@ void Renderer::imguiRenderSettings(void)
|
|||||||
|
|
||||||
void Renderer::renderImgui(void)
|
void Renderer::renderImgui(void)
|
||||||
{
|
{
|
||||||
// ImGui::Begin("Renderer");
|
|
||||||
if (ImGui::CollapsingHeader("Renderer"))
|
if (ImGui::CollapsingHeader("Renderer"))
|
||||||
{
|
{
|
||||||
if(rendering())
|
if(rendering())
|
||||||
@ -875,5 +832,15 @@ void Renderer::renderImgui(void)
|
|||||||
else
|
else
|
||||||
imguiPathCreation();
|
imguiPathCreation();
|
||||||
}
|
}
|
||||||
// ImGui::End();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Renderer::shouldClose(void) const
|
||||||
|
{
|
||||||
|
return(_shouldClose);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Renderer::rendering(void) const
|
||||||
|
{
|
||||||
|
return(_destPathIndex != 0 && !_testMode);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user