Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Water current visuals #5922

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bc2a6b6
Some initial work
dligr Feb 14, 2025
b65ba58
Make the visuals mostly work (the code is to be refactored)
dligr Feb 15, 2025
67f5137
Cleanup particle shader
dligr Feb 15, 2025
e06a37d
Make the particle shader formula fully conform to the one in the C#-s…
dligr Feb 15, 2025
e12096e
Replace tabs with spaces, improve wording
dligr Feb 15, 2025
e3c1fe0
Sync particles with currents, for real this time
dligr Feb 16, 2025
43261c0
Slight code cleanup
dligr Feb 16, 2025
221991c
Cleanup more code, update submodules
dligr Feb 16, 2025
d56fe56
Reword a comment
dligr Feb 16, 2025
7aea69b
Fix performance
dligr Feb 16, 2025
84b0899
Remove the unused parameter `pos`
dligr Feb 16, 2025
cbbb108
Make currents vary per-patch (really unbalanced values for now)
dligr Feb 17, 2025
635d072
Make microbes affected by currents
dligr Feb 17, 2025
520d072
Cleanup `MicrobeStage.tscn`
dligr Feb 17, 2025
f82bd42
Slight code cleanup; make the fluid current system run on the main th…
dligr Feb 18, 2025
dfe359e
Rename WaterCurrentDisplay in accordance with previous naming
dligr Feb 19, 2025
9cb50ac
Make some strings into StringNames
dligr Feb 19, 2025
06c8620
Make some shader's variables constant, slightly improve the system code
dligr Feb 19, 2025
b3cad37
Improve a condition
dligr Feb 19, 2025
34b2ea2
Improve noise data handling, re-add current speed (that was accidenta…
dligr Feb 19, 2025
0d03658
Fix linter complaints; implement interpolation for particles' movement
dligr Feb 19, 2025
9174a9b
Add some comments, clean up some code
dligr Feb 19, 2025
051750e
Make water currents affect cells more
dligr Feb 20, 2025
1370036
Fix linter complaints
dligr Feb 20, 2025
6c1b49c
Make particles' size slightly vary
dligr Feb 21, 2025
fd33aa3
Make particles pause when paused
dligr Feb 21, 2025
c9efb68
Fix current particle shader's wrong formula
dligr Feb 21, 2025
5ec59f1
Make particle count a biome parameter
dligr Feb 23, 2025
7bf0875
Merge remote-tracking branch 'origin/master' into current_visuals
dligr Feb 23, 2025
527167f
Update threaded run
dligr Feb 23, 2025
1a9b698
Replace tabs with spaces
dligr Feb 25, 2025
6ce9c8a
Slightly optimize a formula
dligr Feb 25, 2025
b381bbf
Slightly optimize fluid currents system
dligr Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions shaders/CurrentsParticles.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
shader_type particles;
render_mode disable_velocity;

uniform vec3 emission_box_extents;
uniform vec4 colorValue : source_color;
uniform sampler2D alphaCurve : repeat_disable;

uniform float gameTime;

uniform sampler3D noiseDisturbancesX;
uniform sampler3D noiseDisturbancesY;

uniform sampler3D noiseCurrentsX;
uniform sampler3D noiseCurrentsY;

uniform float speed;
uniform float chaoticness;
uniform float scale;

// The following constants should be the same as in FluidCurrentsSystem.cs
const float disturbanceTimescale = 1.0f;
const float currentsTimescale = 1.0f / 500.0f;
const float currentsStretchingMultiplier = 1.0f / 10.0f;
const float disturbanceToCurrentsRatio = 0.15f;
const float minCurrentIntensity = 0.4f;
const float positionScaling = 0.9f;

// Generates a random float and modifies the seed
float rand_from_seed(inout uint seed) {
int k;
int s = int(seed);
if (s == 0) {
s = 305420679;
}
k = s / 127773;
s = 16807 * (s - k * 127773) - 2836 * k;
if (s < 0) {
s += 2147483647;
}
seed = uint(s);
return float(seed % uint(65536)) / 65535.0;
}

uint hash(uint x) {
x = ((x >> uint(16)) ^ x) * uint(73244475);
x = ((x >> uint(16)) ^ x) * uint(73244475);
x = (x >> uint(16)) ^ x;
return x;
}

void start() {
uint base_number = NUMBER;
uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);

CUSTOM = vec4(0.0);
COLOR = colorValue;
TRANSFORM[0].xyz = vec3(1.0, 0.0, 0.0);
TRANSFORM[1].xyz = vec3(0.0, 1.0, 0.0);
TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);
TRANSFORM[3].xyz = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0,
rand_from_seed(alt_seed) * 2.0 - 1.0) * emission_box_extents;
TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
float visibleScale = rand_from_seed(alt_seed) * 0.75f + 0.625f;
TRANSFORM[0].xyz *= visibleScale;
TRANSFORM[1].xyz *= visibleScale;
TRANSFORM[2].xyz *= visibleScale;
}

void process() {
CUSTOM.y += DELTA;
float lifetime_percent = CUSTOM.y / LIFETIME;
if (CUSTOM.y > LIFETIME) {
ACTIVE = false;
}

vec2 current;
{
// The following should strictly conform to the formula in FluidCurrentSystem.cs
vec2 position = TRANSFORM[3].xz * positionScaling * scale;

float disturbanceX = texture(noiseDisturbancesX,
vec3(position, gameTime * chaoticness * disturbanceTimescale) / 64.0f).r;
float disturbanceY = texture(noiseDisturbancesY,
vec3(position, gameTime * chaoticness * disturbanceTimescale) / 64.0f).r;

float currentX = texture(noiseCurrentsX,
vec3(position.x * currentsStretchingMultiplier, position.y, gameTime * currentsTimescale * chaoticness)
/ 64.0f).r;
float currentY = texture(noiseCurrentsY,
vec3(position.x, position.y * currentsStretchingMultiplier, gameTime * currentsTimescale * chaoticness)
/ 64.0f).r;

vec2 disturbances = vec2(disturbanceX, disturbanceY) * 2.0f - 1.0f;
vec2 currents = vec2(currentX, currentY) * 2.0f - 1.0f;

if (abs(currents.x) < minCurrentIntensity)
{
currents.x = 0.0f;
}

if (abs(currents.y) < minCurrentIntensity)
{
currents.y = 0.0f;
}

current = mix(currents, disturbances, disturbanceToCurrentsRatio);
current *= 10.0f * speed;
}

VELOCITY = mix(vec3(current.x, 0.0f, current.y), VELOCITY, 1.0f - DELTA * 2.0f);

TRANSFORM[3].xyz += VELOCITY * DELTA;

vec4 finalColor = colorValue;
finalColor.a *= texture(alphaCurve, vec2(lifetime_percent)).r;
if (speed != 0.0){
// The faster the particle, the more visible it is
finalColor.a *= length(current) / (speed * 10.0f);
}

COLOR = finalColor;
}
2 changes: 1 addition & 1 deletion simulation_parameters/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public static class Constants
/// <summary>
/// The maximum force that can be applied by currents in the fluid system
/// </summary>
public const float MAX_FORCE_APPLIED_BY_CURRENTS = 1200;
public const float MAX_FORCE_APPLIED_BY_CURRENTS = 2000;

public const int TRANSLATION_VERY_INCOMPLETE_THRESHOLD = 30;
public const int TRANSLATION_INCOMPLETE_THRESHOLD = 70;
Expand Down
52 changes: 52 additions & 0 deletions simulation_parameters/microbe_stage/biomes.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.0,
"WaterCurrentChaoticness": 1.2,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 500,
"CompoundCloudBrightness": 1.3,
"GasVolume": 1,
"Conditions": {
Expand Down Expand Up @@ -201,6 +205,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.6,
"WaterCurrentChaoticness": 0.5,
"WaterCurrentScale": 0.6,
"WaterCurrentParticleCount": 350,
"ActiveMusicContexts": [
"PatchVents"
],
Expand Down Expand Up @@ -504,6 +512,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 1.75,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 900,
"ActiveMusicContexts": [
"PatchTidepool"
],
Expand Down Expand Up @@ -751,6 +763,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.75,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 600,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -960,6 +976,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.65,
"WaterCurrentChaoticness": 0.65,
"WaterCurrentScale": 0.9,
"WaterCurrentParticleCount": 400,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -1219,6 +1239,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.8,
"WaterCurrentChaoticness": 0.8,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 450,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -1511,7 +1535,11 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 2.0,
"WaterCurrentScale": 1.0,
"CompoundCloudBrightness": 2.5,
"WaterCurrentParticleCount": 800,
"GasVolume": 1,
"TemperatureVarianceScale": 15,
"Conditions": {
Expand Down Expand Up @@ -1755,6 +1783,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.5,
"WaterCurrentChaoticness": 1.0,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 500,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -2066,6 +2098,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.6,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 450,
"ActiveMusicContexts": [
"PatchIceShelf"
],
Expand Down Expand Up @@ -2348,6 +2384,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 2.5,
"WaterCurrentScale": 1.75,
"WaterCurrentParticleCount": 900,
"CompoundCloudBrightness": 2.5,
"GasVolume": 1,
"TemperatureVarianceScale": 18,
Expand Down Expand Up @@ -2642,6 +2682,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.75,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 450,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -2967,6 +3011,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 1.5,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 750,
"CompoundCloudBrightness": 2.2,
"GasVolume": 1,
"Conditions": {
Expand Down Expand Up @@ -3200,6 +3248,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.0,
"WaterCurrentChaoticness": 1.0,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 500,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down
8 changes: 8 additions & 0 deletions src/microbe_stage/Biome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public class Biome : IRegistryType

public float CompoundCloudBrightness = 1.0f;

public float WaterCurrentSpeed = 1.0f;

public float WaterCurrentChaoticness = 1.0f;

public float WaterCurrentScale = 1.0f;

public int WaterCurrentParticleCount = 300;

/// <summary>
/// Total gas volume of this biome when it is a single patch.
/// </summary>
Expand Down
Loading