From 7ab2e09d48a4f705ca966c177f27a20465ba1bcf Mon Sep 17 00:00:00 2001 From: Niklas Birk Date: Wed, 18 Mar 2020 14:07:11 +0100 Subject: [PATCH] vulkan shader --- CMakeLists.txt | 14 +++++++++++--- openglMain.c | 7 +++---- shaders/vulkan/FragmentShader.frag | 9 +++++++++ utils.c | 2 -- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 shaders/vulkan/FragmentShader.frag diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d53b13..e444c4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,17 @@ add_executable(Informatikprojekt_OpenGL openglMain.c ${PROJECT_SOURCES_OPENGL}) add_executable(Informatikprojekt_Vulkan vulkanMain.c ${PROJECT_SOURCES_VULKAN}) # Copy shader file to output directory -configure_file(./shaders/opengl/ComputeShader.glsl ComputeShader.glsl COPYONLY) -configure_file(./shaders/opengl/VertexShader.glsl VertexShader.glsl COPYONLY) -configure_file(./shaders/opengl/FragmentShader.glsl FragmentShader.glsl COPYONLY) +## OpenGL +configure_file(./shaders/opengl/ComputeShader.glsl ./opengl/ComputeShader.glsl COPYONLY) +configure_file(./shaders/opengl/VertexShader.glsl ./opengl/VertexShader.glsl COPYONLY) +configure_file(./shaders/opengl/FragmentShader.glsl ./opengl/FragmentShader.glsl COPYONLY) +## Vulkan +configure_file(./shaders/vulkan/ComputeShader.comp ./vulkan/ComputeShader.comp COPYONLY) +configure_file(./shaders/vulkan/VertexShader.vert ./vulkan/VertexShader.vert COPYONLY) +configure_file(./shaders/vulkan/FragmentShader.frag ./vulkan/FragmentShader.frag COPYONLY) +configure_file(./shaders/vulkan/runCompiler.bat ./vulkan/runCompiler.bat COPYONLY) +execute_process(COMMAND runCompiler.bat WORKING_DIRECTORY ./vulkan) + # Vulkan find_package(Vulkan REQUIRED) diff --git a/openglMain.c b/openglMain.c index f188bda..9ee2ddb 100644 --- a/openglMain.c +++ b/openglMain.c @@ -1,4 +1,3 @@ -#include #include "particlesystem.h" #include "initOpenGL.h" #include "utils.h" @@ -29,9 +28,9 @@ int main() initRandomParticles(e1); /************* SHADER *************/ - const GLchar *computeShaderSource = readFile("ComputeShader.glsl"); - const GLchar *vertexShaderSource = readFile("VertexShader.glsl"); - const GLchar *fragmentShaderSource = readFile("FragmentShader.glsl"); + const GLchar *computeShaderSource = readFile("./opengl/ComputeShader.glsl"); + const GLchar *vertexShaderSource = readFile("./opengl/VertexShader.glsl"); + const GLchar *fragmentShaderSource = readFile("./opengl/FragmentShader.glsl"); GLuint computeShader = compileShader(computeShaderSource, GL_COMPUTE_SHADER); GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER); diff --git a/shaders/vulkan/FragmentShader.frag b/shaders/vulkan/FragmentShader.frag new file mode 100644 index 0000000..b007fd9 --- /dev/null +++ b/shaders/vulkan/FragmentShader.frag @@ -0,0 +1,9 @@ +#version 460 + +layout(location = 0) in vec3 colV; +layout(location = 0) out vec4 colOut; + +void main(void) +{ + colOut = vec4(colV, 1); +} diff --git a/utils.c b/utils.c index 2cdee3b..223d8c5 100644 --- a/utils.c +++ b/utils.c @@ -4,8 +4,6 @@ #include #include "utils.h" -#define BUFFER_SIZE 1024 - char *readFile(char *filename) { FILE *file;