Browse Source

working marching cubes

Kajetan Johannes Hammerle 3 years ago
parent
commit
b13f74766d
6 changed files with 491 additions and 3 deletions
  1. 403 0
      Game.cpp
  2. 33 0
      Game.h
  3. 13 2
      Main.cpp
  4. 13 1
      meson.build
  5. 16 0
      resources/fragment.fs
  6. 13 0
      resources/vertex.vs

+ 403 - 0
Game.cpp

@@ -0,0 +1,403 @@
+#include <cmath>
+#include <iostream>
+
+#include "Game.h"
+#include "gaming-core/utils/Array.h"
+#include "gaming-core/utils/List.h"
+#include "gaming-core/utils/Random.h"
+#include "gaming-core/utils/Utils.h"
+
+// static GLuint texture3d;
+static List<Vector3, 122880> list;
+static float tData[16][16][16];
+static Array<List<Array<Vector3, 3>, 4>, 256> table;
+static List<Vector3, 50> points;
+
+static int known[15] = {0b00000000, 0b10000000, 0b11000000, 0b10000100,
+                        0b01110000, 0b11110000, 0b01111000, 0b10100101,
+                        0b10110001, 0b01110001, 0b10000010, 0b11000010,
+                        0b01001010, 0b10101010, 0b10110010};
+static Array<List<Array<Vector3, 3>, 4>, 15> knownTable;
+
+static void addCube(int x, int y, int z) {
+    bool b1 = tData[x][y][z] < 0.5f;
+    bool b2 = tData[x + 1][y][z] < 0.5f;
+    bool b3 = tData[x + 1][y][z + 1] < 0.5f;
+    bool b4 = tData[x][y][z + 1] < 0.5f;
+    bool b5 = tData[x][y + 1][z] < 0.5f;
+    bool b6 = tData[x + 1][y + 1][z] < 0.5f;
+    bool b7 = tData[x + 1][y + 1][z + 1] < 0.5f;
+    bool b8 = tData[x][y + 1][z + 1] < 0.5f;
+
+    int index = (b1 << 7) | (b2 << 6) | (b3 << 5) | (b4 << 4) | (b5 << 3) |
+                (b6 << 2) | (b7 << 1) | b8;
+
+    Vector3 v(static_cast<float>(x), static_cast<float>(y),
+              static_cast<float>(z));
+
+    for(int i = 0; i < table[index].getLength(); i++) {
+        list.add(table[index][i][0] + v);
+        list.add(table[index][i][1] + v);
+        list.add(table[index][i][2] + v);
+    }
+
+    // if(b1) {
+    //    list.add(Vector3(x - 0.1f, y + 0.0f, z + 0.0f));
+    //    list.add(Vector3(x + 0.0f, y - 0.1f, z + 0.0f));
+    //    list.add(Vector3(x + 0.0f, y + 0.0f, z - 0.1f));
+    //}
+}
+
+static void addKnownTable(int index, const Vector3& a, const Vector3& b,
+                          const Vector3& c) {
+    Array<Vector3, 3> array;
+    array[0] = a;
+    array[1] = b;
+    array[2] = c;
+    knownTable[index].add(array);
+}
+
+static int swapBits(int index, int a, int b) {
+    int bitA = (index & (1 << a)) != 0;
+    int bitB = (index & (1 << b)) != 0;
+    index &= ~((1 << a) | (1 << b));
+    index |= bitA << b;
+    index |= bitB << a;
+    return index;
+}
+
+static int flipYZ(int index) {
+    index = swapBits(index, 0, 1);
+    index = swapBits(index, 3, 2);
+    index = swapBits(index, 4, 5);
+    index = swapBits(index, 7, 6);
+    return index;
+}
+
+static int flipXY(int index) {
+    index = swapBits(index, 0, 3);
+    index = swapBits(index, 1, 2);
+    index = swapBits(index, 4, 7);
+    index = swapBits(index, 5, 6);
+    return index;
+}
+
+static int rotateY(int index) {
+    index = swapBits(index, 0, 1);
+    index = swapBits(index, 0, 3);
+    index = swapBits(index, 3, 2);
+    index = swapBits(index, 4, 5);
+    index = swapBits(index, 4, 7);
+    index = swapBits(index, 7, 6);
+    return index;
+}
+
+static int rotateZ(int index) {
+    index = swapBits(index, 0, 1);
+    index = swapBits(index, 0, 4);
+    index = swapBits(index, 4, 5);
+    index = swapBits(index, 3, 2);
+    index = swapBits(index, 3, 7);
+    index = swapBits(index, 7, 6);
+    return index;
+}
+
+static int rotateX(int index) {
+    index = swapBits(index, 2, 1);
+    index = swapBits(index, 1, 5);
+    index = swapBits(index, 5, 6);
+    index = swapBits(index, 3, 0);
+    index = swapBits(index, 0, 4);
+    index = swapBits(index, 4, 7);
+    return index;
+}
+
+static void flipYZ(List<Array<Vector3, 3>, 4>& perm) {
+    Matrix m;
+    m.translateX(-0.5f);
+    m.scale(Vector3(-1.0f, 1.0f, 1.0f));
+    m.translateX(0.5f);
+    for(int i = 0; i < perm.getLength(); i++) {
+        perm[i][0] = m * perm[i][0];
+        perm[i][1] = m * perm[i][1];
+        perm[i][2] = m * perm[i][2];
+    }
+}
+
+static void flipXY(List<Array<Vector3, 3>, 4>& perm) {
+    Matrix m;
+    m.translateZ(-0.5f);
+    m.scale(Vector3(1.0f, 1.0f, -1.0f));
+    m.translateZ(0.5f);
+    for(int i = 0; i < perm.getLength(); i++) {
+        perm[i][0] = m * perm[i][0];
+        perm[i][1] = m * perm[i][1];
+        perm[i][2] = m * perm[i][2];
+    }
+}
+
+static void applyMatrix(List<Array<Vector3, 3>, 4>& perm, Matrix& m) {
+    for(int i = 0; i < perm.getLength(); i++) {
+        perm[i][0] = m * perm[i][0];
+        perm[i][1] = m * perm[i][1];
+        perm[i][2] = m * perm[i][2];
+    }
+}
+
+static bool check(int index) {
+    Matrix m;
+    for(int i = 0; i < 15; i++) {
+        List<Array<Vector3, 3>, 4> perm = knownTable[i];
+        int normal = index;
+        for(int h = 0; h < 4; h++) {
+            for(int w = 0; w < 4; w++) {
+                for(int k = 0; k < 4; k++) {
+                    for(int l = 0; l < 2; l++) {
+                        /*if(known[i] == flipXY(flipYZ((normal)))) {
+                            flipYZ(perm);
+                            flipXY(perm);
+                            table[index] = perm;
+                            return false;
+                        } else*/
+                        if(known[i] == normal) {
+                            Matrix m2;
+                            m2.translate(Vector3(-0.5f, -0.5f, -0.5f));
+                            m *= m2;
+                            m.translate(Vector3(0.5f, 0.5f, 0.5f));
+                            applyMatrix(perm, m);
+                            table[index] = perm;
+                            return false;
+                        }
+                        normal = ((~normal) & 0xFF);
+                    }
+                    normal = rotateY(normal);
+                    Matrix m2;
+                    m2.rotateY(-90.0f);
+                    m *= m2;
+                }
+                normal = rotateZ(normal);
+                Matrix m2;
+                m2.rotateZ(90.0f);
+                m *= m2;
+            }
+            normal = rotateX(normal);
+            Matrix m2;
+            m2.rotateX(90.0f);
+            m *= m2;
+        }
+    }
+    return true;
+}
+
+static void generateTable() {
+    addKnownTable(1, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.0f, 0.5f));
+
+    addKnownTable(2, Vector3(0.0f, 0.0f, 0.5f), Vector3(1.0f, 0.0f, 0.5f),
+                  Vector3(0.0f, 0.5f, 0.0f));
+    addKnownTable(2, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+
+    addKnownTable(3, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.0f, 0.5f));
+    addKnownTable(3, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+
+    addKnownTable(4, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+    addKnownTable(4, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+    addKnownTable(4, Vector3(0.0f, 0.5f, 1.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 0.5f, 1.0f));
+
+    addKnownTable(5, Vector3(0.0f, 0.5f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.5f, 1.0f));
+    addKnownTable(5, Vector3(1.0f, 0.5f, 1.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.5f, 1.0f));
+
+    addKnownTable(6, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+    addKnownTable(6, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+    addKnownTable(6, Vector3(0.0f, 0.5f, 1.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(1.0f, 0.5f, 1.0f));
+    addKnownTable(6, Vector3(0.5f, 1.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+
+    addKnownTable(7, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.0f, 0.5f));
+    addKnownTable(7, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+    addKnownTable(7, Vector3(0.5f, 1.0f, 1.0f), Vector3(0.0f, 0.5f, 1.0f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(7, Vector3(0.5f, 1.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+
+    addKnownTable(8, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.0f, 1.0f, 0.5f),
+                  Vector3(0.5f, 1.0f, 1.0f));
+    addKnownTable(8, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(0.5f, 1.0f, 1.0f));
+    addKnownTable(8, Vector3(1.0f, 0.5f, 1.0f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(0.5f, 1.0f, 1.0f));
+    addKnownTable(8, Vector3(1.0f, 0.5f, 1.0f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(1.0f, 0.0f, 0.5f));
+
+    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(9, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(9, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+
+    addKnownTable(10, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 0.0f, 0.5f));
+    addKnownTable(10, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+
+    addKnownTable(11, Vector3(0.0f, 0.0f, 0.5f), Vector3(1.0f, 0.0f, 0.5f),
+                  Vector3(0.0f, 0.5f, 0.0f));
+    addKnownTable(11, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 0.5f, 0.0f));
+    addKnownTable(11, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+
+    addKnownTable(12, Vector3(0.5f, 1.0f, 1.0f), Vector3(1.0f, 0.5f, 1.0f),
+                  Vector3(1.0f, 1.0f, 0.5f));
+    addKnownTable(12, Vector3(0.5f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 0.0f),
+                  Vector3(1.0f, 0.0f, 0.5f));
+    addKnownTable(12, Vector3(0.5f, 1.0f, 0.0f), Vector3(0.0f, 0.5f, 0.0f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+
+    addKnownTable(13, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.5f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(13, Vector3(0.5f, 0.0f, 0.0f), Vector3(0.0f, 1.0f, 0.5f),
+                  Vector3(0.0f, 1.0f, 0.5f));
+    addKnownTable(13, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.5f, 0.0f, 1.0f),
+                  Vector3(0.5f, 1.0f, 1.0f));
+    addKnownTable(13, Vector3(1.0f, 0.0f, 0.5f), Vector3(0.5f, 1.0f, 1.0f),
+                  Vector3(0.5f, 1.0f, 1.0f));
+
+    addKnownTable(14, Vector3(0.0f, 0.5f, 0.0f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(0.0f, 0.5f, 1.0f));
+    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(0.0f, 0.5f, 1.0f));
+    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 0.0f, 0.0f),
+                  Vector3(1.0f, 0.0f, 0.5f));
+    addKnownTable(14, Vector3(1.0f, 1.0f, 0.5f), Vector3(0.5f, 1.0f, 1.0f),
+                  Vector3(0.0f, 0.5f, 1.0f));
+
+    int counter = 0;
+    for(int i = 0; i < 256; i++) {
+        counter += check(i);
+    }
+    std::cout << "Unsupported: " << counter << "\n";
+}
+
+Game::Game(Shader& shader, Buttons& buttons, const Size& size)
+    : shader(shader), buttons(buttons), size(size),
+      frustum(60, 0.1f, 1000.0f, size), up(buttons.add(GLFW_KEY_SPACE, "Up")),
+      down(buttons.add(GLFW_KEY_LEFT_SHIFT, "Down")),
+      left(buttons.add(GLFW_KEY_A, "left")),
+      right(buttons.add(GLFW_KEY_D, "right")),
+      front(buttons.add(GLFW_KEY_W, "front")),
+      back(buttons.add(GLFW_KEY_S, "back")) {
+    shader.use();
+    vertexBuffer.setAttributes(Attributes().addFloat(3));
+
+    generateTable();
+
+    /*Matrix m;
+    m.translate(Vector3(-0.5f, -0.5f, -0.5f));
+    m.rotateX(-90);
+    m.translate(Vector3(0.5f, 0.5f, 0.5f));
+
+    Vector3 v(0.5f, 0.0f, 0.0f);
+    v = m * v;
+    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
+    v = m * v;
+    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
+    v = m * v;
+    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
+    v = m * v;
+    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";*/
+
+    Random r(0);
+    for(int x = 0; x < 16; x++) {
+        for(int y = 0; y < 16; y++) {
+            for(int z = 0; z < 16; z++) {
+                if(x == 0 || x == 15 || y == 0 || y == 15 || z == 0 ||
+                   z == 15) {
+                    tData[x][y][z] = 0.0f;
+                } else {
+                    // tData[x][y][z] = 1.0f;
+                    float sinX = sinf(M_PI * x / 8.0f);
+                    float cosY = cosf(M_PI * y / 8.0f);
+                    float cosZ = cosf(M_PI * z / 8.0f);
+                    tData[x][y][z] = (sinX * sinX + cosY * cosY + cosZ * cosZ) *
+                                     (1.0f / 3.0f);
+                }
+            }
+        }
+    }
+
+    for(int x = 0; x < 15; x++) {
+        for(int y = 0; y < 15; y++) {
+            for(int z = 0; z < 15; z++) {
+                addCube(x, y, z);
+            }
+        }
+    }
+    vertexBuffer.setStaticData(sizeof(Vector3) * list.getLength(),
+                               list.begin());
+
+    /*glGenTextures(1, &texture3d);
+    glBindTexture(GL_TEXTURE_3D, texture3d);
+    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+    glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, 16, 16, 1, 0, GL_RED, GL_FLOAT,
+                 tData);
+    glActiveTexture(GL_TEXTURE0);*/
+}
+
+void Game::render(float lag) {
+    Vector3 interPos = Utils::interpolate(oldPosition, position, lag);
+    shader.setMatrix("proj", frustum.updateProjection().getValues());
+
+    Matrix m;
+    m.translate(interPos);
+    m.translateZ(-30.0f);
+    m.translateX(-8.0f);
+    // m.rotateY(-30.0f);
+    // m.scale(Vector3(0.05f, 0.05f, 1.0f));
+    shader.setMatrix("view", m.getValues());
+
+    vertexBuffer.draw(list.getLength());
+}
+
+void Game::tick() {
+    oldPosition = position;
+    if(up.isDown()) {
+        position -= Vector3(0.0f, 0.5f, 0.0f);
+    }
+    if(down.isDown()) {
+        position += Vector3(0.0f, 0.5f, 0.0f);
+    }
+    if(left.isDown()) {
+        position += Vector3(0.5f, 0.0f, 0.0f);
+    }
+    if(right.isDown()) {
+        position -= Vector3(0.5f, 0.0f, 0.0f);
+    }
+    if(front.isDown()) {
+        position += Vector3(0.0f, 0.0f, 0.5f);
+    }
+    if(back.isDown()) {
+        position -= Vector3(0.0f, 0.0f, 0.5f);
+    }
+}

+ 33 - 0
Game.h

@@ -0,0 +1,33 @@
+#ifndef GAME_H
+#define GAME_H
+
+#include "gaming-core/input/Buttons.h"
+#include "gaming-core/math/Frustum.h"
+#include "gaming-core/utils/Size.h"
+#include "gaming-core/wrapper/Shader.h"
+#include "gaming-core/wrapper/VertexBuffer.h"
+
+class Game final {
+    Shader& shader;
+    Buttons& buttons;
+    const Size& size;
+    VertexBuffer vertexBuffer;
+    Frustum frustum;
+
+    Button& up;
+    Button& down;
+    Button& left;
+    Button& right;
+    Button& front;
+    Button& back;
+    Vector3 oldPosition;
+    Vector3 position;
+
+public:
+    Game(Shader& shader, Buttons& buttons, const Size& size);
+
+    void render(float lag);
+    void tick();
+};
+
+#endif

+ 13 - 2
Main.cpp

@@ -1,8 +1,10 @@
+#include "Game.h"
 #include "gaming-core/input/Buttons.h"
 #include "gaming-core/utils/Clock.h"
 #include "gaming-core/wrapper/GL.h"
 #include "gaming-core/wrapper/GLEW.h"
 #include "gaming-core/wrapper/GLFW.h"
+#include "gaming-core/wrapper/Shader.h"
 #include "gaming-core/wrapper/Window.h"
 #include "gaming-core/wrapper/WindowOptions.h"
 
@@ -26,25 +28,34 @@ int main() {
         return 0;
     }
 
+    Shader shader("resources/vertex.vs", "resources/fragment.fs");
+    if(shader.hasError()) {
+        return 0;
+    }
+
     Buttons buttons(window);
     Clock fps;
 
     window.show();
 
+    Game game(shader, buttons, size);
+
     GL::checkAndPrintError("setup error");
+    GL::enableDepthTesting();
 
     const Clock::Nanos nanosPerTick = 50000000;
     Clock::Nanos lag = 0;
     while(!window.shouldClose()) {
         GL::checkAndPrintError("loop error");
         updateSize(window, size);
-        // call render tick: static_cast<float> (lag) / nanosPerTick;
+        game.render(static_cast<float>(lag) / nanosPerTick);
         window.swapBuffers();
+        GL::clearFramebuffer();
         lag += fps.update();
         while(lag >= nanosPerTick) {
             lag -= nanosPerTick;
             buttons.tick();
-            // call game tick
+            game.tick();
         }
         glfwPollEvents();
     }

+ 13 - 1
meson.build

@@ -1,13 +1,25 @@
 project('spg project', 'cpp')
 
 sources = ['Main.cpp',
+    'Game.cpp',
     'gaming-core/utils/Size.cpp',
     'gaming-core/utils/Clock.cpp',
+    'gaming-core/utils/Random.cpp',
     'gaming-core/wrapper/GLFW.cpp',
     'gaming-core/wrapper/GL.cpp',
     'gaming-core/wrapper/GLEW.cpp',
     'gaming-core/wrapper/Window.cpp',
     'gaming-core/wrapper/WindowOptions.cpp',
+    'gaming-core/wrapper/Shader.cpp',
+    'gaming-core/wrapper/VertexBuffer.cpp',
+    'gaming-core/wrapper/Attributes.cpp',
+    'gaming-core/wrapper/Texture.cpp',
+    'gaming-core/wrapper/TextureFormat.cpp',
+    'gaming-core/math/Frustum.cpp',
+    'gaming-core/math/Plane.cpp',
+    'gaming-core/math/Matrix.cpp',
+    'gaming-core/math/Quaternion.cpp',
+    'gaming-core/math/Vector.cpp',
     'gaming-core/input/Button.cpp',
     'gaming-core/input/Buttons.cpp']
 
@@ -18,4 +30,4 @@ executable('demo',
     sources: sources,
     dependencies : [glewDep, glfwDep],
     include_directories : include_directories('gaming-core'),
-    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])
+    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror', '-Wno-unused-function'])

+ 16 - 0
resources/fragment.fs

@@ -0,0 +1,16 @@
+#version 430
+
+layout (binding = 0) uniform sampler3D samp;
+
+in vec3 varTexture;
+
+out vec4 color;
+
+void main(void) {
+    //float f = texture(samp, varTexture).r;
+    float x = varTexture.x - int(varTexture.x);
+    float y = varTexture.y - int(varTexture.y);
+    float z = varTexture.z - int(varTexture.z);
+    color = vec4(x, y, z, 1.0);
+    //color = vec4(varTexture, 0.0, 1.0);
+}

+ 13 - 0
resources/vertex.vs

@@ -0,0 +1,13 @@
+#version 430
+
+layout (location = 0) in vec3 position;
+
+uniform mat4 proj;
+uniform mat4 view;
+
+out vec3 varTexture;
+
+void main(void) { 
+    gl_Position = proj * view * vec4(position, 1.0);
+    varTexture = position;
+}