-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from gue-ni/dev
Dev
- Loading branch information
Showing
8 changed files
with
258 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pre-commit.ps1 | |
CMakeSettings.json | ||
NOTES.txt | ||
imgui.ini | ||
terrain/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function(make_includable input_file output_file) | ||
file(READ ${input_file} content) | ||
set(delim "") | ||
set(content "R\"${delim}(\n${content})${delim}\"") | ||
file(WRITE ${output_file} "${content}") | ||
endfunction(make_includable) | ||
|
||
make_includable( | ||
"${SHADER_DIR}/shaders/sky.frag" | ||
"${SHADER_DIR}/generated/sky.frag") | ||
|
||
make_includable( | ||
"${SHADER_DIR}/shaders/sky.vert" | ||
"${SHADER_DIR}/generated/sky.vert") | ||
|
||
make_includable( | ||
"${SHADER_DIR}/shaders/terrain.vert" | ||
"${SHADER_DIR}/generated/terrain.vert") | ||
|
||
make_includable( | ||
"${SHADER_DIR}/shaders/terrain.frag" | ||
"${SHADER_DIR}/generated/terrain.frag") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#version 430 | ||
|
||
uniform vec3 u_sky_color_1; | ||
uniform vec3 u_sky_color_2; | ||
|
||
out vec4 frag_color; | ||
in vec3 uv; | ||
|
||
#define sq(x) (x * x) | ||
|
||
vec3 map_cube_to_sphere(vec3 point_on_cube) { | ||
float x = point_on_cube.x, y = point_on_cube.y, z = point_on_cube.z; | ||
|
||
vec3 point_on_sphere; | ||
point_on_sphere.x = x * sqrt(1.0f - (sq(y) / 2.0f) - (sq(z) / 2.0f) + ((sq(y) * sq(z)) / 3.0f)); | ||
point_on_sphere.y = y * sqrt(1.0f - (sq(z) / 2.0f) - (sq(x) / 2.0f) + ((sq(z) * sq(x)) / 3.0f)); | ||
point_on_sphere.z = z * sqrt(1.0f - (sq(x) / 2.0f) - (sq(y) / 2.0f) + ((sq(x) * sq(y)) / 3.0f)); | ||
return point_on_sphere; | ||
} | ||
|
||
void main() { | ||
vec3 spherical = map_cube_to_sphere(uv); | ||
|
||
vec3 color = mix(u_sky_color_1, u_sky_color_2, spherical.y); | ||
|
||
vec3 sun_dir = normalize(vec3(0, 1, 2)); | ||
vec3 sun_color = vec3(1.0, 0.9, 0.7); | ||
float sun_factor = max(dot(spherical, sun_dir), 0.0); | ||
|
||
color = mix(color, sun_color, pow(sun_factor, 8.0)); | ||
|
||
frag_color = vec4(color, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#version 430 | ||
layout (location = 0) in vec3 a_pos; | ||
|
||
uniform mat4 u_model; | ||
uniform mat4 u_view; | ||
uniform mat4 u_proj; | ||
|
||
out vec3 uv; | ||
|
||
void main() { | ||
uv = a_pos; | ||
vec4 pos = u_proj * u_view * vec4(a_pos, 1.0); | ||
gl_Position = pos.xyww; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#version 430 | ||
|
||
in vec2 uv; | ||
in vec4 world_pos; | ||
out vec3 out_normal; | ||
|
||
out vec4 frag_color; | ||
|
||
uniform vec2 u_albedo_uv_min; | ||
uniform vec2 u_albedo_uv_max; | ||
uniform sampler2D u_albedo_texture; | ||
uniform vec3 u_fog_color; | ||
uniform float u_fog_near; | ||
uniform float u_fog_far; | ||
uniform float u_fog_density; | ||
uniform vec3 u_camera_position; | ||
uniform uint u_zoom; | ||
uniform bool u_debug_view; | ||
|
||
uint compute_hash(uint a) { | ||
uint b = (a+2127912214u) + (a<<12u); | ||
b = (b^3345072700u) ^ (b>>19u); | ||
b = (b+374761393u) + (b<<5u); | ||
b = (b+3551683692u) ^ (b<<9u); | ||
b = (b+4251993797u) + (b<<3u); | ||
b = (b^3042660105u) ^ (b>>16u); | ||
return b; | ||
} | ||
|
||
vec3 color_from_uint(uint a) { | ||
uint hash = compute_hash(a); | ||
return vec3(float(hash & 255u), float((hash >> 8u) & 255u), float((hash >> 16u) & 255u)) / 255.0; | ||
} | ||
|
||
vec2 map_range(vec2 value, vec2 in_min, vec2 in_max, vec2 out_min, vec2 out_max) { | ||
return out_min + (value - in_min) * (out_max - out_min) / (in_max - in_min); | ||
} | ||
|
||
void main() { | ||
vec2 scaled_uv = map_range(uv, vec2(0), vec2(1), u_albedo_uv_min, u_albedo_uv_max); | ||
|
||
vec3 color = texture(u_albedo_texture, scaled_uv).rgb; | ||
|
||
#if 0 | ||
color = mix(color, vec3(scaled_uv.xy, 0), 0.5); | ||
#endif | ||
|
||
if (u_fog_color != vec3(0)) { | ||
vec3 camera_dir = normalize(u_camera_position - world_pos.xyz); | ||
float camera_dist = length(world_pos.xyz - u_camera_position); | ||
float dist_ratio = 4.0 * camera_dist / u_fog_far; | ||
float fog_factor = 1.0 - exp(-dist_ratio * u_fog_density); | ||
|
||
vec3 sun_dir = normalize(vec3(0, 1, 2)); | ||
vec3 sun_color = vec3(1.0, 0.9, 0.7); | ||
float sun_factor = max(dot(camera_dir, sun_dir), 0.0); | ||
|
||
//vec3 fog_color = mix(u_fog_color, sun_color, pow(sun_factor, 8.0)); | ||
vec3 fog_color = u_fog_color; | ||
|
||
color = mix(color, fog_color, fog_factor); | ||
} | ||
|
||
if (u_debug_view) { | ||
color = mix(color_from_uint(u_zoom), color, 0.5); | ||
} | ||
|
||
// color = out_normal; | ||
|
||
frag_color = vec4(color, 1); | ||
} |
Oops, something went wrong.