Add skybox rendering support
This commit is contained in:
parent
f6a9d18c5c
commit
f943e4c945
4 changed files with 93 additions and 3 deletions
22
resources/shaders/skybox.frag
Normal file
22
resources/shaders/skybox.frag
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 direction;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D equirect;
|
||||
|
||||
const vec2 inv_atan = vec2(0.15915494309, 0.31830988618);
|
||||
|
||||
vec2 sample_spherical_map(vec3 v) {
|
||||
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
|
||||
uv *= inv_atan;
|
||||
uv += 0.5;
|
||||
return uv;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = sample_spherical_map(normalize(direction));
|
||||
vec3 color = texture(equirect, uv).rgb;
|
||||
frag_color = vec4(color, 1.0);
|
||||
}
|
||||
15
resources/shaders/skybox.vert
Normal file
15
resources/shaders/skybox.vert
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 position;
|
||||
|
||||
uniform mat4 view;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec3 direction;
|
||||
|
||||
void main() {
|
||||
direction = position;
|
||||
vec4 pos = projection * view * vec4(position, 1.0);
|
||||
gl_Position = pos.xyww;
|
||||
}
|
||||
BIN
resources/skyboxes/sky_24_2k.png
Normal file
BIN
resources/skyboxes/sky_24_2k.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
Loading…
Add table
Add a link
Reference in a new issue