Skip to content

Commit

Permalink
Re-add water
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Apr 20, 2022
1 parent f357345 commit 2505fb6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/shaders/terrain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ void main() {
vec3 objectColor = vec3(0.5f, 0.4f, 0.3f) * (lengthDeviation / 4 + 1);

float waterTreshold = 0.001 + (noiseValue() * 2 - 1) * 0.00025;
if (waterElevation >= waterTreshold && interpData < 373.15) {
if (waterElevation/planetRadius >= waterTreshold && interpData < 373.15) {
if (interpData < 273.15) {
objectColor = vec3(1.0f, 1.0f, 1.0f);
//objectColor = mix(objectColor, vec3(1.0f, 1.0f, 1.0f), min(waterElevation*1000, 1)); // ice
} else {
objectColor = mix(vec3(0.1f, 0.3f, 0.8f), vec3(0.05f, 0.2f, 0.4f), min(waterElevation*15, 1)); // ocean blue
specularPower = mix(16, 256, min(waterElevation*100, 1));
objectColor = mix(vec3(0.1f, 0.3f, 0.8f), vec3(0.05f, 0.2f, 0.4f), min(waterElevation/planetRadius*15, 1)); // ocean blue
specularPower = mix(16, 256, min(waterElevation/planetRadius*100, 1));
specularStrength = 0.5;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/simulation/planet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ pub const Planet = struct {
const value = radius + perlin.p2do(theta * 3 + 74, phi * 3 + 42, 4) * (radius / 20);

elevation[i / 3] = value;
//waterElev[i / 3] = std.math.max(0, value - radius);
waterElev[i / 3] = 0;
waterElev[i / 3] = std.math.max(0, value - radius);
temperature[i / 3] = (perlin.p2do(theta * 10 + 1, phi * 10 + 1, 6) + 1) * 300; // 0°C
vertices[i / 3] = point.norm();
}
Expand Down Expand Up @@ -298,7 +297,6 @@ pub const Planet = struct {
bufData[i*5+2] = transformedPoint.z();
bufData[i*5+3] = self.temperature[i];
bufData[i*5+4] = self.waterElevation[i];
//bufData[i*5+4] = 0;
}

gl.bindVertexArray(self.vao);
Expand Down Expand Up @@ -355,7 +353,7 @@ pub const Planet = struct {
// TODO: maybe follow a logarithmic distribution?
const radiation = std.math.min(1, temp / 3000 * options.timeScale);

// TODO: conductivity depends on water level
// conductivity depends on water level
const waterCoeff = self.waterElevation[i] / self.radius * 2 + 1;
const conductivity = std.math.min(options.conductivity * waterCoeff * options.timeScale, 1);
const factor = 6 / conductivity;
Expand Down
2 changes: 1 addition & 1 deletion src/states/play.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub const PlayState = struct {
var i: usize = 0;
while (i < simulationSteps) : (i += 1) {
if (self.debug_emitWater) {
planet.waterElevation[123] += 0.05 * self.timeScale;
planet.waterElevation[123] += (planet.radius / 50) * self.timeScale;
}
if (self.debug_suckWater) {
var j: usize = 100;
Expand Down

0 comments on commit 2505fb6

Please sign in to comment.