MAPVIEW: added skybox and updated the water shader
parent
18c8c53a7b
commit
029ea7c0e1
|
@ -0,0 +1 @@
|
|||
Taken from the LearnOpenGL examples about cubemaps.
|
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
|
@ -14,6 +14,12 @@ set(SRCS_SHADERS
|
|||
shaders/voxel.vert shaders/voxel.frag
|
||||
)
|
||||
set(FILES
|
||||
sky/sky_bk.png
|
||||
sky/sky_dn.png
|
||||
sky/sky_ft.png
|
||||
sky/sky_lf.png
|
||||
sky/sky_rt.png
|
||||
sky/sky_up.png
|
||||
)
|
||||
engine_add_module(TARGET ${LIB} SRCS ${SRCS} ${SRCS_SHADERS} FILES ${FILES} DEPENDENCIES frontend render voxelfont voxelworld)
|
||||
generate_shaders(${LIB} world water world_instanced voxel)
|
||||
|
|
|
@ -55,6 +55,7 @@ void WorldRenderer::shutdown() {
|
|||
_opaqueBuffer.shutdown();
|
||||
_waterBuffer.shutdown();
|
||||
_shadow.shutdown();
|
||||
_skybox.shutdown();
|
||||
_shapeRenderer.shutdown();
|
||||
_shapeBuilder.shutdown();
|
||||
_shapeRendererOcclusionQuery.shutdown();
|
||||
|
@ -376,10 +377,13 @@ int WorldRenderer::renderWorld(const video::Camera& camera, int* vertices) {
|
|||
}
|
||||
drawCallsWorld += renderEntities(camera);
|
||||
{
|
||||
_skybox.bind(video::TextureUnit::Two);
|
||||
core_trace_scoped(WorldRendererRenderWater);
|
||||
video::ScopedShader scoped(_waterShader);
|
||||
_waterShader.setModel(glm::mat4(1.0f));
|
||||
_waterShader.setFocuspos(_focusPos);
|
||||
_waterShader.setCubemap(video::TextureUnit::Two);
|
||||
_waterShader.setCamerapos(camera.position());
|
||||
_waterShader.setLightdir(_shadow.sunDirection());
|
||||
_waterShader.setMaterialblock(_materialBlock);
|
||||
_waterShader.setFogcolor(_clearColor);
|
||||
|
@ -413,6 +417,8 @@ int WorldRenderer::renderWorld(const video::Camera& camera, int* vertices) {
|
|||
_shapeRenderer.render(_aabbMeshes, camera);
|
||||
}
|
||||
|
||||
_skybox.render(camera);
|
||||
|
||||
return drawCallsWorld;
|
||||
}
|
||||
|
||||
|
@ -612,6 +618,10 @@ bool WorldRenderer::init(const glm::ivec2& position, const glm::ivec2& dimension
|
|||
if (!_chrShader.setup()) {
|
||||
return false;
|
||||
}
|
||||
if (!_skybox.init("sky")) {
|
||||
Log::warn("Failed to initialize the sky");
|
||||
return false;
|
||||
}
|
||||
|
||||
const int shaderMaterialColorsArraySize = lengthof(shader::WorldData::MaterialblockData::materialcolor);
|
||||
const int materialColorsArraySize = voxel::getMaterialColors().size();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "render/RandomColorTexture.h"
|
||||
#include "video/ShapeBuilder.h"
|
||||
#include "render/ShapeRenderer.h"
|
||||
#include "render/Skybox.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
|
@ -92,6 +93,8 @@ protected:
|
|||
render::Shadow _shadow;
|
||||
render::RandomColorTexture _colorTexture;
|
||||
|
||||
render::Skybox _skybox;
|
||||
|
||||
video::ShapeBuilder _shapeBuilder;
|
||||
render::ShapeRenderer _shapeRenderer;
|
||||
int32_t _aabbMeshes = -1;
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
// for now they are the same
|
||||
$in vec3 v_pos;
|
||||
$in vec4 v_color;
|
||||
$in float v_ambientocclusion;
|
||||
uniform mat4 u_viewprojection;
|
||||
uniform float u_time;
|
||||
uniform samplerCube u_cubemap;
|
||||
uniform vec3 u_camerapos;
|
||||
|
||||
vec2 calculateShadowTexcoord(vec2 uv) {
|
||||
float offset = cos(u_time / 1000.0) * 0.000125;
|
||||
|
@ -8,4 +13,25 @@ vec2 calculateShadowTexcoord(vec2 uv) {
|
|||
}
|
||||
|
||||
#define CUSTOM_SHADOW_TEXCOORD
|
||||
#include "world.frag"
|
||||
#include "_fog.frag"
|
||||
#include "_shadowmap.frag"
|
||||
|
||||
uniform mediump vec3 u_lightdir;
|
||||
uniform lowp vec3 u_diffuse_color;
|
||||
uniform lowp vec3 u_ambient_color;
|
||||
$out vec4 o_color;
|
||||
|
||||
void main(void) {
|
||||
vec3 fdx = dFdx(v_pos.xyz);
|
||||
vec3 fdy = dFdy(v_pos.xyz);
|
||||
vec3 normal = normalize(cross(fdx, fdy));
|
||||
vec3 I = normalize(vec3(v_pos) - u_camerapos);
|
||||
vec3 R = reflect(I, normal);
|
||||
vec3 cubeColor = texture(u_cubemap, R).rgb;
|
||||
float ndotl1 = dot(normal, u_lightdir);
|
||||
float ndotl2 = dot(normal, -u_lightdir);
|
||||
vec3 diffuse = u_diffuse_color * max(0.0, max(ndotl1, ndotl2));
|
||||
vec3 shadowColor = shadow(u_viewprojection, mix(cubeColor, v_color.rgb, 0.01), diffuse, u_ambient_color);
|
||||
vec3 linearColor = shadowColor * v_ambientocclusion;
|
||||
o_color = fog(v_pos.xyz, linearColor, v_color.a);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue