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

Day/night cycle #154

Merged
merged 25 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
171763b
Basic sun added.
Unarelith Jul 14, 2020
eef600f
Basic moon added.
Unarelith Jul 14, 2020
7fb9d20
Basic day/night cycle added.
Unarelith Jul 14, 2020
10cac46
[Skybox] Now uses its own shader.
Unarelith Jul 14, 2020
1160813
[Skybox] Small tweaks.
Unarelith Jul 14, 2020
0c6e56d
[Skybox] Sun texture added.
Unarelith Jul 14, 2020
e99e45e
[Skybox] Moon texture added.
Unarelith Jul 14, 2020
49f9c1d
[Skybox] Stars added.
Unarelith Jul 15, 2020
6ecb613
[GameTime] Added to centralize time, sunlight intensity and sky color.
Unarelith Jul 16, 2020
ebecc93
[CelestialObject] Now allows to control rotation speed.
Unarelith Jul 16, 2020
f9edb0c
[Config] It's now possible to use fallback AO only while using smooth…
Unarelith Jul 16, 2020
ff60898
[mods/default] Pickaxe is now effective against Glowstone and Redston…
Unarelith Jul 16, 2020
c609f9e
[GameTime] Tick system added.
Unarelith Jul 16, 2020
7ddf58f
[GameTime] 'getCurrentTime' now uses the new tick system.
Unarelith Jul 16, 2020
ad84470
[DebugInfoWidget] Added 'Ticks' and 'Game time'.
Unarelith Jul 17, 2020
6629d3c
[ChatCommandHandler] '/time <add|set>' command added.
Unarelith Jul 17, 2020
dc3107a
[WorldSaveBasicBackend] Now saving game time.
Unarelith Jul 17, 2020
accd1e5
[Config] Added option to disable star rendering.
Unarelith Jul 17, 2020
5dd33ce
Small fixes.
Unarelith Jul 17, 2020
0f91e85
[Lua API] Added moon, sun and stars attributes in sky definition.
Unarelith Jul 17, 2020
5c677aa
[Lua API] Added 'daylight_cycle' in sky definition to control its pre…
Unarelith Jul 17, 2020
36c5660
[Skybox] Stars now follow sky rotation.
Unarelith Jul 17, 2020
7a6c566
[Config] Now using 'Fast' AO setting by default.
Unarelith Jul 17, 2020
5db8f6c
[README.md] Updated.
Unarelith Jul 17, 2020
5f262bf
[ChunkBuilder] Don't apply AO on light sources.
Unarelith Jul 17, 2020
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ The long-term goal of this project is to provide a viable alternative to Minecra

## Project status

This list is non exhaustive.
This list is non complete.

See also the roadmap for 1.0.0 [here](https://github.com/Unarelith/OpenMiner/wiki/Roadmap).

### Implemented features

Expand All @@ -97,15 +99,15 @@ This list is non exhaustive.
- World loading/saving (see [#26](https://github.com/Unarelith/OpenMiner/issues/26))
- Texture pack system (partially implemented, see [#34](https://github.com/Unarelith/OpenMiner/issues/34))
- Entities ([#90](https://github.com/Unarelith/OpenMiner/pull/90))
- Day/night cycle with sun/moon/stars ([#154](https://github.com/Unarelith/OpenMiner/pull/154))

### Missing features

- Fluid propagation ([#62](https://github.com/Unarelith/OpenMiner/issues/62))
- Day/night cycle with sun/moon display ([#73](https://github.com/Unarelith/OpenMiner/issues/73))
- Seed-based worldgen ([#116](https://github.com/Unarelith/OpenMiner/issues/116))
- Cave tunnels ([#118](https://github.com/Unarelith/OpenMiner/issues/118))
- Clouds ([#52](https://github.com/Unarelith/OpenMiner/pull/52))
- Particle system
- Clouds ([#156](https://github.com/Unarelith/OpenMiner/issues/156))
- Particle system ([#155](https://github.com/Unarelith/OpenMiner/issues/155))

## Screenshots

Expand Down
110 changes: 106 additions & 4 deletions docs/lua-api-sky.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ mod:sky {
fog_color = {
day = {50, 153, 204},
},

daylight_cycle = {
speed = 1.0
},

objects = {
sun = {
texture = "texture-sun",
size = 256,
},

moon = {
texture = "texture-moon_phases",
size = 256,
phases = {
count = 8,
size = 32
}
},

stars = {
count = 1000,
size = 4,
}
}
}
```

Expand All @@ -29,9 +54,26 @@ color = {
}
```

Possible values:
Attributes:

- `day`: sky color at midday

### `daylight_cycle`

Day/night cycle parameters.

Example:
```lua
daylight_cycle = {
speed = 1.0
}
```

The example above is the minimal code required to add a day/night cycle to a sky.

Attributes:

- `day`: Sky color at midday
- `speed`: speed of the cycle (default: `1.0`)

### `fog_color`

Expand All @@ -44,9 +86,9 @@ fog_color = {
}
```

Possible values:
Attributes:

- `day`: Fog color at midday
- `day`: fog color at midday

### `id`

Expand All @@ -59,3 +101,63 @@ id = "sky_nether"

IDs are usually of the form `mod:sky` but the `mod:` prefix is prepended automatically so it's not needed.

### `objects`

#### `moon`

Moon attributes table.

Example:
```lua
moon = {
texture = "texture-moon_phases"
size = 256,
phases = {
count = 8,
size = 32
}
},
```

Attributes:

- `texture`: texture to use (without texture, the moon will use this color: (240, 240, 240))
- `size`: size of the moon (default: `256`)
- `phases`
- `count`: amount of phases (default: `1`)
- `size`: size of the phase texture (default: `32`)

#### `sun`

Sun attribute table.

Example:
```lua
sun = {
texture = "texture-sun",
size = 256,
},
```

Attributes:

- `texture`: texture to use (without texture, the sun will use this color: (255, 255, 0))
- `size`: size of the sun (default: `256`)

#### `stars`

Stars attribute table.

Example:
```lua
stars = {
count = 1000,
size = 4,
}
```

Attributes:

- `count`: size of the sun (default: `1000`)
- `size`: size of the sun (default: `4`)

8 changes: 8 additions & 0 deletions docs/network-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ _This packet has no field._

### Clientbound

#### ServerTick

Packet sent at the beginning of every server tick.

| Field name | Field type | Notes |
| ------------- | ----------- | ---------------------------------------------------- |
| Current time | u64 | Current time in the server |

#### ServerClosed

| Field name | Field type | Notes |
Expand Down
2 changes: 1 addition & 1 deletion external/gamekit
6 changes: 6 additions & 0 deletions mods/default/blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ mod:block {
name = "Glowstone",
tiles = "glowstone.png",
is_light_source = true,
groups = {
om_material_stone = 1
},
}

mod:block {
Expand Down Expand Up @@ -338,6 +341,9 @@ mod:block {
id = "redstone_lamp",
name = "Redstone Lamp",
tiles = "redstone_lamp_off.png",
groups = {
om_material_stone = 1
},

states = {
{ is_light_source = true, tiles = "redstone_lamp_on.png" }
Expand Down
25 changes: 25 additions & 0 deletions mods/default/sky.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ mod:sky {
fog_color = {
day = {50, 153, 204},
},

daylight_cycle = {
speed = 1.0
},

objects = {
sun = {
texture = "texture-sun", -- FIXME: Use a path instead like block attribute 'tiles'
size = 256,
},

moon = {
texture = "texture-moon_phases", -- FIXME: ^
size = 256,
phases = {
count = 8,
size = 32
}
},

stars = {
count = 1000,
size = 4,
}
}
}

mod:sky {
Expand Down
6 changes: 5 additions & 1 deletion mods/default/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function register_tool(name, material, mining_speed, harvest_capability)
elseif name == "shovel" then
tool_def.effective_on = {
"group:om_material_dirt",
"group:om_material:sand"
"group:om_material_sand"
}

tool_def.on_item_activated = function(pos, block, player, world, client, server)
Expand All @@ -61,6 +61,10 @@ function register_tool(name, material, mining_speed, harvest_capability)
tool_def.effective_on = {
"group:om_material_wood"
}
elseif name == "pickaxe" then
tool_def.effective_on = {
"group:om_material_stone"
}
end

mod:item(tool_def)
Expand Down
2 changes: 2 additions & 0 deletions resources/config/textures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<texture name="block_destroy" path="resources/textures/block_destroy.png" />
<texture name="font" path="resources/textures/font.png" />
<texture name="menu_background" path="resources/textures/menu_background.png" repeat="true" />
<texture name="moon_phases" path="resources/textures/moon_phases.png" />
<texture name="player" path="resources/textures/player.png" />
<texture name="sun" path="resources/textures/sun.png" />
<texture name="title_screen" path="resources/textures/title_screen.png" />
<texture name="toasts" path="resources/textures/toasts.png" />
<texture name="widgets" path="resources/textures/widgets.png" />
Expand Down
3 changes: 2 additions & 1 deletion resources/shaders/fog.f.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#version 120

uniform vec4 u_fogColor;
uniform vec4 u_skyColor;

vec4 fog(vec4 color, float fogCoord, float fogStart, float fogEnd) {
float fog = clamp((fogEnd - fogCoord) / (fogEnd - fogStart), 0.0, 1.0);

return mix(u_fogColor, color, fog);
return mix(vec4(u_skyColor.r, u_skyColor.g, u_skyColor.b, u_fogColor.a), color, fog);
}

13 changes: 12 additions & 1 deletion resources/shaders/game.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ varying float v_blockFace;
varying float v_dist;

uniform int u_renderDistance;

uniform sampler2D u_tex;

uniform vec4 u_skyColor;
uniform float u_sunlightIntensity;

// Get light color
vec4 light(vec4 color, vec3 lightColor, vec4 lightPosition, float ambientIntensity, float diffuseIntensity);

Expand All @@ -24,6 +28,9 @@ void main() {
float blockFace = floor(v_blockFace + 0.5);
float lightCheck = floor(v_lightValue.x + 0.5);

// Discard if the pixel is too far away
if(blockFace > -1. && v_dist > u_renderDistance) discard;

// Get current pixel color and apply multiplier on grayscale textures
vec4 color = v_color;
if (v_texCoord.x > -0.99 && v_texCoord.y > -0.99) {
Expand All @@ -50,6 +57,8 @@ void main() {

float minBrightness = 2.0 / 16.0;
if (lightCheck != -1.) {
float sunlight = clamp(v_lightValue.x * u_sunlightIntensity, 3, 15);

float ambientIntensity = max(max(v_lightValue.x, v_lightValue.y) / 16.0, minBrightness);
float diffuseIntensity = max(v_lightValue.x, v_lightValue.y) / 32.0;

Expand All @@ -64,7 +73,9 @@ void main() {
if (blockFace == 2. || blockFace == 3.)
ambientIntensity = max(ambientIntensity * 0.9, minBrightness);

color = light(color, vec3(1.0, 1.0, 1.0), v_coord3d, ambientIntensity, diffuseIntensity);
float lightval = clamp(sunlight / 15.0, v_lightValue.y / 15.0, 1.0);

color = light(color, vec3(lightval, lightval, lightval), v_coord3d, ambientIntensity, diffuseIntensity);
}

color.rgb *= v_ambientOcclusion;
Expand Down
2 changes: 1 addition & 1 deletion resources/shaders/game.v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() {
v_lightValue = lightValue;

if (ambientOcclusion != 5) {
const float aovalues[] = float[](0.5, 0.75, 0.9, 1.0);
const float aovalues[] = float[](0.2, 0.45, 0.75, 1.0);
v_ambientOcclusion = aovalues[int(ambientOcclusion)];
} else {
v_ambientOcclusion = 1.0;
Expand Down
27 changes: 27 additions & 0 deletions resources/shaders/skybox.f.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 120

varying vec4 v_color;
varying vec4 v_coord3d;
varying vec2 v_texCoord;

uniform sampler2D u_tex;

uniform vec4 u_skyColor;
uniform vec4 u_starColor;

void main() {
vec4 color = v_color;

if (v_texCoord.x > -0.99 && v_texCoord.y > -0.99) {
color = texture2D(u_tex, v_texCoord);
color += u_skyColor;
}
else if (color.a == 0) {
color = u_starColor;
}

if (color.a < 0.3) discard;

gl_FragColor = color;
}

22 changes: 22 additions & 0 deletions resources/shaders/skybox.v.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#version 120

attribute vec4 color;
attribute vec4 coord3d;
attribute vec2 texCoord;

varying vec4 v_color;
varying vec4 v_coord3d;
varying vec2 v_texCoord;

uniform mat4 u_modelMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_viewMatrix;

void main() {
v_coord3d = u_modelMatrix * vec4(coord3d.xyz, 1.0);
v_color = color;
v_texCoord = texCoord;

gl_Position = u_projectionMatrix * u_viewMatrix * v_coord3d;
}

Binary file added resources/textures/moon_phases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/textures/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading