aboutsummaryrefslogtreecommitdiff
path: root/src/shader/code/vertex.glsl
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-04-28 20:41:07 +0200
committerAdrian Kummerlaender2019-04-28 20:41:07 +0200
commitd290dcd50821308a08aed4b1bcd6087e16b0c1ed (patch)
tree0cf975057e20031f9a5f1d7ec513fc624ca15443 /src/shader/code/vertex.glsl
parentecaf665a05bdfcd10937152c378cfaec7cdf1836 (diff)
downloadcompustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.gz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.bz2
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.lz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.xz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.zst
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.zip
More consistent restrictions of display values
Diffstat (limited to 'src/shader/code/vertex.glsl')
-rw-r--r--src/shader/code/vertex.glsl41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 5136023..6ad54cf 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -10,13 +10,11 @@ out VS_OUT {
uniform uint nX;
uniform uint nY;
-uniform bool show_fluid_quality;
+uniform bool show_quality;
uniform bool show_curl;
uniform int palette_factor;
-float unit(float x) {
- return 1.0/(1.0+exp(-x));
-}
+/// Vector utilities
float sq(float x) {
return x*x;
@@ -26,6 +24,8 @@ float norm(vec2 v) {
return sqrt(sq(v.x)+sq(v.y));
}
+/// Array indexing
+
vec2 fluidVertexAtIndex(uint i) {
const float y = floor(float(i) / float(nX));
return vec2(
@@ -34,6 +34,8 @@ vec2 fluidVertexAtIndex(uint i) {
);
}
+/// Material number meaning
+
bool isInactive(int material) {
return material == 0;
}
@@ -42,6 +44,8 @@ bool isWallFrontier(int material) {
return material == 2 || material == 3;
}
+/// Data restriction
+
float restrictedQuality(float quality) {
if ( quality < 0.0 ) {
return 0.0;
@@ -50,7 +54,17 @@ float restrictedQuality(float quality) {
}
}
-vec3 trafficLightPalette(float x) {
+float restrictedCurl(float curl) {
+ if ( abs(curl) < 1.0 ) {
+ return 0.5;
+ } else {
+ return 0.5 + 0.5*min(1.0, curl / (50*palette_factor));
+ }
+}
+
+/// Color palettes
+
+vec3 greenYellowRedPalette(float x) {
if ( x < 0.5 ) {
return mix(
vec3(0.0, 1.0, 0.0),
@@ -98,6 +112,8 @@ vec3 blueRedPalette(float x) {
);
}
+/// Actual vertex shader
+
void main() {
const vec2 idx = fluidVertexAtIndex(gl_VertexID);
@@ -115,19 +131,14 @@ void main() {
} else if ( isWallFrontier(material) ) {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
- if ( show_fluid_quality ) {
- vs_out.color = trafficLightPalette(
+ if ( show_quality ) {
+ vs_out.color = greenYellowRedPalette(
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);
- }
+ vs_out.color = blueBlackRedPalette(
+ restrictedCurl(VertexPosition.x)
+ );
} else {
vs_out.color = blueRedPalette(
norm(VertexPosition.xy) / palette_factor