mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
repair codec selection 42 computers, lerp and slerp might be broken :/
This commit is contained in:
4
Makefile
4
Makefile
@ -29,8 +29,8 @@ else
|
|||||||
DIR_DUP = mkdir -p $(@D)
|
DIR_DUP = mkdir -p $(@D)
|
||||||
CC := clang++
|
CC := clang++
|
||||||
CFLAGS := -Wall -Wextra -Werror -g -O3
|
CFLAGS := -Wall -Wextra -Werror -g -O3
|
||||||
IFLAGS := -I./includes -I./includes/RT -I./includes/imgui -I/usr/include
|
IFLAGS := -I./includes -I./includes/RT -I./includes/imgui
|
||||||
LDFLAGS := -L/usr/lib/x86_64-linux-gnu -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lstdc++ -lavformat -lavcodec -lavutil -lswscale -lswresample
|
LDFLAGS += -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lavformat -lavcodec -lavutil -lswscale -lswresample
|
||||||
FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l)
|
FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l)
|
||||||
CMP = 1
|
CMP = 1
|
||||||
endif
|
endif
|
||||||
|
@ -3,7 +3,7 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Camera]
|
[Window][Camera]
|
||||||
Pos=927,11
|
Pos=795,76
|
||||||
Size=259,200
|
Size=259,200
|
||||||
|
|
||||||
[Window][Material]
|
[Window][Material]
|
||||||
@ -19,11 +19,11 @@ Pos=1642,668
|
|||||||
Size=260,143
|
Size=260,143
|
||||||
|
|
||||||
[Window][Debug BVH]
|
[Window][Debug BVH]
|
||||||
Pos=772,16
|
Pos=744,269
|
||||||
Size=274,205
|
Size=274,205
|
||||||
Collapsed=1
|
Collapsed=1
|
||||||
|
|
||||||
[Window][Renderer]
|
[Window][Renderer]
|
||||||
Pos=344,18
|
Pos=374,0
|
||||||
Size=514,500
|
Size=514,500
|
||||||
|
|
||||||
|
@ -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/28 01:20:39 by tomoron ### ########.fr */
|
/* Updated: 2025/01/29 02:34:11 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -44,23 +44,29 @@ class Renderer
|
|||||||
private:
|
private:
|
||||||
void addPoint(void);
|
void addPoint(void);
|
||||||
void makeMovement(float timeFromStart, float curSplitTimeReset);
|
void makeMovement(float timeFromStart, float curSplitTimeReset);
|
||||||
void initRender(std::string filename);
|
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);
|
std::string floatToTime(float timef);
|
||||||
glm::vec2 sphereInterpolate(glm::vec2 from, glm::vec2 to, float time);
|
glm::vec2 sphereInterpolate(glm::vec2 from, glm::vec2 to, float time);
|
||||||
|
void updateAvailableCodecs(void);
|
||||||
|
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
||||||
|
|
||||||
int _min;
|
int _min;
|
||||||
int _sec;
|
int _sec;
|
||||||
int _samples;
|
int _samples;
|
||||||
int _testSamples;
|
int _testSamples;
|
||||||
int _fps;
|
int _fps;
|
||||||
bool _mine;
|
char _filenameBuffer[512];
|
||||||
std::vector<t_pathPoint> _path;
|
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;
|
||||||
|
|
||||||
int _curPathIndex;
|
int _curPathIndex;
|
||||||
int _destPathIndex;
|
int _destPathIndex;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{ pkgs ? import <nixpkgs> {} }:
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
nativeBuildInputs = with pkgs; [ libGL xorg.libX11 libGLU glfw ffmpeg];
|
nativeBuildInputs = with pkgs; [ libGL xorg.libX11 libGLU glfw ffmpeg];
|
||||||
|
shellHook="make -j";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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/01/28 02:19:41 by tomoron ### ########.fr */
|
/* Updated: 2025/01/29 02:43:55 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,17 +24,74 @@ Renderer::Renderer(Scene *scene, Window *win)
|
|||||||
_curSamples = 0;
|
_curSamples = 0;
|
||||||
_destPathIndex = 0;
|
_destPathIndex = 0;
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
|
_outputFilename = "output.mp4";
|
||||||
|
memcpy(_filenameBuffer, _outputFilename.c_str(), _outputFilename.length());
|
||||||
|
_filenameBuffer[_outputFilename.length()] = 0;
|
||||||
|
|
||||||
_rgb_frame = 0;
|
_rgb_frame = 0;
|
||||||
_yuv_frame = 0;
|
_yuv_frame = 0;
|
||||||
_format = 0;
|
_format = 0;
|
||||||
_codec_context = 0;
|
_codec_context = 0;
|
||||||
|
updateAvailableCodecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::initRender(std::string filename)
|
void Renderer::fillGoodCodecList(std::vector<AVCodecID> &lst)
|
||||||
|
{
|
||||||
|
lst.push_back(AV_CODEC_ID_H264);
|
||||||
|
lst.push_back(AV_CODEC_ID_MPEG4);
|
||||||
|
lst.push_back(AV_CODEC_ID_H263);
|
||||||
|
lst.push_back(AV_CODEC_ID_MPEG2VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::updateAvailableCodecs(void)
|
||||||
{
|
{
|
||||||
const AVCodec *codec;
|
const AVCodec *codec;
|
||||||
|
AVCodecContext *ctx;
|
||||||
|
const AVOutputFormat *muxer;
|
||||||
|
const char *format;
|
||||||
|
std::vector<AVCodecID> goodCodecList;
|
||||||
|
|
||||||
|
fillGoodCodecList(goodCodecList);
|
||||||
|
_codecList.clear();
|
||||||
|
_codecListStr.clear();
|
||||||
|
_codecIndex = 0;
|
||||||
|
av_log_set_level(AV_LOG_QUIET);
|
||||||
|
format = _outputFilename.c_str();
|
||||||
|
if(_outputFilename.find(".") != std::string::npos)
|
||||||
|
format += _outputFilename.find(".") + 1;
|
||||||
|
|
||||||
|
muxer = av_guess_format(format, 0, 0);
|
||||||
|
for(std::vector<AVCodecID>::iterator it = goodCodecList.begin(); it != goodCodecList.end(); it++)
|
||||||
|
{
|
||||||
|
codec = avcodec_find_encoder(*it);
|
||||||
|
if(!codec)
|
||||||
|
continue;
|
||||||
|
ctx = avcodec_alloc_context3(codec);
|
||||||
|
if(ctx)
|
||||||
|
{
|
||||||
|
if (avformat_query_codec(muxer, codec->id, FF_COMPLIANCE_STRICT) > 0)
|
||||||
|
{
|
||||||
|
ctx->width = WIDTH;
|
||||||
|
ctx->height = HEIGHT;
|
||||||
|
ctx->time_base = {1, _fps};
|
||||||
|
ctx->framerate = {_fps, 1};
|
||||||
|
ctx->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||||
|
ctx->gop_size = 10;
|
||||||
|
ctx->max_b_frames = 1;
|
||||||
|
if (avcodec_open2(ctx, codec, NULL) == 0)
|
||||||
|
_codecList.push_back(codec);
|
||||||
|
}
|
||||||
|
avcodec_free_context(&ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(auto it = _codecList.begin(); it != _codecList.end(); it++)
|
||||||
|
{
|
||||||
|
_codecListStr.push_back((*it)->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::initRender(void)
|
||||||
|
{
|
||||||
_destPathIndex = _path.size() - 1;
|
_destPathIndex = _path.size() - 1;
|
||||||
_curPathIndex = 0;
|
_curPathIndex = 0;
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
@ -45,12 +102,9 @@ void Renderer::initRender(std::string filename)
|
|||||||
_scene->getCamera()->setPosition(_path[0].pos);
|
_scene->getCamera()->setPosition(_path[0].pos);
|
||||||
_scene->getCamera()->setDirection(_path[0].dir.x, _path[0].dir.y);
|
_scene->getCamera()->setDirection(_path[0].dir.x, _path[0].dir.y);
|
||||||
_win->setFrameCount(-1);
|
_win->setFrameCount(-1);
|
||||||
avformat_alloc_output_context2(&_format, nullptr, nullptr, filename.c_str());
|
avformat_alloc_output_context2(&_format, nullptr, nullptr, _outputFilename.c_str());
|
||||||
codec = avcodec_find_encoder(AV_CODEC_ID_H264);
|
|
||||||
if (!codec)
|
|
||||||
throw std::runtime_error("unable to find H264 audio/video codec, glhf");
|
|
||||||
|
|
||||||
_codec_context = avcodec_alloc_context3(codec);
|
_codec_context = avcodec_alloc_context3(_codecList[_codecIndex]);
|
||||||
_codec_context->width = WIDTH;
|
_codec_context->width = WIDTH;
|
||||||
_codec_context->height = HEIGHT;
|
_codec_context->height = HEIGHT;
|
||||||
_codec_context->time_base = {1, _fps};
|
_codec_context->time_base = {1, _fps};
|
||||||
@ -62,10 +116,10 @@ void Renderer::initRender(std::string filename)
|
|||||||
if (_format->oformat->flags & AVFMT_GLOBALHEADER)
|
if (_format->oformat->flags & AVFMT_GLOBALHEADER)
|
||||||
_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
|
_codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
|
||||||
|
|
||||||
if (avcodec_open2(_codec_context, codec, nullptr) < 0)
|
if (avcodec_open2(_codec_context, _codecList[_codecIndex], nullptr) < 0)
|
||||||
throw std::runtime_error("Failed to open codec");
|
throw std::runtime_error("Failed to open codec");
|
||||||
|
|
||||||
_stream = avformat_new_stream(_format, codec);
|
_stream = avformat_new_stream(_format, _codecList[_codecIndex]);
|
||||||
if (!_stream)
|
if (!_stream)
|
||||||
throw std::runtime_error("Failed to create stream");
|
throw std::runtime_error("Failed to create stream");
|
||||||
_stream->time_base = _codec_context->time_base;
|
_stream->time_base = _codec_context->time_base;
|
||||||
@ -73,8 +127,8 @@ void Renderer::initRender(std::string filename)
|
|||||||
|
|
||||||
if (!(_format->flags & AVFMT_NOFILE))
|
if (!(_format->flags & AVFMT_NOFILE))
|
||||||
{
|
{
|
||||||
if (avio_open(&_format->pb, filename.c_str(), AVIO_FLAG_WRITE) < 0)
|
if (avio_open(&_format->pb, _outputFilename.c_str(), AVIO_FLAG_WRITE) < 0)
|
||||||
throw std::runtime_error("couldn't open " + filename);
|
throw std::runtime_error("couldn't open " + _outputFilename);
|
||||||
}
|
}
|
||||||
(void)avformat_write_header(_format, nullptr);
|
(void)avformat_write_header(_format, nullptr);
|
||||||
|
|
||||||
@ -236,12 +290,10 @@ glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha)
|
|||||||
}
|
}
|
||||||
|
|
||||||
glm::quat eulerToQuaternion(float pitch, float yaw) {
|
glm::quat eulerToQuaternion(float pitch, float yaw) {
|
||||||
std::cout << "input : " << pitch << ", " << yaw << std::endl;
|
|
||||||
glm::quat qPitch = glm::angleAxis(glm::radians(pitch), glm::vec3(1, 0, 0));
|
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 qYaw = glm::angleAxis(glm::radians(yaw), glm::vec3(0, 1, 0));
|
||||||
|
|
||||||
glm::quat result = qYaw* qPitch;
|
glm::quat result = qYaw* qPitch;
|
||||||
std::cout << "output : " << glm::to_string(result) << std::endl;
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,8 +392,14 @@ void Renderer::imguiPathCreation(void)
|
|||||||
ImGui::SliderInt("test spi", &_testSamples, 1, 10);
|
ImGui::SliderInt("test spi", &_testSamples, 1, 10);
|
||||||
ImGui::SliderInt("render spi", &_samples, 1, 1000);
|
ImGui::SliderInt("render spi", &_samples, 1, 1000);
|
||||||
ImGui::SliderInt("render fps", &_fps, 30, 120);
|
ImGui::SliderInt("render fps", &_fps, 30, 120);
|
||||||
ImGui::Checkbox("mine", &_mine);
|
|
||||||
if(_path.size() && ImGui::Button("try full path"))
|
ImGui::Combo("codec", &_codecIndex, _codecListStr.data(), _codecListStr.size());
|
||||||
|
if(ImGui::InputText("file name", _filenameBuffer, 512))
|
||||||
|
{
|
||||||
|
_outputFilename = _filenameBuffer;
|
||||||
|
updateAvailableCodecs();
|
||||||
|
}
|
||||||
|
if(_path.size() > 1 && ImGui::Button("try full path"))
|
||||||
{
|
{
|
||||||
_scene->getCamera()->setPosition(_path[0].pos);
|
_scene->getCamera()->setPosition(_path[0].pos);
|
||||||
_scene->getCamera()->setDirection(_path[0].dir.x, _path[0].dir.y);
|
_scene->getCamera()->setDirection(_path[0].dir.x, _path[0].dir.y);
|
||||||
@ -351,16 +409,16 @@ void Renderer::imguiPathCreation(void)
|
|||||||
_destPathIndex = _path.size() - 1;
|
_destPathIndex = _path.size() - 1;
|
||||||
_testMode = 1;
|
_testMode = 1;
|
||||||
}
|
}
|
||||||
if(_path.size() && ImGui::Button("start render"))
|
if(_path.size() > 1 && _codecList.size() && ImGui::Button("start render"))
|
||||||
{
|
initRender();
|
||||||
initRender("output.mp4");
|
|
||||||
}
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::SliderInt("minutes", &_min, 0, 2);
|
ImGui::SliderInt("minutes", &_min, 0, 2);
|
||||||
ImGui::SliderInt("seconds", &_sec, 0, 60);
|
ImGui::SliderInt("seconds", &_sec, 0, 60);
|
||||||
if(ImGui::Button("add step"))
|
if(ImGui::Button("add step"))
|
||||||
addPoint();
|
addPoint();
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
for(unsigned long i = 0; i < _path.size(); i++)
|
for(unsigned long i = 0; i < _path.size(); i++)
|
||||||
|
@ -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/25 03:09:56 by tomoron ### ########.fr */
|
/* Updated: 2025/01/28 15:15:53 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -71,6 +71,8 @@ void Window::process_input()
|
|||||||
bool up = glfwGetKey(_window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
bool up = glfwGetKey(_window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
||||||
bool down = glfwGetKey(_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
bool down = glfwGetKey(_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||||
|
|
||||||
|
if(_renderer->rendering())
|
||||||
|
return ;
|
||||||
if (forward || backward || left || right || up || down)
|
if (forward || backward || left || right || up || down)
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user