Commit 600aae88 authored by GERHarcos's avatar GERHarcos

aufhübschung

parent 8b76ad7c
......@@ -6,8 +6,8 @@
int main(int argc, char const* argv[])
{
int width = 640;
int height = 480;
int width = 1024;
int height = 768;
//set width and height according to input parameters
if (argc == 3)
......@@ -20,7 +20,7 @@ int main(int argc, char const* argv[])
if (int inHeight = atoi(argv[1]) < 10000)
{
if (inHeight < 0)
if (inHeight < 0 && inHeight > -10000)
width = -inHeight;
}
}
......
#version 430
/*#version 430
layout (local_size_x = 1, local_size_y = 1) in;
layout (rgba32f, binding = 0) uniform image2D img_output;
......@@ -54,4 +54,44 @@ void main () {
}
// TODO: gl_GlobalInvocationID.xy gives (0,0), but we want it to hold the current Pixel's Position!
// After that, you should check on the Hit-Calculation if it does not give the Sphere Shape.
\ No newline at end of file
// After that, you should check on the Hit-Calculation if it does not give the Sphere Shape.
*/
#version 430
//size of local work group
layout(local_size_x = 1, local_size_y = 1) in;
//internal image format
layout(rgba32f, binding = 0) uniform image2D img_output;
vec3 ray_d = vec3(0.0, 0.0, -1.0); // ortho
vec3 sphere_c = vec3(0.0, 0.0, -10.0);
float sphere_r = 7.07;
void main() {
// base pixel colour for image
vec4 pixel = vec4(1.0, 0.0, 0.0, 1.0);
// get index in global work group i.e x,y position
ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
//
// Raytracing stuff
//
float max_x = 5.0;
float max_y = 5.0;
ivec2 dims = imageSize(img_output); // fetch image dimensions
float x = (float(pixel_coords.x * 2 - dims.x) / dims.x);
float y = (float(pixel_coords.y * 2 - dims.y) / dims.y);
vec3 ray_o = vec3(x * max_x, y * max_y, 0.0);
vec3 omc = ray_o - sphere_c;
float b = dot(ray_d, omc);
float c = dot(omc, omc) - sphere_r * sphere_r;
float bsqmc = b * b - c;
// hit one or both sides
if (bsqmc >= 0.0) {
pixel = vec4(0.4, 0.4, 1.0, 1.0);
}
// output to a specific pixel in the image
imageStore(img_output, pixel_coords, pixel);
}
......@@ -90,16 +90,16 @@ bool rt::rt_window::init(int sizeX, int sizeY, std::string name)
//set vertex data of texture quad
rt_texture_quad = new VertexData[4];
rt_texture_quad[0].position[0] = 1.0;
rt_texture_quad[0].position[0] = -1.0;
rt_texture_quad[0].position[1] = 1.0;
rt_texture_quad[0].position[2] = 0.0;
rt_texture_quad[1].position[0] = -1.0;
rt_texture_quad[1].position[1] = 1.0;
rt_texture_quad[1].position[1] = -1.0;
rt_texture_quad[1].position[2] = 0.0;
rt_texture_quad[2].position[0] = -1.0;
rt_texture_quad[2].position[1] = -1.0;
rt_texture_quad[2].position[0] = 1.0;
rt_texture_quad[2].position[1] = 1.0;
rt_texture_quad[2].position[2] = 0.0;
rt_texture_quad[3].position[0] = 1.0;
......@@ -108,13 +108,13 @@ bool rt::rt_window::init(int sizeX, int sizeY, std::string name)
//-------------------------------init UserData----------------------------------------------------------------
//allocate memory for user data
userData = new UserData;
//userData = new UserData;
//Not necessary
//glfwSetWindowUserPointer(window, (void*)userData);
//set vertex data count
userData->vertexDataCount = 4;
vertexDataCount = 4;
//-------------------------------init Non-Compute Shaders + Program--------------------------------------------------------
//Create the vertex shader:
......@@ -167,28 +167,28 @@ bool rt::rt_window::init(int sizeX, int sizeY, std::string name)
checkError("glUseProgram");
// store program object in context
userData->programObjectNonCompute = programObject;
programObjectNonCompute = programObject;
//initialize the modell
userData->time = glfwGetTime();
time = glfwGetTime();
//-------------------------------init VertexArray + Buffers----------------------------------------------------------------
// create and bind dummy vao... it is needed in desktop OpenGL
glGenVertexArrays(1, &(userData->vertexArrayObject));
glGenVertexArrays(1, &(vertexArrayObject));
checkError("glGenVertexArray");
glBindVertexArray(userData->vertexArrayObject);
glBindVertexArray(vertexArrayObject);
checkError("glBindVertexArray");
// generate a VBO
glGenBuffers(1, &(userData->vertexBufferObject));
glGenBuffers(1, &(vertexBufferObject));
checkError("glGenBuffers");
glBindBuffer(GL_ARRAY_BUFFER, userData->vertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
checkError("glBindBuffer");
//set buffer data
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * userData->vertexDataCount, (const GLvoid*)rt_texture_quad, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * vertexDataCount, (const GLvoid*)rt_texture_quad, GL_STATIC_DRAW);
checkError("glBufferData");
//attribute index, component count, normalize, stride, pointer
......@@ -229,13 +229,11 @@ bool rt::rt_window::init(int sizeX, int sizeY, std::string name)
void rt::rt_window::teardown()
{
glDeleteBuffers(1, &(userData->vertexBufferObject));
glDeleteBuffers(1, &(vertexBufferObject));
checkError("glDeleteBuffers");
glDeleteVertexArrays(1, &(userData->vertexArrayObject));
glDeleteVertexArrays(1, &(vertexArrayObject));
checkError("glDeleteVertexArrays");
delete(userData);
}
void rt::rt_window::error_callback(int error, const char* description)
......@@ -316,16 +314,16 @@ void rt::rt_window::initComputeShader()
glLinkProgram(computeProgram);
checkError("linking program");
userData->programObjectCompute = computeProgram;
programObjectCompute = computeProgram;
}
void rt::rt_window::update()
{
//using compute shader to do the raytracing bit
glUseProgram(userData->programObjectCompute);
glUseProgram(programObjectCompute);
glDispatchCompute((GLuint)windowWidth, (GLuint)windowHeight, 1);
//image needs to be written before it is read
//image needs to be written before it is used
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
/*
......@@ -340,19 +338,7 @@ void rt::rt_window::update()
//Fmod = float modulo, [0.0, 2pi]
userData->angleY = fmod(userData->angleY + (Y_ROT_SPEED * timeDelta), 2 * M_PI);
*/
// get the window size and update quad and texture size if necessary
int tmpWidth = windowWidth;
int tmpHeight = windowHeight;
glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
if (tmpWidth != windowWidth || tmpHeight != windowHeight)
{
throw std::exception("TODO: change quad texture size");
}
// set viewport
glViewport(0, 0, windowWidth, windowHeight);
checkError("glViewport");
}
void rt::rt_window::draw()
......@@ -361,10 +347,10 @@ void rt::rt_window::draw()
glClear(GL_COLOR_BUFFER_BIT);
// use program
glUseProgram(userData->programObjectNonCompute);
glUseProgram(programObjectNonCompute);
checkError("glUseProgram");
glBindVertexArray(userData->vertexArrayObject);
glBindVertexArray(vertexArrayObject);
//set finished texture
glActiveTexture(GL_TEXTURE0);
......@@ -372,7 +358,8 @@ void rt::rt_window::draw()
// draw stuff
// primitive type, start index in array, number of elements to render
glDrawArrays(GL_TRIANGLE_FAN, 0, userData->vertexDataCount);
//glDrawArrays(GL_TRIANGLE_FAN, 0, vertexDataCount);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexDataCount);
checkError("glDrawArrays");
}
......
......@@ -35,19 +35,16 @@ namespace rt
GLfloat texCoords[3];
};
struct UserData
{
GLuint programObjectNonCompute;
GLuint programObjectCompute;
GLuint vertexBufferObject;
GLuint vertexDataCount;
GLuint vertexArrayObject;
double time;
};
//UserData
GLuint programObjectNonCompute;
GLuint programObjectCompute;
GLuint vertexBufferObject;
GLuint vertexDataCount;
GLuint vertexArrayObject;
double time;
//Variables
GLFWwindow* window;
struct UserData* userData;
int windowWidth, windowHeight;
GLuint texture; //for raytracing
struct VertexData* rt_texture_quad; //quad, which the texture is presented on
......
 glCalls.cpp
LINK : D:\Freiberg\Multimeida\Raytracing\mm_raytracer\OpenGL_Raytracer\x64\Debug\OpenGL_Raytracer.exe wurde nicht gefunden oder beim letzten inkrementellen Linkvorgang nicht erstellt; vollständiger Link wird durchgeführt.
OpenGL_Raytracer.vcxproj -> D:\Freiberg\Multimeida\Raytracing\mm_raytracer\OpenGL_Raytracer\x64\Debug\OpenGL_Raytracer.exe
B^D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\GLAD.C
......
B^D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLAD.OBJ|D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLCALLS.OBJ|D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\OPENGL_RAYTRACER.OBJ
......
B^D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLAD.OBJ|D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\GLCALLS.OBJ|D:\FREIBERG\MULTIMEIDA\RAYTRACING\MM_RAYTRACER\OPENGL_RAYTRACER\OPENGL_RAYTRACER\X64\DEBUG\OPENGL_RAYTRACER.OBJ
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment