mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Accumulation texture
This commit is contained in:
14
srcs/RT.cpp
14
srcs/RT.cpp
@ -21,20 +21,6 @@ int main(int argc, char **argv)
|
||||
|
||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 1);
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||
|
||||
// Material redMaterial = {glm::vec3(1.0f, 0.2f, 0.2f), 1.0, 1.0, 0.0};
|
||||
// scene.addMaterial(&redMaterial);
|
||||
|
||||
// for (int i = 0; i < 150; i++)
|
||||
// {
|
||||
// float angle = (2.0f * M_PI * i) / 150.0f;
|
||||
// float x = 30.0f * cos(angle);
|
||||
// float z = 30.0f * sin(angle);
|
||||
// float y = 2.0f * sin(angle * 3.0f);
|
||||
// glm::vec3 position(x, y, z);
|
||||
// float sphereSize = 0.8f + 0.4f * sin(angle * 2.0f);
|
||||
// scene.addObject(new Sphere(position, sphereSize, 0));
|
||||
// }
|
||||
|
||||
GLuint objectSSBO;
|
||||
glGenBuffers(1, &objectSSBO);
|
||||
|
@ -54,6 +54,8 @@ Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string com
|
||||
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
|
||||
const char *computeCode = loadFileWithIncludes(computePath);
|
||||
|
||||
std::cout << computeCode << std::endl;
|
||||
|
||||
_vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
glShaderSource(_vertex, 1, &vertexCode, NULL);
|
||||
@ -90,7 +92,6 @@ void Shader::attach(void)
|
||||
_program = glCreateProgram();
|
||||
_program_compute = glCreateProgram();
|
||||
|
||||
|
||||
glAttachShader(_program, _vertex);
|
||||
glAttachShader(_program, _fragment);
|
||||
glAttachShader(_program_compute, _compute);
|
||||
@ -98,14 +99,23 @@ void Shader::attach(void)
|
||||
glLinkProgram(_program);
|
||||
glLinkProgram(_program_compute);
|
||||
|
||||
glGenTextures(1, &_outputTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, _outputTexture);
|
||||
glGenTextures(1, &_output_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, _output_texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glBindImageTexture(0, _outputTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
|
||||
glBindImageTexture(0, _output_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
|
||||
|
||||
glGenTextures(1, &_accumulation_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, _accumulation_texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL);
|
||||
glBindImageTexture(1, _accumulation_texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
|
||||
}
|
||||
|
||||
void Shader::checkCompileErrors(GLuint shader)
|
||||
@ -146,7 +156,7 @@ void Shader::setupVertexBuffer(const Vertex* vertices, size_t size)
|
||||
void Shader::drawTriangles(size_t size)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, _outputTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, _output_texture);
|
||||
glUniform1i(glGetUniformLocation(_program, "screenTexture"), 0);
|
||||
|
||||
glBindVertexArray(_screen_VAO);
|
||||
|
@ -64,6 +64,8 @@ void Window::process_input()
|
||||
bool up = glfwGetKey(_window, GLFW_KEY_SPACE) == GLFW_PRESS;
|
||||
bool down = glfwGetKey(_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||
|
||||
if (forward || backward || left || right || up || down)
|
||||
_frameCount = 0;
|
||||
_scene->getCamera()->process_keyboard(forward, backward, left, right, up, down);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user