aboutsummaryrefslogtreecommitdiff
path: root/src/shader/code
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader/code')
-rw-r--r--src/shader/code/extra.glsl53
-rw-r--r--src/shader/code/interact.glsl2
-rw-r--r--src/shader/code/vertex.glsl52
3 files changed, 102 insertions, 5 deletions
diff --git a/src/shader/code/extra.glsl b/src/shader/code/extra.glsl
new file mode 100644
index 0000000..5ba6207
--- /dev/null
+++ b/src/shader/code/extra.glsl
@@ -0,0 +1,53 @@
+static const std::string EXTRA_SHADER_CODE = R"(
+#version 430
+
+layout (local_size_x = 1, local_size_y = 1) in;
+
+layout (std430, binding=3) buffer bufferFluid { float fluidCells[]; };
+layout (std430, binding=4) buffer bufferExtra { float extraCells[]; };
+
+uniform uint nX;
+uniform uint nY;
+
+const float convLength = 1.0 / float(max(nX,nY));
+
+/// Array indexing
+
+uint indexOfDirection(int i, int j) {
+ return 3*(i+1) + (j+1);
+}
+
+uint indexOfFluidVertex(uint x, uint y) {
+ return 3*nX*y + 3*x;
+}
+
+/// Data access
+
+vec2 getFluidVelocity(uint x, uint y) {
+ const uint idx = indexOfFluidVertex(x, y);
+ return vec2(
+ fluidCells[idx + 0],
+ fluidCells[idx + 1]
+ );
+}
+
+void setFluidExtra(uint x, uint y, float curl) {
+ const uint idx = indexOfFluidVertex(x, y);
+ extraCells[idx + 0] = curl;
+}
+
+void main() {
+ const uint x = gl_GlobalInvocationID.x;
+ const uint y = gl_GlobalInvocationID.y;
+
+ if ( !(x < nX && y < nY) ) {
+ return;
+ }
+
+ // simple central difference discretization of the 2d curl operator
+ const float dxvy = (getFluidVelocity(x+1,y).y - getFluidVelocity(x-1,y).y) / (2*convLength);
+ const float dyvx = (getFluidVelocity(x,y+1).x - getFluidVelocity(x,y-1).x) / (2*convLength);
+
+ setFluidExtra(x, y, dxvy - dyvx);
+}
+)";
diff --git a/src/shader/code/interact.glsl b/src/shader/code/interact.glsl
index 613c4cd..141673a 100644
--- a/src/shader/code/interact.glsl
+++ b/src/shader/code/interact.glsl
@@ -4,6 +4,7 @@ static const std::string INTERACT_SHADER_CODE = R"(
layout (local_size_x = 1, local_size_y = 1) in;
layout (std430, binding=3) buffer bufferFluid { float fluidCells[]; };
+layout (std430, binding=4) buffer bufferExtra { float extraCells[]; };
uniform uint nX;
uniform uint nY;
@@ -62,6 +63,7 @@ int getMaterial(uint x, uint y) {
void setMaterial(uint x, uint y, int m) {
const uint idx = indexOfFluidVertex(x, y);
fluidCells[idx + 2] = m;
+ extraCells[idx + 2] = m;
}
/// Geometry cleanup
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 0f0e07c..5136023 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -11,6 +11,7 @@ uniform uint nX;
uniform uint nY;
uniform bool show_fluid_quality;
+uniform bool show_curl;
uniform int palette_factor;
float unit(float x) {
@@ -65,6 +66,38 @@ vec3 trafficLightPalette(float x) {
}
}
+vec3 blueBlackRedPalette(float x) {
+ if ( x < 0.5 ) {
+ return mix(
+ vec3(0.0, 0.0, 1.0),
+ vec3(0.0, 0.0, 0.0),
+ 2*x
+ );
+ } else {
+ return mix(
+ vec3(0.0, 0.0, 0.0),
+ vec3(1.0, 0.0, 0.0),
+ 2*(x - 0.5)
+ );
+ }
+}
+
+vec3 blackGoldPalette(float x) {
+ return mix(
+ vec3(0.0, 0.0, 0.0),
+ vec3(0.5, 0.35, 0.05),
+ x
+ );
+}
+
+vec3 blueRedPalette(float x) {
+ return mix(
+ vec3(0.0, 0.0, 1.0),
+ vec3(1.0, 0.0, 0.0),
+ x
+ );
+}
+
void main() {
const vec2 idx = fluidVertexAtIndex(gl_VertexID);
@@ -83,12 +116,21 @@ void main() {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
if ( show_fluid_quality ) {
- vs_out.color = trafficLightPalette(restrictedQuality(VertexPosition.y));
+ vs_out.color = trafficLightPalette(
+ restrictedQuality(VertexPosition.y)
+ );
+ } else if ( show_curl ) {
+ const float factor = 1.0 / float(100*palette_factor);
+ if ( abs(VertexPosition.x) > 1.0 ) {
+ vs_out.color = blueBlackRedPalette(
+ 0.5 + (VertexPosition.x * factor)
+ );
+ } else {
+ vs_out.color = vec3(0.0,0.0,0.0);
+ }
} else {
- vs_out.color = mix(
- vec3(-0.5, 0.0, 1.0),
- vec3( 1.0, 0.0, 0.0),
- norm(VertexPosition.xy) / float(palette_factor)
+ vs_out.color = blueRedPalette(
+ norm(VertexPosition.xy) / palette_factor
);
}
}