Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Univerxel
Univerxel
Commits
bce746ca
Commit
bce746ca
authored
Aug 05, 2020
by
Shu
🍠
Browse files
Merge workers and other fixs
parent
310efea6
Changes
24
Hide whitespace changes
Inline
Side-by-side
TODO.md
View file @
bce746ca
...
...
@@ -43,7 +43,7 @@
-
[ ] ZeroMQ
-
[x] Logger
-
[ ] FastNoiseSIMD / HastyNoise double precision
-
[
] Generation identifier
-
[
x
] Generation
al
identifier
-
[ ] Limit map usage
## Rendering
...
...
content/shaders/Color.fs
View file @
bce746ca
...
...
@@ -6,5 +6,5 @@ layout(location = 0) out vec4 color;
in
vec4
Color
;
void
main
()
{
color
=
Color
;
color
=
vec4
(
Color
.
xyz
,
.
5
)
;
}
\ No newline at end of file
content/shaders/Main.fs
View file @
bce746ca
...
...
@@ -10,14 +10,14 @@ uniform sampler2DArray HOSAtlas;
uniform
mat4
View
;
uniform
vec3
FogColor
;
#
ifdef
BLEND
#
ifdef
GEOMETRY
in
GeometryData
#
else
in
VertexData
#
endif
{
vec3
Position_modelspace
;
#
ifdef
BLEND
#
ifdef
GEOMETRY
flat
uint
Materials
[
3
];
vec3
MaterialRatio
;
#
else
...
...
@@ -39,6 +39,7 @@ vec3 expand(vec3 v) {
}
vec4
getTexture
(
sampler2DArray
sample
,
vec2
UV
)
{
#
ifdef
GEOMETRY
#
ifdef
BLEND
vec4
colx
=
texture
(
sample
,
vec3
(
UV
,
vs
.
Materials
[
0
]));
if
(
vs
.
Materials
[
1
]
==
vs
.
Materials
[
0
])
{
...
...
@@ -50,6 +51,12 @@ vec4 getTexture(sampler2DArray sample, vec2 UV) {
vs
.
Materials
[
2
]
==
vs
.
Materials
[
1
]
?
mix
(
coly
,
colx
,
vs
.
MaterialRatio
.
x
)
:
colx
*
vs
.
MaterialRatio
.
x
+
coly
*
vs
.
MaterialRatio
.
y
+
texture
(
sample
,
vec3
(
UV
,
vs
.
Materials
[
2
]))
*
vs
.
MaterialRatio
.
z
);
}
#
else
int
mainMaterial
=
vs
.
MaterialRatio
.
x
>=
vs
.
MaterialRatio
.
y
?
(
vs
.
MaterialRatio
.
x
>=
vs
.
MaterialRatio
.
z
?
0
:
2
)
:
(
vs
.
MaterialRatio
.
y
>=
vs
.
MaterialRatio
.
z
?
1
:
2
);
return
texture
(
sample
,
vec3
(
UV
,
vs
.
Materials
[
mainMaterial
]));
#
endif
#
else
return
texture
(
sample
,
vec3
(
UV
,
vs
.
Material
));
#
endif
...
...
src/contouring/Abstract.hpp
View file @
bce746ca
...
...
@@ -26,7 +26,9 @@ namespace contouring {
/// Display ImGui config
virtual
void
onGui
()
=
0
;
/// Get options
virtual
std
::
string
getOptions
()
=
0
;
virtual
std
::
string
getOptions
()
const
=
0
;
// Get camera recommended far range
virtual
std
::
pair
<
float
,
float
>
getFarRange
()
const
=
0
;
/// Get buffers in frustum with model matrices
/// @note buffers invalidated after update
...
...
src/contouring/AbstractFlat.cpp
View file @
bce746ca
...
...
@@ -44,7 +44,7 @@ namespace contouring {
loadDistance
=
opt
[
"load_distance"
].
value_or
(
loadDistance
);
keepDistance
=
opt
[
"keep_distance"
].
value_or
(
keepDistance
);
}
std
::
string
AbstractFlat
::
getOptions
()
{
std
::
string
AbstractFlat
::
getOptions
()
const
{
std
::
ostringstream
ss
;
ss
<<
toml
::
table
({
{
"load_distance"
,
loadDistance
},
...
...
@@ -52,6 +52,9 @@ namespace contouring {
});
return
ss
.
str
();
}
std
::
pair
<
float
,
float
>
AbstractFlat
::
getFarRange
()
const
{
return
std
::
make_pair
((
loadDistance
-
1.5
)
*
CHUNK_LENGTH
,
(
keepDistance
+
.5
)
*
CHUNK_LENGTH
);
}
void
AbstractFlat
::
onGui
()
{
ImGui
::
SliderInt
(
"Load Distance"
,
&
loadDistance
,
1
,
keepDistance
);
...
...
src/contouring/AbstractFlat.hpp
View file @
bce746ca
...
...
@@ -13,7 +13,8 @@ namespace contouring {
/// Display ImGui config
void
onGui
()
override
;
std
::
string
getOptions
()
override
;
std
::
string
getOptions
()
const
override
;
std
::
pair
<
float
,
float
>
getFarRange
()
const
override
;
/// Get buffers in frustum with model matrices
/// @note buffers invalidated after update
...
...
@@ -22,8 +23,7 @@ namespace contouring {
protected:
size_t
clear
(
const
voxel_pos
&
,
const
world
::
area_map
&
areas
);
//MAYBE: store position copy
robin_hood
::
unordered_flat_map
<
area_id
,
robin_hood
::
pair
<
area_pos
,
robin_hood
::
unordered_flat_map
<
chunk_pos
,
buffer
::
Abstract
*>>>
buffers
;
robin_hood
::
unordered_map
<
area_id
,
robin_hood
::
pair
<
area_pos
,
robin_hood
::
unordered_map
<
chunk_pos
,
buffer
::
Abstract
*>>>
buffers
;
int
loadDistance
=
3
;
int
keepDistance
=
4
;
...
...
src/contouring/Dummy.hpp
View file @
bce746ca
...
...
@@ -13,7 +13,8 @@ namespace contouring {
void
onUpdate
(
const
area_
<
chunk_pos
>
&
,
const
chunk_pos
&
,
const
world
::
ChunkContainer
&
,
geometry
::
Faces
)
override
{}
void
onNotify
(
const
area_
<
chunk_pos
>
&
,
const
chunk_pos
&
,
const
world
::
ChunkContainer
&
)
override
{}
void
onGui
()
override
{
}
std
::
string
getOptions
()
override
{
return
""
;
}
std
::
string
getOptions
()
const
override
{
return
""
;
}
std
::
pair
<
float
,
float
>
getFarRange
()
const
override
{
return
std
::
make_pair
(
0
,
0
);
}
void
getModels
(
std
::
vector
<
std
::
pair
<
glm
::
mat4
,
buffer
::
Abstract
*
const
>>
&
,
const
std
::
optional
<
geometry
::
Frustum
>&
,
const
glm
::
llvec3
&
,
int
)
override
{
}
};
}
\ No newline at end of file
src/contouring/FlatDualMC.cpp
View file @
bce746ca
...
...
@@ -30,7 +30,7 @@ namespace contouring {
}
FlatDualMC
::~
FlatDualMC
()
{
running
=
false
;
loadQueue
.
notify
();
loadQueue
.
notify
_all
();
for
(
auto
&
worker
:
workers
)
{
if
(
worker
.
joinable
())
...
...
@@ -38,7 +38,7 @@ namespace contouring {
}
}
std
::
string
FlatDualMC
::
getOptions
()
{
std
::
string
FlatDualMC
::
getOptions
()
const
{
std
::
ostringstream
ss
;
ss
<<
toml
::
table
({
{
"load_distance"
,
loadDistance
},
...
...
src/contouring/FlatDualMC.hpp
View file @
bce746ca
...
...
@@ -9,8 +9,6 @@
#include
"../render/buffer/ShortIndexed.hpp"
#include
<thread>
#define REPORT_BUFFER_SIZE 128
using
namespace
data
;
namespace
contouring
{
/// Dual Marching Cube 1:1 contouring
...
...
@@ -23,7 +21,7 @@ namespace contouring {
void
onGui
()
override
;
std
::
string
getOptions
()
override
;
std
::
string
getOptions
()
const
override
;
/// Chunk data change
void
onUpdate
(
const
area_
<
chunk_pos
>
&
,
const
chunk_pos
&
,
const
world
::
ChunkContainer
&
,
geometry
::
Faces
)
override
;
...
...
src/contouring/FlatSurroundingBox.cpp
View file @
bce746ca
...
...
@@ -28,7 +28,7 @@ namespace contouring {
}
FlatSurroundingBox
::~
FlatSurroundingBox
()
{
running
=
false
;
loadQueue
.
notify
();
loadQueue
.
notify
_all
();
for
(
auto
&
worker
:
workers
)
{
if
(
worker
.
joinable
())
...
...
src/contouring/FlatSurroundingBox.hpp
View file @
bce746ca
...
...
@@ -9,8 +9,6 @@
#include
"../render/buffer/ShortIndexed.hpp"
#include
<thread>
#define REPORT_BUFFER_SIZE 128
using
namespace
data
;
namespace
contouring
{
/// Stupid cubes 1:1 contouring
...
...
src/contouring/dualmc.h
View file @
bce746ca
...
...
@@ -14,7 +14,7 @@
#include
<cstdint>
// stl includes
#include
<
unordered_map
>
#include
<
robin_hood.h
>
#include
<vector>
namespace
dualmc
{
...
...
@@ -211,7 +211,7 @@ protected:
};
/// Hash map for shared vertex index computations
st
d
::
unordered_map
<
DualPointKey
,
QuadIndexType
,
DualPointKeyHash
>
pointToIndex
;
robin_hoo
d
::
unordered_map
<
DualPointKey
,
QuadIndexType
,
DualPointKeyHash
>
pointToIndex
;
};
// inline function definitions
...
...
src/control/InputMap.hpp
View file @
bce746ca
#pragma once
#include
<
unordered_map
>
#include
<
robin_hood.h
>
#include
<vector>
#include
<GL/glew.h>
...
...
@@ -37,7 +37,7 @@ public:
private:
GLFWwindow
*
window
;
st
d
::
unordered_map
<
Input
,
int
>
Map
=
{
robin_hoo
d
::
unordered_map
<
Input
,
int
>
Map
=
{
{
Input
::
Forward
,
GLFW_KEY_W
},
{
Input
::
Backward
,
GLFW_KEY_S
},
{
Input
::
Left
,
GLFW_KEY_A
},
...
...
@@ -51,7 +51,7 @@ private:
const
std
::
vector
<
Input
>
Toggles
=
{
Input
::
Mouse
,
Input
::
Debug
,
Input
::
Throw
};
st
d
::
unordered_map
<
Input
,
bool
>
Previous
;
robin_hoo
d
::
unordered_map
<
Input
,
bool
>
Previous
;
bool
PreviousLeft
;
bool
PreviousRight
;
...
...
src/data/safe_priority_queue.hpp
View file @
bce746ca
...
...
@@ -2,7 +2,6 @@
#include
<tuple>
#include
<vector>
#include
<unordered_set>
#include
<robin_hood.h>
#include
<mutex>
#include
<condition_variable>
...
...
@@ -59,9 +58,12 @@ namespace data {
return
map
.
size
();
}
void
notify
()
{
void
notify
_all
()
{
cv
.
notify_all
();
}
void
notify_one
()
{
cv
.
notify_one
();
}
void
wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
...
...
@@ -121,9 +123,12 @@ namespace data {
return
set
.
size
();
}
void
notify
()
{
void
notify
_all
()
{
cv
.
notify_all
();
}
void
notify_one
()
{
cv
.
notify_one
();
}
void
wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
...
...
src/data/safe_queue.hpp
View file @
bce746ca
...
...
@@ -47,9 +47,12 @@ namespace data {
return
queue
.
size
();
}
void
notify
()
{
void
notify
_all
()
{
cv
.
notify_all
();
}
void
notify_one
()
{
cv
.
notify_one
();
}
void
wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
...
...
src/data/safe_unique_queue.hpp
View file @
bce746ca
...
...
@@ -62,9 +62,12 @@ namespace data {
return
set
.
size
();
}
void
notify
()
{
void
notify
_all
()
{
cv
.
notify_all
();
}
void
notify_one
()
{
cv
.
notify_one
();
}
void
wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex
);
...
...
src/render/UI.cpp
View file @
bce746ca
...
...
@@ -79,8 +79,14 @@ UI::Actions UI::draw(options &options, state &state, const reports &reports, GLu
changeRenderer
|=
ImGui
::
Checkbox
(
"PBR"
,
&
options
.
renderer
.
main
.
pbr
);
ImGui
::
SameLine
();
changeRenderer
|=
ImGui
::
Checkbox
(
"Triplanar"
,
&
options
.
renderer
.
main
.
triplanar
);
changeRenderer
|=
ImGui
::
Checkbox
(
"Geometry"
,
&
options
.
renderer
.
main
.
geometry
);
ImGui
::
SameLine
();
changeRenderer
|=
ImGui
::
Checkbox
(
"Blend"
,
&
options
.
renderer
.
main
.
blend
);
if
(
options
.
renderer
.
main
.
geometry
)
{
changeRenderer
|=
ImGui
::
Checkbox
(
"Blend"
,
&
options
.
renderer
.
main
.
blend
);
}
else
{
ImGui
::
TextDisabled
(
"Blend"
);
}
changeRenderer
|=
ImGui
::
Checkbox
(
"Fog"
,
&
options
.
renderer
.
main
.
fog
);
ImGui
::
SameLine
();
...
...
@@ -113,11 +119,6 @@ UI::Actions UI::draw(options &options, state &state, const reports &reports, GLu
if
(
ImGui
::
SliderInt
(
"Load distance"
,
&
options
.
world
.
loadDistance
,
1
,
options
.
world
.
keepDistance
)
|
ImGui
::
SliderInt
(
"Keep distance"
,
&
options
.
world
.
keepDistance
,
options
.
world
.
loadDistance
+
1
,
21
))
{
actions
=
actions
|
Actions
::
World
;
const
auto
far
=
std
::
clamp
(
options
.
camera
.
far
,
(
options
.
world
.
loadDistance
-
1.5
f
)
*
CHUNK_LENGTH
/
options
.
voxel_density
,
(
options
.
world
.
keepDistance
+
.5
f
)
*
CHUNK_LENGTH
/
options
.
voxel_density
);
if
(
far
!=
options
.
camera
.
far
)
{
options
.
camera
.
far
=
far
;
actions
=
actions
|
Actions
::
Camera
;
}
}
if
(
ImGui
::
SliderInt
(
"Voxel density"
,
&
options
.
voxel_density
,
1
,
CHUNK_LENGTH
*
REGION_LENGTH
))
{
options
.
voxel_density
=
pow
(
2
,
ceil
(
log
(
options
.
voxel_density
)
/
log
(
2
)));
...
...
@@ -145,23 +146,31 @@ UI::Actions UI::draw(options &options, state &state, const reports &reports, GLu
ImGui
::
End
();
}
if
(
options
.
show_debug_controls
)
{
ImGui
::
Begin
(
"Debug: Controls"
,
&
options
.
show_debug_controls
,
ImGuiWindowFlags_AlwaysAutoResize
);
const
auto
p
=
state
.
position
.
as_voxel
(
options
.
voxel_density
);
ImGui
::
Text
(
"Position: (%lld, %lld, %lld)"
,
p
.
x
,
p
.
y
,
p
.
z
);
ImGui
::
Separator
();
{
bool
changePerspective
=
false
;
changePerspective
|=
ImGui
::
SliderAngle
(
"FoV"
,
&
options
.
camera
.
fov
,
30
,
110
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Near"
,
&
options
.
camera
.
near
,
0.01
,
10
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Far"
,
&
options
.
camera
.
far
,
(
options
.
world
.
loadDistance
-
1.5
)
*
CHUNK_LENGTH
/
options
.
voxel_density
,
(
options
.
world
.
keepDistance
+
.5
)
*
CHUNK_LENGTH
/
options
.
voxel_density
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Move speed"
,
&
options
.
camera
.
speed
,
0.1
,
50
);
changePerspective
|=
ImGui
::
SliderInt
(
"Sensibility"
,
&
options
.
camera
.
sensibility
,
1
,
100
,
"%d%%"
);
if
(
changePerspective
)
{
actions
=
actions
|
Actions
::
Camera
;
{
const
auto
farRange
=
state
.
contouring
->
getFarRange
();
if
(
options
.
show_debug_controls
)
{
ImGui
::
Begin
(
"Debug: Controls"
,
&
options
.
show_debug_controls
,
ImGuiWindowFlags_AlwaysAutoResize
);
const
auto
p
=
state
.
position
.
as_voxel
(
options
.
voxel_density
);
ImGui
::
Text
(
"Position: (%lld, %lld, %lld)"
,
p
.
x
,
p
.
y
,
p
.
z
);
ImGui
::
Separator
();
{
bool
changePerspective
=
false
;
changePerspective
|=
ImGui
::
SliderAngle
(
"FoV"
,
&
options
.
camera
.
fov
,
30
,
110
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Near"
,
&
options
.
camera
.
near
,
0.01
,
10
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Far"
,
&
options
.
camera
.
far
,
farRange
.
first
/
options
.
voxel_density
,
farRange
.
second
/
options
.
voxel_density
);
changePerspective
|=
ImGui
::
SliderFloat
(
"Move speed"
,
&
options
.
camera
.
speed
,
0.1
,
50
);
changePerspective
|=
ImGui
::
SliderInt
(
"Sensibility"
,
&
options
.
camera
.
sensibility
,
1
,
100
,
"%d%%"
);
if
(
changePerspective
)
{
actions
=
actions
|
Actions
::
Camera
;
}
}
ImGui
::
End
();
}
const
auto
far
=
std
::
clamp
(
options
.
camera
.
far
,
farRange
.
first
/
options
.
voxel_density
,
farRange
.
second
/
options
.
voxel_density
);
if
(
far
!=
options
.
camera
.
far
)
{
options
.
camera
.
far
=
far
;
actions
=
actions
|
Actions
::
Camera
;
}
ImGui
::
End
();
}
if
(
options
.
editor_show
)
{
...
...
src/render/pass/MainProgram.cpp
View file @
bce746ca
...
...
@@ -13,13 +13,16 @@ MainProgram::MainProgram(const MainProgram::options& opts): Program() {
flags
.
emplace_back
(
"TRIPLANAR"
);
if
(
opts
.
fog
)
flags
.
emplace_back
(
"FOG"
);
if
(
opts
.
blend
)
flags
.
emplace_back
(
"BLEND"
);
if
(
opts
.
geometry
)
{
flags
.
emplace_back
(
"GEOMETRY"
);
if
(
opts
.
blend
)
flags
.
emplace_back
(
"BLEND"
);
}
std
::
vector
<
Shader
*>
shaders
;
shaders
.
push_back
(
loadShader
(
GL_VERTEX_SHADER
,
flags
));
shaders
.
push_back
(
loadShader
(
GL_FRAGMENT_SHADER
,
flags
));
if
(
opts
.
blend
)
if
(
opts
.
geometry
)
shaders
.
push_back
(
loadShader
(
GL_GEOMETRY_SHADER
,
flags
));
load
(
shaders
);
...
...
src/render/pass/MainProgram.hpp
View file @
bce746ca
...
...
@@ -12,8 +12,10 @@ namespace pass {
bool
pbr
=
true
;
/// Triplanar texture mapping
bool
triplanar
=
false
;
/// Blend voxel with mixed materials
bool
blend
=
true
;
/// Active geometry pass
bool
geometry
=
true
;
/// Blend voxel with mixed materials (requires geometry)
bool
blend
=
false
;
/// Depth fog
bool
fog
=
true
;
};
...
...
src/state.h
View file @
bce746ca
...
...
@@ -3,7 +3,6 @@
#define UI_MARGIN 5
#define MIN_FPS 24
#define MAX_FPS 240
#define REPORT_BUFFER_SIZE 128
#include
<toml.h>
#include
<fstream>
...
...
@@ -42,6 +41,7 @@ struct options {
renderer
.
mipMapLOD
=
config
[
"render"
][
"texture_quality"
].
value_or
(
renderer
.
mipMapLOD
);
renderer
.
main
.
pbr
=
config
[
"render"
][
"pbr"
].
value_or
(
renderer
.
main
.
pbr
);
renderer
.
main
.
triplanar
=
config
[
"render"
][
"triplanar"
].
value_or
(
renderer
.
main
.
triplanar
);
renderer
.
main
.
geometry
=
config
[
"render"
][
"geometry"
].
value_or
(
renderer
.
main
.
geometry
);
renderer
.
main
.
blend
=
config
[
"render"
][
"blend"
].
value_or
(
renderer
.
main
.
blend
);
renderer
.
main
.
fog
=
config
[
"render"
][
"fog"
].
value_or
(
renderer
.
main
.
fog
);
const
std
::
string
fog
=
config
[
"render"
][
"fog_color"
].
value_or
(
std
::
string
{
"#000000"
});
...
...
@@ -92,6 +92,7 @@ struct options {
{
"texture_quality"
,
renderer
.
mipMapLOD
},
{
"pbr"
,
renderer
.
main
.
pbr
},
{
"triplanar"
,
renderer
.
main
.
triplanar
},
{
"geometry"
,
renderer
.
main
.
geometry
},
{
"blend"
,
renderer
.
main
.
blend
},
{
"fog"
,
renderer
.
main
.
fog
},
{
"fog_color"
,
toHexa
(
renderer
.
clear_color
)},
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment