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 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 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
3eb5576
Rename a parameter to make the constructor JSON-safe
dligr Mar 4, 2025
91f5d6f
Rename noise files
dligr Mar 4, 2025
abfd8c2
Optimize away some `ConvertToWorld()` calls
dligr Mar 4, 2025
d3fca0c
Slight style improvement
dligr Mar 4, 2025
7eb9e38
Make a method agressively inline, rename a variable
dligr Mar 4, 2025
74a8e4b
Rename some more variables and methods to be consistent with the styl…
dligr Mar 4, 2025
0e71526
Make currents velocity clamping not axis-based
dligr Mar 5, 2025
be9b128
Merge branch 'master' of https://github.com/Revolutionary-Games/Thriv…
dligr Mar 5, 2025
f18f921
Use the positive modulo function
dligr Mar 5, 2025
8de2306
Slight optimization (avoid getter calls)
dligr Mar 5, 2025
de91458
Make interpolation faster, fix particle flickering, tweak a constant
dligr Mar 5, 2025
5563078
Remove a parameterless struct constructor, improve the shader a bit
dligr Mar 5, 2025
79124ae
Add a safety check in case noise images are null
dligr Mar 5, 2025
d33a64c
Remove unused resources
dligr Mar 5, 2025
cdb1ff5
Merge remote-tracking branch 'origin' into current_visuals
dligr Mar 7, 2025
54c8c86
Fix a merge mistake, make particles take speed-up into account
dligr Mar 8, 2025
0569ddd
Make the handling of images being null more efficient, slightly optim…
dligr Mar 8, 2025
082f068
Merge branch 'master' into current_visuals
hhyyrylainen Mar 10, 2025
47a0729
Update src/microbe_stage/systems/FluidCurrentsSystem.cs
hhyyrylainen Mar 10, 2025
d57de04
Fixed heat gradient place in MicrobeStage.tscn
hhyyrylainen Mar 10, 2025
be2b468
Resaved FluidCurrentDisplay.tscn
hhyyrylainen Mar 10, 2025
83886a7
Fixed a few code style things
hhyyrylainen Mar 10, 2025
4c69c8e
Add missing uid for the particle shader
hhyyrylainen Mar 10, 2025
b9e4596
Fix particle position jitter
dligr Mar 10, 2025
7d43f7b
Merge branch 'current_visuals' of https://github.com/Revolutionary-Ga…
dligr Mar 10, 2025
73fd424
Make currents less common
dligr Mar 10, 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
1 change: 1 addition & 0 deletions Thrive.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=carbondioxide/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Carriable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cellulase/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=chaoticness/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Chemereception/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Chemolithoautotrophy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=chemoplast/@EntryIndexedValue">True</s:Boolean>
Expand Down
118 changes: 118 additions & 0 deletions shaders/CurrentsParticles.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
shader_type particles;
render_mode disable_velocity;

uniform vec3 emissionBoxExtents;
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.50f;
const float positionScaling = 0.9f;

// Generates a random float and modifies the seed
float RandFromSeed(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 baseNumber = NUMBER;
uint altSeed = Hash(baseNumber + 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(RandFromSeed(altSeed) * 2.0 - 1.0, RandFromSeed(altSeed) * 2.0 - 1.0,
RandFromSeed(altSeed) * 2.0 - 1.0) * emissionBoxExtents;
TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
float visibleScale = RandFromSeed(altSeed) * 0.75f + 0.625f;
TRANSFORM[0].xyz *= visibleScale;
TRANSFORM[1].xyz *= visibleScale;
TRANSFORM[2].xyz *= visibleScale;
}

void process() {
CUSTOM.y += DELTA;
float lifetimePercent = 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 (pow(currents.x, 2) + pow(currents.y, 2) < minCurrentIntensity)
{
currents = vec2(0.0f);
}

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

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

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

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

COLOR = finalColor;
}
1 change: 1 addition & 0 deletions shaders/CurrentsParticles.gdshader.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://erlcc6rxb1cy
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 @@ -527,6 +535,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 1.75,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 900,
"ActiveMusicContexts": [
"PatchTidepool"
],
Expand Down Expand Up @@ -774,6 +786,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.75,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 600,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -983,6 +999,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.65,
"WaterCurrentChaoticness": 0.65,
"WaterCurrentScale": 0.9,
"WaterCurrentParticleCount": 400,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -1242,6 +1262,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.8,
"WaterCurrentChaoticness": 0.8,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 450,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -1534,6 +1558,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.5,
"WaterCurrentChaoticness": 2.0,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 800,
"CompoundCloudBrightness": 2.5,
"GasVolume": 1,
"TemperatureVarianceScale": 15,
Expand Down Expand Up @@ -1778,6 +1806,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.5,
"WaterCurrentChaoticness": 1.0,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 500,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -2112,6 +2144,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.6,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 450,
"ActiveMusicContexts": [
"PatchIceShelf"
],
Expand Down Expand Up @@ -2394,6 +2430,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 @@ -2688,6 +2728,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 0.75,
"WaterCurrentChaoticness": 0.75,
"WaterCurrentScale": 0.8,
"WaterCurrentParticleCount": 450,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down Expand Up @@ -3036,6 +3080,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 @@ -3269,6 +3317,10 @@
"z": 0.75
}
},
"WaterCurrentSpeed": 1.0,
"WaterCurrentChaoticness": 1.0,
"WaterCurrentScale": 1.0,
"WaterCurrentParticleCount": 500,
"GasVolume": 1,
"Conditions": {
"Chunks": {
Expand Down
6 changes: 3 additions & 3 deletions src/general/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=69 format=3 uid="uid://c1fc2aip6oiqt"]

[ext_resource type="Theme" uid="uid://b4cx0o110g4b6" path="res://src/gui_common/thrive_theme.tres" id="1"]
[ext_resource type="PackedScene" path="res://src/saving/SaveManagerGUI.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://8to431fk1dnp" path="res://src/saving/SaveManagerGUI.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://khgb1ctp1e5o" path="res://src/general/OptionsMenu.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://cl64wvnxs6ivs" path="res://src/gui_common/dialogs/CustomConfirmationDialog.tscn" id="4"]
[ext_resource type="Script" uid="uid://cmmb0y16fbk1e" path="res://src/gui_common/VersionNumber.cs" id="5"]
Expand All @@ -13,7 +13,7 @@
[ext_resource type="Texture2D" uid="uid://dpxsicy6au2mh" path="res://assets/misc/thrive_logo_big.png" id="10"]
[ext_resource type="PackedScene" uid="uid://cqwy12d33agr4" path="res://src/gui_common/CreditsScroll.tscn" id="11"]
[ext_resource type="PackedScene" uid="uid://c120hjc04sice" path="res://src/gui_common/dialogs/LicensesDisplay.tscn" id="12"]
[ext_resource type="PackedScene" path="res://src/gui_common/dialogs/CustomWindow.tscn" id="12_a6o4c"]
[ext_resource type="PackedScene" uid="uid://du8sc8kjirguk" path="res://src/gui_common/dialogs/CustomWindow.tscn" id="12_a6o4c"]
[ext_resource type="Texture2D" uid="uid://bv0644lcfansy" path="res://assets/textures/gui/social_media/discord.png" id="13"]
[ext_resource type="PackedScene" uid="uid://d06pkd2hx1syf" path="res://src/modding/ModManager.tscn" id="14"]
[ext_resource type="PackedScene" uid="uid://2nt57gfubafw" path="res://src/gui_common/dialogs/ErrorDialog.tscn" id="15"]
Expand Down Expand Up @@ -893,7 +893,7 @@ layout_mode = 1

[node name="GUIAnimations" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_wp2ig")
&"": SubResource("AnimationLibrary_wp2ig")
}

[node name="OpenGLWarningPopup" parent="." instance=ExtResource("4")]
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