aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-05-25 19:49:37 +0200
committerAdrian Kummerlaender2018-05-25 19:49:37 +0200
commite516095a425d1c8d5bd9f9004416a6c19bcaf84f (patch)
treec366ffbec08dff8df561f56f6b967fbd05049815
parent727645613619e366ae51a2eaad69793c9e225b05 (diff)
downloadcomputicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar.gz
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar.bz2
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar.lz
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar.xz
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.tar.zst
computicle-e516095a425d1c8d5bd9f9004416a6c19bcaf84f.zip
Dynamically build compute shader from field function
-rw-r--r--src/main.cc16
-rw-r--r--src/shader/compute.glsl11
2 files changed, 16 insertions, 11 deletions
diff --git a/src/main.cc b/src/main.cc
index ceffe67..71d1cbd 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -22,7 +22,7 @@
#include "shader/display_vertex.glsl"
#include "shader/display_fragment.glsl"
-const unsigned int particle_count = 1000;
+const unsigned int particle_count = 2500;
const unsigned int max_ups = 100;
const unsigned int texture_count = 20;
@@ -83,6 +83,13 @@ std::vector<GLfloat> makeInitialParticles(std::size_t count) {
return buffer;
}
+std::string getShaderFunction(const std::string& fx, const std::string& fy) {
+ return COMPUTE_SHADER_CODE
+ + "vec2 f(vec2 v) {"
+ + "return vec2(" + fx + "," + fy + ");"
+ + "}";
+}
+
int main() {
if( !glfwInit() ) {
std::cerr << "Failed to initialize GLFW" << std::endl;
@@ -123,7 +130,12 @@ int main() {
GraphicShader sceneShader(VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE);
- ComputeShader computeShader(COMPUTE_SHADER_CODE);
+ ComputeShader computeShader(
+ getShaderFunction(
+ "cos(v.x*sin(v.y))",
+ "sin(v.x-v.y)"
+ )
+ );
computeShader.workOn(particleBuffer->getBuffer());
GraphicShader displayShader(DISPLAY_VERTEX_SHADER_CODE,
diff --git a/src/shader/compute.glsl b/src/shader/compute.glsl
index 148157b..eaf5579 100644
--- a/src/shader/compute.glsl
+++ b/src/shader/compute.glsl
@@ -6,17 +6,10 @@ layout (std430, binding=1) buffer bufferA{ float data[]; };
uniform vec2 world;
-// vector field definition
-
-vec2 f(vec2 v) {
- return vec2(
- cos(v.x*sin(v.y)),
- sin(v.x-v.y)
- );
-}
-
// ODE solver
+vec2 f(vec2); // field definition is to be appended
+
vec2 explicitEuler(float h, vec2 v) {
return v + h * f(v);
}