]> git.localhorst.tv Git - blank.git/commitdiff
some skybox experiments
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 23 Sep 2015 16:21:48 +0000 (18:21 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 23 Sep 2015 16:21:48 +0000 (18:21 +0200)
it's soooooo small :(

assets
src/app/WorldState.cpp
src/app/WorldState.hpp
src/graphics/SkyBox.hpp [new file with mode: 0644]
src/graphics/SkyBoxShader.hpp
src/graphics/shader.cpp
src/graphics/viewport.cpp

diff --git a/assets b/assets
index 7f1ebb8448f866ac28ea14b0dd8792edebedcf5a..b965c835cce06d762c9741f42dee34809bbf6a08 160000 (submodule)
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit 7f1ebb8448f866ac28ea14b0dd8792edebedcf5a
+Subproject commit b965c835cce06d762c9741f42dee34809bbf6a08
index b4f8e645480a63ed783e12776f77f104e246c893..590f6ac9c22c99f0939b48bfaf0c988d095d9a47 100644 (file)
@@ -25,6 +25,7 @@ WorldState::WorldState(
 , chunk_renderer(*interface.GetPlayer().chunks)
 , skeletons()
 , spawner(world, skeletons, gc.seed)
+, sky(env.loader.LoadCubeMap("skybox"))
 , preload(env, chunk_loader, chunk_renderer)
 , unload(env, world.Chunks(), save) {
        TextureIndex tex_index;
@@ -94,6 +95,8 @@ void WorldState::Render(Viewport &viewport) {
        viewport.WorldPosition(player.Transform(player.ChunkCoords()));
        chunk_renderer.Render(viewport);
        world.Render(viewport);
+       sky.Render(viewport);
+
        interface.Render(viewport);
 }
 
index d5eac1980d850a9ce31b98ef8988bf187bc9e9d6..b48d1b9c0e71285012d7dc7bfbdde978a96ca38e 100644 (file)
@@ -5,6 +5,7 @@
 #include "State.hpp"
 #include "UnloadState.hpp"
 #include "../ai/Spawner.hpp"
+#include "../graphics/SkyBox.hpp"
 #include "../model/Skeletons.hpp"
 #include "../ui/Interface.hpp"
 #include "../world/BlockTypeRegistry.hpp"
@@ -50,6 +51,8 @@ private:
        Skeletons skeletons;
        Spawner spawner;
 
+       SkyBox sky;
+
        PreloadState preload;
        UnloadState unload;
 
diff --git a/src/graphics/SkyBox.hpp b/src/graphics/SkyBox.hpp
new file mode 100644 (file)
index 0000000..1254fe2
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef BLANK_GRAPHICS_SKYBOX_HPP_
+#define BLANK_GRAPHICS_SKYBOX_HPP_
+
+#include "CubeMap.hpp"
+#include "../model/SkyBoxModel.hpp"
+
+
+namespace blank {
+
+class Viewport;
+
+class SkyBox {
+
+public:
+       explicit SkyBox(CubeMap &&);
+
+       void Render(Viewport &) noexcept;
+
+private:
+       CubeMap texture;
+       SkyBoxModel model;
+
+};
+
+}
+
+#endif
index 752298e816b258384e02230d454fe9c0b5c9d11f..20adef7d10b14e33ca719a5f6110e75239a78f28 100644 (file)
@@ -15,11 +15,9 @@ public:
 
        void SetTexture(CubeMap &) noexcept;
 
-       void SetM(const glm::mat4 &m) noexcept;
        void SetProjection(const glm::mat4 &p) noexcept;
        void SetView(const glm::mat4 &v) noexcept;
        void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
-       void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
 
        const glm::mat4 &Projection() const noexcept { return projection; }
        const glm::mat4 &View() const noexcept { return view; }
@@ -32,9 +30,7 @@ private:
        glm::mat4 view;
        glm::mat4 vp;
 
-       GLuint m_handle;
-       GLuint mv_handle;
-       GLuint mvp_handle;
+       GLuint vp_handle;
        GLuint sampler_handle;
 
 };
index 62a9c631a1057991899c9f511d78ddd6eb341c28..98da25ab348fb7210ac66eb774c6909eb30d39d7 100644 (file)
@@ -499,22 +499,18 @@ void BlendedSprite::SetBG(const glm::vec4 &v) noexcept {
 SkyBoxShader::SkyBoxShader()
 : program()
 , vp(1.0f)
-, m_handle(0)
-, mv_handle(0)
-, mvp_handle(0)
+, vp_handle(0)
 , sampler_handle(0) {
        program.LoadShader(
                GL_VERTEX_SHADER,
                "#version 330 core\n"
                "layout(location = 0) in vec3 vtx_position;\n"
-               "uniform mat4 M;\n"
-               "uniform mat4 MV;\n"
-               "uniform mat4 MVP;\n"
+               "uniform mat4 VP;\n"
                "out vec3 vtx_viewspace;\n"
                "void main() {\n"
-                       "gl_Position = MVP * vec4(vtx_position, 1);\n"
+                       "gl_Position = VP * vec4(vtx_position, 1);\n"
                        "gl_Position.z = gl_Position.w;\n"
-                       "vtx_viewspace = (MV * vec4(vtx_position, 1)).xyz;\n"
+                       "vtx_viewspace = vtx_position;\n"
                "}\n"
        );
        program.LoadShader(
@@ -533,9 +529,7 @@ SkyBoxShader::SkyBoxShader()
                throw std::runtime_error("link program");
        }
 
-       m_handle = program.UniformLocation("M");
-       mv_handle = program.UniformLocation("MV");
-       mvp_handle = program.UniformLocation("MVP");
+       vp_handle = program.UniformLocation("VP");
        sampler_handle = program.UniformLocation("tex_sampler");
 }
 
@@ -544,17 +538,6 @@ void SkyBoxShader::Activate() noexcept {
        program.Use();
 }
 
-void SkyBoxShader::SetM(const glm::mat4 &M) noexcept {
-       glm::mat4 m(M);
-       m[0].w = 0.0f;
-       m[1].w = 0.0f;
-       m[2].w = 0.0f;
-       m[3] = { 0.0f, 0.0f, 0.0f, 1.0f };
-       program.Uniform(m_handle, m);
-       program.Uniform(mv_handle, view * m);
-       program.Uniform(mvp_handle, vp * m);
-}
-
 void SkyBoxShader::SetTexture(CubeMap &tex) noexcept {
        glActiveTexture(GL_TEXTURE0);
        tex.Bind();
@@ -564,6 +547,7 @@ void SkyBoxShader::SetTexture(CubeMap &tex) noexcept {
 void SkyBoxShader::SetProjection(const glm::mat4 &p) noexcept {
        projection = p;
        vp = p * view;
+       program.Uniform(vp_handle, vp);
 }
 
 void SkyBoxShader::SetView(const glm::mat4 &v) noexcept {
@@ -571,8 +555,9 @@ void SkyBoxShader::SetView(const glm::mat4 &v) noexcept {
        view[0].w = 0.0f;
        view[1].w = 0.0f;
        view[2].w = 0.0f;
-       view[3] = { 0.0f, 0.0f, 0.0f, 1.0f };
+       view[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
        vp = projection * v;
+       program.Uniform(vp_handle, vp);
 }
 
 void SkyBoxShader::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept {
@@ -580,11 +565,6 @@ void SkyBoxShader::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept {
        SetView(v);
 }
 
-void SkyBoxShader::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept {
-       SetVP(v, p);
-       SetM(m);
-}
-
 
 PlainColor::PlainColor()
 : program()
index 875da78d83c6ecb1913f5cfa61a45ebcc0cabbcb..181c97cd7a9d8a5ba9859920abe26c2081aed844 100644 (file)
@@ -1,5 +1,6 @@
 #include "Camera.hpp"
 #include "Canvas.hpp"
+#include "SkyBox.hpp"
 #include "Viewport.hpp"
 
 #include "../app/init.hpp"
@@ -73,6 +74,19 @@ void Canvas::UpdateProjection() noexcept {
 }
 
 
+SkyBox::SkyBox(CubeMap &&tex)
+: texture(std::move(tex))
+, model() {
+       model.LoadUnitBox();
+}
+
+void SkyBox::Render(Viewport &viewport) noexcept {
+       SkyBoxShader &prog = viewport.SkyBoxProgram();
+       prog.SetTexture(texture);
+       model.Draw();
+}
+
+
 Viewport::Viewport()
 : cam()
 , canv()
@@ -140,6 +154,7 @@ void Viewport::Resize(int w, int h) noexcept {
        } else {
                entity_prog.SetProjection(Perspective());
        }
+       sky_prog.SetProjection(Perspective());
        sprite_prog.SetProjection(Ortho());
 }
 
@@ -228,6 +243,7 @@ SkyBoxShader &Viewport::SkyBoxProgram() noexcept {
        if (active_prog != SKY_BOX) {
                sky_prog.Activate();
                DisableBlending();
+               DisableBackfaceCulling();
                EqualDepthTest();
                active_prog = SKY_BOX;
        }
@@ -247,6 +263,7 @@ BlendedSprite &Viewport::SpriteProgram() noexcept {
 void Viewport::WorldPosition(const glm::mat4 &t) noexcept {
        cam.View(glm::inverse(t));
        chunk_prog.SetView(cam.View());
+       sky_prog.SetView(cam.View());
 }
 
 }