浏览代码

begin work on custom intersection shader for default blocks in chunks

Kolja Strohm 2 周之前
父节点
当前提交
cf4e241b75

+ 5 - 32
FactoryCraft/Block.cpp

@@ -22,7 +22,6 @@ Block::Block(const BlockType* zType,
       location(pos),
       maxHP((float)maxHP),
       needRequestModelInfo(needRequestModelInfo),
-      partOfModel(0),
       flowOptions(0),
       distanceToSource(0),
       passable(passable),
@@ -78,11 +77,8 @@ void Block::api(char* message)
             Model3D* mdl = World::INSTANCE->getCurrentTarget();
             if (mdl == this)
             {
-                if (partOfModel)
-                {
-                    World::INSTANCE->zSelectedEffectModel()->setDestroyedState(
-                        1 - hp / maxHP);
-                }
+                World::INSTANCE->zSelectedEffectModel()->setDestroyedState(
+                    1 - hp / maxHP);
             }
             if (mdl) mdl->release();
             break;
@@ -95,28 +91,18 @@ void Block::api(char* message)
             setModelData(currentModelInfo->getModel());
             setSize(currentModelInfo->getSize());
             setModelTextur(currentModelInfo->getTexture());
-            Chunk* zChunk = World::INSTANCE->zChunk(
-                World::INSTANCE->getChunkCenter(location.x, location.y));
-            if (zChunk)
-            {
-                zChunk->setModelChanged(partOfModel);
-            }
             if (old)
             {
                 delete old;
             }
+            // TODO: update chunk gpu data
             break;
         }
     case 2: // update fluid state
         {
             flowOptions = message[1];
             distanceToSource = message[2];
-            Chunk* zChunk = World::INSTANCE->zChunk(
-                World::INSTANCE->getChunkCenter(location.x, location.y));
-            if (zChunk)
-            {
-                zChunk->setModelChanged(partOfModel);
-            }
+            // TODO: update fluid gpu data
         }
     case 3: // update passable and speed modifier
         {
@@ -140,7 +126,7 @@ void Block::setLightData(Direction dir, unsigned char* data, Chunk* zC)
         sideVisible[getDirectionIndex(dir)] = 1;
     else
         sideVisible[getDirectionIndex(dir)] = 0;
-    if (zC) zC->setLightChanged(partOfModel);
+    // TODO: update chunk gpu data
     int sum1 = 0;
     int sum2 = 0;
     int sum3 = 0;
@@ -157,14 +143,6 @@ void Block::setLightData(Direction dir, unsigned char* data, Chunk* zC)
     setAverageLight(average);
 }
 
-void Block::setPartOfModel(int type, bool part)
-{
-    if (part)
-        this->partOfModel |= type;
-    else
-        this->partOfModel &= ~type;
-}
-
 const unsigned char* Block::getLightData(Direction dir) const
 {
     return lightData + getDirectionIndex(dir) * 6;
@@ -264,11 +242,6 @@ Text Block::printLightInfo()
     return result;
 }
 
-int Block::getPartOfModels() const
-{
-    return partOfModel;
-}
-
 char Block::getFlowOptions() const
 {
     return flowOptions;

+ 0 - 3
FactoryCraft/Block.h

@@ -22,7 +22,6 @@ protected:
     Vec3<int> location;
     unsigned char lightData[6 * 6];
     char needRequestModelInfo;
-    int partOfModel;
     char flowOptions;
     char distanceToSource;
     bool passable;
@@ -51,7 +50,6 @@ public:
     void api(char* message);
     void copyLightTo(Block* zB);
     void setLightData(Direction dir, unsigned char* data, Chunk* zC);
-    void setPartOfModel(int type, bool part);
     __int64 getMaxLight() const;
     const unsigned char* getLightData(Direction dir) const;
     bool isVisible() const;
@@ -61,7 +59,6 @@ public:
     const BlockType* zBlockType() const;
     Skeleton* zSkeleton() const;
     Text printLightInfo();
-    int getPartOfModels() const;
     char getFlowOptions() const;
     char getDistanceToSource() const;
     const ModelInfo& getCurrentModelInfo() const;

+ 62 - 165
FactoryCraft/Chunk.cpp

@@ -1,86 +1,21 @@
 #include "Chunk.h"
 
-#include <Shader.h>
-
-#include "ChunkFluidModel.h"
-#include "ChunkGroundModel.h"
 #include "Constants.h"
-#include "CustomDX12API.h"
-#include "FactoryCraftModel.h"
+#include "DX12ChunkData.h"
 #include "Globals.h"
-#include "TransparentChunkGroundModel.h"
 
 Chunk::Chunk(Framework::Point location)
     : ReferenceCounter(),
       location(location),
       isLoading(0),
       lightChanged(0),
-      modelChanged(0),
       bLock(),
       vLock(),
-      aLock()
+      aLock(),
+      dx12Data(new DX12ChunkData(location))
 {
     blocks = new Block*[CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT];
     memset(blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof(Block*));
-    // FactoryCraftModel* ground = new FactoryCraftModel();
-    // Model3DData* chunkModel
-    //    = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
-    // Text("chunk_ground_") + location.x + location.y);
-    // if (!chunkModel)
-    // {
-    //     chunkModel
-    //         = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
-    //             Text("chunk_ground_") + location.x + location.y);
-    // }
-    // chunkModel->setAmbientFactor(0.f);
-    // chunkModel->setDiffusFactor(1.f);
-    // chunkModel->setSpecularFactor(0.f);
-    // chunkModel->setVertecies(0, 0);
-    // ground->setModelData(chunkModel);
-    // ground->setPosition(
-    //     (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
-    // ground->tick(0);
-    // ChunkModelBuilder* groundModel = new ChunkGroundModel(ground, this);
-    // modelBuilders.add(groundModel);
-    // FactoryCraftModel* transparentGround = new FactoryCraftModel();
-    // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
-    //    Text("transparent_chunk_ground_") + location.x + location.y);
-    // if (!chunkModel)
-    //{
-    //    chunkModel
-    //        = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
-    //            Text("transparent_chunk_ground_") + location.x + location.y);
-    //}
-    // chunkModel->setAmbientFactor(0.f);
-    // chunkModel->setDiffusFactor(1.f);
-    // chunkModel->setSpecularFactor(0.f);
-    // chunkModel->setVertecies(0, 0);
-    // transparentGround->setModelData(chunkModel);
-    // transparentGround->setPosition(
-    //    (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
-    // transparentGround->tick(0);
-    // ChunkModelBuilder* transparentGroundModel
-    //    = new TransparentChunkGroundModel(transparentGround, this);
-    // modelBuilders.add(transparentGroundModel);
-    // FactoryCraftModel* fluids = new FactoryCraftModel();
-    // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
-    //    Text("chunk_fluids_") + location.x + location.y);
-    // if (!chunkModel)
-    //{
-    //    chunkModel
-    //        = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
-    //            Text("chunk_fluids_") + location.x + location.y);
-    //}
-    // chunkModel->setAmbientFactor(0.f);
-    // chunkModel->setDiffusFactor(1.f);
-    // chunkModel->setSpecularFactor(0.f);
-    // chunkModel->setVertecies(0, 0);
-    // fluids->setModelData(chunkModel);
-    // fluids->setPosition(
-    //    (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
-    // fluids->tick(0);
-    // ChunkModelBuilder* fluidModel = new ChunkFluidModel(fluids, this);
-    // modelBuilders.add(fluidModel);
 }
 
 Chunk::Chunk(Framework::Point location, Framework::StreamReader* zReader)
@@ -111,6 +46,7 @@ Chunk::~Chunk()
     }
     delete[] blocks;
     bLock.unlockWrite();
+    dx12Data->release();
 }
 
 void Chunk::appendAnimation(
@@ -197,12 +133,13 @@ void Chunk::load(Framework::StreamReader* zReader)
             bLock.unlockWrite();
             if (b->isVisible())
             {
-                if (!blockTypes[id]->getModelInfo().getModelName().isEqual(
-                        "cube")
-                    && !blockTypes[id]->getModelInfo().getModelName().isEqual(
-                        "grass"))
+                if (blockTypes[id]->getModelInfo().getModelName().isEqual(
+                        "cube"))
+                {
+                    dx12Data->setBlock(index, b);
+                }
+                else
                 {
-                    b->tick(0);
                     vLock.lockWrite();
                     visibleBlocks.add(b);
                     vLock.unlockWrite();
@@ -350,25 +287,8 @@ void Chunk::load(Framework::StreamReader* zReader)
     isLoading = 0;
 }
 
-// void Chunk::buildModel(ChunkModelBuilder* builder)
-//{
-//     modelChanged &= ~builder->getType();
-//     lightChanged &= ~builder->getType();
-//     builder->buildModel();
-// }
-
-// void Chunk::updateLight(ChunkModelBuilder* builder)
-//{
-//     lightChanged &= ~builder->getType();
-//     builder->updateLightning();
-// }
-
 void Chunk::forAll(std::function<void(Model3D*)> f)
 {
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     f(builder->zModel());
-    // }
     vLock.lockRead();
     for (Block* b : visibleBlocks)
     {
@@ -379,21 +299,7 @@ void Chunk::forAll(std::function<void(Model3D*)> f)
 
 bool Chunk::tick(std::function<void(Model3D*)> f, double time)
 {
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     if ((modelChanged | builder->getType()) == modelChanged)
-    //         buildModel(builder);
-    // }
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     if ((lightChanged | builder->getType()) == lightChanged)
-    //         updateLight(builder);
-    // }
     bool res = 0;
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     res |= builder->zModel()->tick(time);
-    // }
     aLock.lockRead();
     auto iterator = animations.begin();
     while (iterator)
@@ -419,22 +325,16 @@ bool Chunk::tick(std::function<void(Model3D*)> f, double time)
         ++iterator;
     }
     aLock.unlockRead();
+    vLock.lockRead();
+    for (Block* b : visibleBlocks)
+    {
+        res |= b->tick(time);
+    }
+    vLock.unlockRead();
     return 1;
 }
 
-void Chunk::destroy()
-{
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     Model3DData* chunkModel = builder->zModel()->zModelData();
-    //     // remove old model
-    //     while (chunkModel->getPolygonCount() > 0)
-    //     {
-    //         chunkModel->removePolygon(0);
-    //     }
-    //     chunkModel->setVertecies(0, 0);
-    // }
-}
+void Chunk::destroy() {}
 
 void Chunk::api(char* message)
 {
@@ -534,83 +434,80 @@ void Chunk::setBlock(Block* block)
     if (pos.x < 0) pos.x += CHUNK_SIZE;
     if (pos.y < 0) pos.y += CHUNK_SIZE;
     int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
-    int affectsGround = 0;
-    int newAffectsGround = 0;
     bLock.lockWrite();
-    // for (ChunkModelBuilder* builder : modelBuilders)
-    //{
-    //     if (block && builder->isPartOfModel(block))
-    //     {
-    //         newAffectsGround |= builder->getType();
-    //     }
-    //     if (blocks[index] && builder->isPartOfModel(blocks[index]))
-    //     {
-    //         affectsGround |= builder->getType();
-    //     }
-    // }
     if (blocks[index])
     {
-        vLock.lockWrite();
-        for (Framework::ArrayIterator<Block*> vi = visibleBlocks.begin(); vi;
-            vi++)
+        if (!blocks[index]->zBlockType()->getModelInfo().getModelName().isEqual(
+                "cube"))
         {
-            if (blocks[index] == (Block*)vi)
+            vLock.lockWrite();
+            for (Framework::ArrayIterator<Block*> vi = visibleBlocks.begin();
+                vi;
+                vi++)
             {
-                vi.remove();
-                break;
+                if (blocks[index] == (Block*)vi)
+                {
+                    vi.remove();
+                    break;
+                }
             }
+            vLock.unlockWrite();
         }
-        vLock.unlockWrite();
         blocks[index]->copyLightTo(block);
         blocks[index]->release();
-        blocks[index] = block;
-        bLock.unlockWrite();
-        modelChanged |= affectsGround | newAffectsGround;
-        if (block && block->isVisible() && !newAffectsGround)
+    }
+    blocks[index] = block;
+    bLock.unlockWrite();
+    if (block && block->isVisible())
+    {
+        if (block->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
+        {
+            dx12Data->setBlock(index, block);
+        }
+        else
         {
-            block->tick(0);
+            dx12Data->setBlock(index, 0);
             vLock.lockWrite();
             visibleBlocks.add(block);
             vLock.unlockWrite();
         }
-        return;
     }
-    blocks[index] = block;
-    bLock.unlockWrite();
-    modelChanged |= affectsGround | newAffectsGround;
-    if (block && block->isVisible() && !newAffectsGround)
+    else
     {
-        block->tick(0);
-        vLock.lockWrite();
-        visibleBlocks.add(block);
-        vLock.unlockWrite();
+        dx12Data->setBlock(index, 0);
     }
 }
 
 void Chunk::removeBlock(Block* zBlock)
 {
-    vLock.lockWrite();
-    for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
-        iterator;
-        iterator++)
+    if (!zBlock->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
     {
-        if (zBlock == (Block*)iterator)
+        vLock.lockWrite();
+        for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
+            iterator;
+            iterator++)
         {
-            iterator.remove();
-            break;
+            if (zBlock == (Block*)iterator)
+            {
+                iterator.remove();
+                break;
+            }
         }
+        vLock.unlockWrite();
     }
-    vLock.unlockWrite();
     Vec3<int> pos = zBlock->getLocation();
     pos.x = pos.x % CHUNK_SIZE;
     pos.y = pos.y % CHUNK_SIZE;
     if (pos.x < 0) pos.x += CHUNK_SIZE;
     if (pos.y < 0) pos.y += CHUNK_SIZE;
     int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
+    if (zBlock->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
+    {
+        dx12Data->setBlock(index, 0);
+    }
     bLock.lockWrite();
     if (blocks[index])
     {
-        modelChanged |= blocks[index]->getPartOfModels();
         blocks[index]->release();
         blocks[index] = 0;
     }
@@ -659,11 +556,6 @@ Framework::Vec3<int> Chunk::getMax() const
         location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
 }
 
-void Chunk::setModelChanged(int type)
-{
-    modelChanged |= type;
-}
-
 void Chunk::setLightChanged(int type)
 {
     lightChanged |= type;
@@ -673,3 +565,8 @@ Lock& Chunk::getBlockReadLock() const
 {
     return bLock.getReadLock();
 }
+
+DX12ChunkData* Chunk::zDX12Data() const
+{
+    return dx12Data;
+}

+ 4 - 5
FactoryCraft/Chunk.h

@@ -3,15 +3,14 @@
 #include <Array.h>
 #include <Critical.h>
 #include <Model3D.h>
-#include <Model3DCollection.h>
 #include <Point.h>
 #include <Reader.h>
 
-#include "Area.h"
 #include "Block.h"
 #include "BlockAnimation.h"
 #include "Constants.h"
-#include "FactoryCraftModel.h"
+
+class DX12ChunkData;
 
 class Chunk : public Framework::ReferenceCounter
 {
@@ -36,7 +35,7 @@ private:
     Framework::ReadWriteLock aLock;
     Framework::RCArray<BlockAnimation> animations;
     int lightChanged;
-    int modelChanged;
+    DX12ChunkData* dx12Data;
 
     void appendAnimation(
         Block* zB, int boneId, double time, Vec3<float> pos, Vec3<float> rot);
@@ -61,9 +60,9 @@ public:
     Framework::Point getCenter() const;
     Framework::Vec3<int> getMin() const;
     Framework::Vec3<int> getMax() const;
-    void setModelChanged(int modelType);
     void setLightChanged(int modelType);
     Lock& getBlockReadLock() const;
+    DX12ChunkData* zDX12Data() const;
 
     inline static int index(Framework::Vec3<int> localLocation)
     {

+ 0 - 312
FactoryCraft/ChunkFluidModel.cpp

@@ -1,312 +0,0 @@
-#include "ChunkFluidModel.h"
-
-#include <Trie.h>
-
-#include "Area.h"
-#include "Block.h"
-#include "Constants.h"
-#include "FactoryCraftModel.h"
-#include "Globals.h"
-
-ChunkFluidModel::ChunkFluidModel(FactoryCraftModel* target, Chunk* zChunk)
-    : ChunkModelBuilder(target, zChunk, Chunk::CombinedModels::FLUID)
-{}
-
-__int64 ChunkFluidModel::calculateLight(Framework::Vec3<float> vertexPos,
-    Framework::Vec3<int> blockPos,
-    Direction direction)
-{
-    __int64 result = 0;
-    int sumCount = 1;
-    short lightSum[6];
-    Block* current = blocks()[Chunk::index(blockPos)];
-    const unsigned char* light = current->getLightData(direction);
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (short)light[i];
-    }
-    Vec3<int> vertexDirs(vertexPos.x < 0 ? -1 : 1,
-        vertexPos.y < 0 ? -1 : 1,
-        vertexPos.z < 0 ? -1 : 1);
-    Directions dirs = getDirectionsFromVector(vertexDirs) & ~direction;
-    Vec3<int> neighborDirs[3];
-    int neighborIndex = 0;
-    for (int i = 0; i < 6; i++)
-    {
-        Direction dir = getDirectionFromIndex(i);
-        if ((dirs | dir) == dirs)
-        {
-            neighborDirs[neighborIndex++] = getDirection(dir);
-            if (neighborIndex == 2) break;
-        }
-    }
-    neighborDirs[2] = neighborDirs[0] + neighborDirs[1];
-    for (int i = 0; i < 3; i++)
-    {
-        neighborDirs[i] += blockPos;
-        if (neighborDirs[i].x >= 0 && neighborDirs[i].y >= 0
-            && neighborDirs[i].z >= 0 && neighborDirs[i].x < CHUNK_SIZE
-            && neighborDirs[i].y < CHUNK_SIZE
-            && neighborDirs[i].z < WORLD_HEIGHT)
-        {
-            int neighborIndex = Chunk::index(neighborDirs[i]);
-            Block* neighbor = blocks()[neighborIndex];
-            if (neighbor)
-            {
-                const unsigned char* neighborLight
-                    = neighbor->getLightData(direction);
-                if ((neighborLight[0] | neighborLight[1] | neighborLight[2]
-                        | neighborLight[3] | neighborLight[4]
-                        | neighborLight[5])
-                    != 0)
-                {
-                    sumCount++;
-                    for (int j = 0; j < 6; j++)
-                    {
-                        lightSum[j] += (short)neighborLight[j];
-                    }
-                }
-            }
-        }
-        else
-        { // TODO: get light from neighbor chunk
-        }
-    }
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (lightSum[i] / sumCount) & 0xFF;
-    }
-    result = ((__int64)lightSum[0] << 24) | ((__int64)lightSum[1] << 16)
-           | ((__int64)lightSum[2] << 8) | ((__int64)lightSum[3] << 56)
-           | ((__int64)lightSum[4] << 48) | ((__int64)lightSum[5] << 40);
-    return result;
-}
-
-bool ChunkFluidModel::isPartOfGroundModel(
-    Framework::Vec3<int> location, int directionIndex)
-{
-    Framework::Vec3<int> neighborLocation
-        = location + getDirection(getDirectionFromIndex(directionIndex));
-    bool needed = 0;
-    if (neighborLocation.x < 0 || neighborLocation.y < 0
-        || neighborLocation.z < 0 || neighborLocation.x >= CHUNK_SIZE
-        || neighborLocation.y >= CHUNK_SIZE
-        || neighborLocation.z >= WORLD_HEIGHT)
-    {
-        needed = 1;
-    }
-    else
-    {
-        int naighborIndex = Chunk::index(neighborLocation);
-        int currIndex = Chunk::index(location);
-        if (!blocks()[naighborIndex] || !isPartOfModel(blocks()[naighborIndex])
-            || blocks()[currIndex]->zBlockType()
-                   != blocks()[naighborIndex]->zBlockType()
-            || blocks()[naighborIndex]->getDistanceToSource()
-                   > blocks()[currIndex]->getDistanceToSource())
-        {
-            needed = 1;
-        }
-    }
-    return needed;
-}
-
-void ChunkFluidModel::buildModel()
-{
-    Model3DData* chunkModel = target->zModelData();
-    // remove old model
-    while (chunkModel->getPolygonCount() > 0)
-    {
-        chunkModel->removePolygon(0);
-    }
-    // calculate verticies
-    Trie<GroundModelPart*> groundModelBuidler;
-    Array<GroundModelPart*> groundPartArray;
-    Vertex3D* groundVerticies = new Vertex3D[10000];
-    __int64* lightBuffer = new __int64[10000];
-    int groundVertexCount = 0;
-    int groundVertexArraySize = 10000;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i])
-        {
-            if (isPartOfModel(blocks()[i]))
-            {
-                setBlockPartOfModel(blocks()[i], 1);
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
-                {
-                    Framework::Vec3<int> location(
-                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
-                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                        i % WORLD_HEIGHT);
-                    Framework::Vec3<int> aboveLocation
-                        = location + getDirection(Direction::TOP);
-                    int aboveIndex = Chunk::index(aboveLocation);
-                    bool sameAbove = aboveLocation.z < WORLD_HEIGHT
-                                  && blocks()[aboveIndex]
-                                  && blocks()[aboveIndex]->zBlockType()
-                                         == blocks()[i]->zBlockType();
-                    if (isPartOfGroundModel(location, index))
-                    {
-                        if (!groundModelBuidler.get(
-                                *textureName, textureName->getLength()))
-                        {
-                            GroundModelPart* part = new GroundModelPart();
-                            part->indexList = new int[10000];
-                            part->indexCount = 0;
-                            part->indexArraySize = 10000;
-                            part->name = *textureName;
-                            groundModelBuidler.set(
-                                *textureName, textureName->getLength(), part);
-                            groundPartArray.add(part);
-                        }
-                        GroundModelPart* part = groundModelBuidler.get(
-                            *textureName, textureName->getLength());
-                        const Vertex3D* vBuffer
-                            = blocks()[i]->zModelData()->zVertexBuffer();
-                        Polygon3D* polygon
-                            = blocks()[i]->zModelData()->getPolygon(index);
-                        if (part->indexCount + polygon->indexAnz
-                            > part->indexArraySize)
-                        {
-                            int* tmp = new int[part->indexArraySize + 10000];
-                            memcpy(tmp, part->indexList, part->indexCount * 4);
-                            delete[] part->indexList;
-                            part->indexList = tmp;
-                            part->indexArraySize += 10000;
-                        }
-                        if (groundVertexCount + polygon->indexAnz
-                            > groundVertexArraySize)
-                        {
-                            Vertex3D* tmp
-                                = new Vertex3D[groundVertexArraySize + 10000];
-                            memcpy(tmp,
-                                groundVerticies,
-                                groundVertexCount * sizeof(Vertex3D));
-                            delete[] groundVerticies;
-                            groundVerticies = tmp;
-                            groundVertexArraySize += 10000;
-                            __int64* lTmp = new __int64[groundVertexArraySize];
-                            memcpy(lTmp,
-                                lightBuffer,
-                                groundVertexCount * sizeof(__int64));
-                            delete[] lightBuffer;
-                            lightBuffer = lTmp;
-                        }
-                        for (int vi = 0; vi < polygon->indexAnz; vi++)
-                        {
-                            lightBuffer[groundVertexCount] = calculateLight(
-                                vBuffer[polygon->indexList[vi]].pos,
-                                location,
-                                getDirectionFromIndex(index));
-                            part->indexList[part->indexCount++]
-                                = groundVertexCount;
-                            groundVerticies[groundVertexCount++]
-                                = vBuffer[polygon->indexList[vi]];
-                            if (groundVerticies[groundVertexCount - 1].pos.z > 0
-                                && !sameAbove)
-                            {
-                                char maxFlowDist = blocks()[i]
-                                                       ->zBlockType()
-                                                       ->getMaxFlowDistance();
-                                float dist
-                                    = (float)(maxFlowDist + 1
-                                              - blocks()[i]
-                                                  ->getDistanceToSource())
-                                    / (float)(maxFlowDist + 1);
-                                groundVerticies[groundVertexCount - 1].pos.z
-                                    -= (1 - dist);
-                            }
-                            groundVerticies[groundVertexCount - 1].pos
-                                += blocks()[i]->getPos()
-                                 - Vec3<float>((float)chunkCenter().x,
-                                     (float)chunkCenter().y,
-                                     (float)WORLD_HEIGHT / 2.f);
-                            groundVerticies[groundVertexCount - 1].id
-                                = groundVertexCount - 1;
-                        }
-                    }
-                    index++;
-                }
-            }
-            else
-            {
-                setBlockPartOfModel(blocks()[i], 0);
-            }
-        }
-    }
-    Model3DTexture* texture = new Model3DTexture();
-    int pi = 0;
-    for (GroundModelPart* part : groundPartArray)
-    {
-        Polygon3D* polygon = new Polygon3D();
-        polygon->indexAnz = part->indexCount;
-        polygon->indexList = part->indexList;
-        target->zModelData()->addPolygon(polygon);
-        texture->setPolygonTexture(pi,
-            uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTexture(
-                part->name));
-        pi++;
-        delete part;
-    }
-    target->zModelData()->setVertecies(groundVerticies, groundVertexCount);
-    target->setModelTextur(texture);
-    target->setVertexLightBuffer(lightBuffer, groundVertexCount);
-}
-
-bool ChunkFluidModel::updateLightning()
-{
-    __int64* lightBuffer = target->zLightBuffer();
-    int oldVertexCount = target->getVertexCount();
-    int groundVertexCount = 0;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i] && isPartOfModel(blocks()[i]))
-        {
-            int index = 0;
-            for (Text* textureName :
-                *blocks()[i]->getCurrentModelInfo().getTexturNames())
-            {
-                Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
-                    (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                    i % WORLD_HEIGHT);
-                if (isPartOfGroundModel(location, index))
-                {
-                    const Vertex3D* vBuffer
-                        = blocks()[i]->zModelData()->zVertexBuffer();
-                    Polygon3D* polygon
-                        = blocks()[i]->zModelData()->getPolygon(index);
-                    for (int vi = 0; vi < polygon->indexAnz; vi++)
-                    {
-                        if (oldVertexCount <= groundVertexCount)
-                        {
-                            std::cout << "ERROR: to many vertecies in chunk "
-                                         "fluid model"
-                                      << std::endl;
-                            return 0;
-                        }
-                        lightBuffer[groundVertexCount++] = calculateLight(
-                            vBuffer[polygon->indexList[vi]].pos,
-                            location,
-                            getDirectionFromIndex(index));
-                    }
-                }
-                index++;
-            }
-        }
-    }
-    target->copyLightToGPU();
-    return 1;
-}
-
-bool ChunkFluidModel::isTransparent() const
-{
-    return true;
-}
-
-bool ChunkFluidModel::isPartOfModel(Block* zBlock) const
-{
-    return zBlock->zBlockType()->isFluid();
-}

+ 0 - 20
FactoryCraft/ChunkFluidModel.h

@@ -1,20 +0,0 @@
-#pragma once
-
-#include "Area.h"
-#include "ChunkModelBuilder.h"
-
-class ChunkFluidModel : public ChunkModelBuilder
-{
-private:
-    __int64 calculateLight(Framework::Vec3<float> vertexPos,
-        Framework::Vec3<int> blockPos,
-        Direction direction);
-    bool isPartOfGroundModel(Framework::Vec3<int> location, int directionIndex);
-
-public:
-    ChunkFluidModel(FactoryCraftModel* target, Chunk* zChunk);
-    void buildModel() override;
-    bool updateLightning() override;
-    bool isTransparent() const override;
-    bool isPartOfModel(Block* zBlock) const override;
-};

+ 0 - 288
FactoryCraft/ChunkGroundModel.cpp

@@ -1,288 +0,0 @@
-#include "ChunkGroundModel.h"
-
-#include <Trie.h>
-
-#include "Area.h"
-#include "Block.h"
-#include "Constants.h"
-#include "FactoryCraftModel.h"
-#include "Globals.h"
-
-using namespace Framework;
-
-ChunkGroundModel::ChunkGroundModel(FactoryCraftModel* target, Chunk* zChunk)
-    : ChunkModelBuilder(target, zChunk, Chunk::CombinedModels::GROUND)
-{}
-
-__int64 ChunkGroundModel::calculateLight(Framework::Vec3<float> vertexPos,
-    Framework::Vec3<int> blockPos,
-    Direction direction)
-{
-    __int64 result = 0;
-    int sumCount = 1;
-    short lightSum[6];
-    Block* current = blocks()[Chunk::index(blockPos)];
-    const unsigned char* light = current->getLightData(direction);
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (short)light[i];
-    }
-    Vec3<int> vertexDirs(vertexPos.x < 0 ? -1 : 1,
-        vertexPos.y < 0 ? -1 : 1,
-        vertexPos.z < 0 ? -1 : 1);
-    Directions dirs = getDirectionsFromVector(vertexDirs) & ~direction;
-    Vec3<int> neighborDirs[3];
-    int neighborIndex = 0;
-    for (int i = 0; i < 6; i++)
-    {
-        Direction dir = getDirectionFromIndex(i);
-        if ((dirs | dir) == dirs)
-        {
-            neighborDirs[neighborIndex++] = getDirection(dir);
-            if (neighborIndex == 2) break;
-        }
-    }
-    neighborDirs[2] = neighborDirs[0] + neighborDirs[1];
-    for (int i = 0; i < 3; i++)
-    {
-        neighborDirs[i] += blockPos;
-        if (neighborDirs[i].x >= 0 && neighborDirs[i].y >= 0
-            && neighborDirs[i].z >= 0 && neighborDirs[i].x < CHUNK_SIZE
-            && neighborDirs[i].y < CHUNK_SIZE
-            && neighborDirs[i].z < WORLD_HEIGHT)
-        {
-            int neighborIndex = Chunk::index(neighborDirs[i]);
-            Block* neighbor = blocks()[neighborIndex];
-            if (neighbor)
-            {
-                const unsigned char* neighborLight
-                    = neighbor->getLightData(direction);
-                if ((neighborLight[0] | neighborLight[1] | neighborLight[2]
-                        | neighborLight[3] | neighborLight[4]
-                        | neighborLight[5])
-                    != 0)
-                {
-                    sumCount++;
-                    for (int j = 0; j < 6; j++)
-                    {
-                        lightSum[j] += (short)neighborLight[j];
-                    }
-                }
-            }
-        }
-        else
-        { // TODO: get light from neighbor chunk
-        }
-    }
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (lightSum[i] / sumCount) & 0xFF;
-    }
-    result = ((__int64)lightSum[0] << 24) | ((__int64)lightSum[1] << 16)
-           | ((__int64)lightSum[2] << 8) | ((__int64)lightSum[3] << 56)
-           | ((__int64)lightSum[4] << 48) | ((__int64)lightSum[5] << 40);
-    return result;
-}
-
-bool ChunkGroundModel::isPartOfGroundModel(
-    Framework::Vec3<int> location, int directionIndex)
-{
-    Framework::Vec3<int> neighborLocation
-        = location + getDirection(getDirectionFromIndex(directionIndex));
-    bool needed = 0;
-    if (neighborLocation.x < 0 || neighborLocation.y < 0
-        || neighborLocation.z < 0 || neighborLocation.x >= CHUNK_SIZE
-        || neighborLocation.y >= CHUNK_SIZE
-        || neighborLocation.z >= WORLD_HEIGHT)
-    {
-        needed = 1;
-    }
-    else
-    {
-        int naighborIndex = Chunk::index(neighborLocation);
-        if (!blocks()[naighborIndex]
-            || !blocks()[naighborIndex]
-                ->getCurrentModelInfo()
-                .getModelName()
-                .isEqual("cube"))
-        {
-            needed = 1;
-        }
-    }
-    return needed;
-}
-
-void ChunkGroundModel::buildModel()
-{
-    Model3DData* chunkModel = target->zModelData();
-    // remove old model
-    while (chunkModel->getPolygonCount() > 0)
-    {
-        chunkModel->removePolygon(0);
-    }
-    // calculate verticies
-    Trie<GroundModelPart*> groundModelBuidler;
-    Array<GroundModelPart*> groundPartArray;
-    Vertex3D* groundVerticies = new Vertex3D[10000];
-    __int64* lightBuffer = new __int64[10000];
-    int groundVertexCount = 0;
-    int groundVertexArraySize = 10000;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i])
-        {
-            if (isPartOfModel(blocks()[i]))
-            {
-                setBlockPartOfModel(blocks()[i], 1);
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
-                {
-                    Framework::Vec3<int> location(
-                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
-                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                        i % WORLD_HEIGHT);
-                    if (isPartOfGroundModel(location, index))
-                    {
-                        if (!groundModelBuidler.get(
-                                *textureName, textureName->getLength()))
-                        {
-                            GroundModelPart* part = new GroundModelPart();
-                            part->indexList = new int[10000];
-                            part->indexCount = 0;
-                            part->indexArraySize = 10000;
-                            part->name = *textureName;
-                            groundModelBuidler.set(
-                                *textureName, textureName->getLength(), part);
-                            groundPartArray.add(part);
-                        }
-                        GroundModelPart* part = groundModelBuidler.get(
-                            *textureName, textureName->getLength());
-                        const Vertex3D* vBuffer
-                            = blocks()[i]->zModelData()->zVertexBuffer();
-                        Polygon3D* polygon
-                            = blocks()[i]->zModelData()->getPolygon(index);
-                        if (part->indexCount + polygon->indexAnz
-                            > part->indexArraySize)
-                        {
-                            int* tmp = new int[part->indexArraySize + 10000];
-                            memcpy(tmp, part->indexList, part->indexCount * 4);
-                            delete[] part->indexList;
-                            part->indexList = tmp;
-                            part->indexArraySize += 10000;
-                        }
-                        if (groundVertexCount + polygon->indexAnz
-                            > groundVertexArraySize)
-                        {
-                            Vertex3D* tmp
-                                = new Vertex3D[groundVertexArraySize + 10000];
-                            memcpy(tmp,
-                                groundVerticies,
-                                groundVertexCount * sizeof(Vertex3D));
-                            delete[] groundVerticies;
-                            groundVerticies = tmp;
-                            groundVertexArraySize += 10000;
-                            __int64* lTmp = new __int64[groundVertexArraySize];
-                            memcpy(lTmp,
-                                lightBuffer,
-                                groundVertexCount * sizeof(__int64));
-                            delete[] lightBuffer;
-                            lightBuffer = lTmp;
-                        }
-                        for (int vi = 0; vi < polygon->indexAnz; vi++)
-                        {
-                            lightBuffer[groundVertexCount] = calculateLight(
-                                vBuffer[polygon->indexList[vi]].pos,
-                                location,
-                                getDirectionFromIndex(index));
-                            part->indexList[part->indexCount++]
-                                = groundVertexCount;
-                            groundVerticies[groundVertexCount++]
-                                = vBuffer[polygon->indexList[vi]];
-                            groundVerticies[groundVertexCount - 1].pos
-                                += blocks()[i]->getPos()
-                                 - Vec3<float>((float)chunkCenter().x,
-                                     (float)chunkCenter().y,
-                                     (float)WORLD_HEIGHT / 2.f);
-                            groundVerticies[groundVertexCount - 1].id
-                                = groundVertexCount - 1;
-                        }
-                    }
-                    index++;
-                }
-            }
-            else
-            {
-                setBlockPartOfModel(blocks()[i], 0);
-            }
-        }
-    }
-    Model3DTexture* texture = new Model3DTexture();
-    int pi = 0;
-    for (GroundModelPart* part : groundPartArray)
-    {
-        Polygon3D* polygon = new Polygon3D();
-        polygon->indexAnz = part->indexCount;
-        polygon->indexList = part->indexList;
-        target->zModelData()->addPolygon(polygon);
-        texture->setPolygonTexture(pi,
-            uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTexture(
-                part->name));
-        pi++;
-        delete part;
-    }
-    target->zModelData()->setVertecies(groundVerticies, groundVertexCount);
-    target->setModelTextur(texture);
-    target->setVertexLightBuffer(lightBuffer, groundVertexCount);
-}
-
-bool ChunkGroundModel::updateLightning()
-{
-    __int64* lightBuffer = target->zLightBuffer();
-    int groundVertexCount = 0;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i])
-        {
-            if (isPartOfModel(blocks()[i]))
-            {
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
-                {
-                    Framework::Vec3<int> location(
-                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
-                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                        i % WORLD_HEIGHT);
-                    if (isPartOfGroundModel(location, index))
-                    {
-                        const Vertex3D* vBuffer
-                            = blocks()[i]->zModelData()->zVertexBuffer();
-                        Polygon3D* polygon
-                            = blocks()[i]->zModelData()->getPolygon(index);
-                        for (int vi = 0; vi < polygon->indexAnz; vi++)
-                        {
-                            lightBuffer[groundVertexCount++] = calculateLight(
-                                vBuffer[polygon->indexList[vi]].pos,
-                                location,
-                                getDirectionFromIndex(index));
-                        }
-                    }
-                    index++;
-                }
-            }
-        }
-    }
-    target->copyLightToGPU();
-    return 1;
-}
-
-bool ChunkGroundModel::isTransparent() const
-{
-    return false;
-}
-
-bool ChunkGroundModel::isPartOfModel(Block* zBlock) const
-{
-    return zBlock->getCurrentModelInfo().getModelName().isEqual("cube");
-}

+ 0 - 19
FactoryCraft/ChunkGroundModel.h

@@ -1,19 +0,0 @@
-#pragma once
-#include "ChunkModelBuilder.h"
-#include "Area.h"
-
-class ChunkGroundModel : public ChunkModelBuilder
-{
-private:
-    __int64 calculateLight(Framework::Vec3<float> vertexPos,
-        Framework::Vec3<int> blockPos,
-        Direction direction);
-    bool isPartOfGroundModel(Framework::Vec3<int> location, int directionIndex);
-
-public:
-    ChunkGroundModel(FactoryCraftModel* target, Chunk* zChunk);
-    void buildModel() override;
-    bool updateLightning() override;
-    bool isTransparent() const override;
-    bool isPartOfModel(Block* zBlock) const override;
-};

+ 0 - 52
FactoryCraft/ChunkModelBuilder.cpp

@@ -1,52 +0,0 @@
-#include "ChunkModelBuilder.h"
-
-#include "Chunk.h"
-
-ChunkModelBuilder::ChunkModelBuilder(
-    FactoryCraftModel* target, Chunk* zChunk, int type)
-    : ReferenceCounter(),
-      zChunk(zChunk),
-      type(type),
-      target(target)
-{}
-
-ChunkModelBuilder::~ChunkModelBuilder()
-{
-    target->release();
-}
-
-Block** ChunkModelBuilder::blocks()
-{
-    return 0;
-    // return zChunk->blocks;
-}
-
-void ChunkModelBuilder::setBlockPartOfModel(Block* zBlock, bool partOfModel)
-{
-    // int state = zBlock->getPartOfModels();
-    // if (!state && partOfModel)
-    //{
-    //     zChunk->visibleBlocks.removeValue(zBlock);
-    // }
-    // zBlock->setPartOfModel(type, partOfModel);
-    // if (state && !zBlock->getPartOfModels())
-    //{
-    //     zChunk->visibleBlocks.add(zBlock);
-    // }
-}
-
-Framework::Point ChunkModelBuilder::chunkCenter()
-{
-    return {0, 0};
-    // return zChunk->location;
-}
-
-FactoryCraftModel* ChunkModelBuilder::zModel() const
-{
-    return target;
-}
-
-int ChunkModelBuilder::getType() const
-{
-    return type;
-}

+ 0 - 40
FactoryCraft/ChunkModelBuilder.h

@@ -1,40 +0,0 @@
-#pragma once
-
-#include <ReferenceCounter.h>
-#include <Point.h>
-#include <Text.h>
-
-class Block;
-class Chunk;
-class FactoryCraftModel;
-
-struct GroundModelPart
-{
-    int* indexList;
-    int indexCount;
-    int indexArraySize;
-    Framework::Text name;
-};
-
-class ChunkModelBuilder : public Framework::ReferenceCounter
-{
-private:
-    Chunk* zChunk;
-    int type;
-
-protected:
-    FactoryCraftModel* target;
-    Block** blocks();
-    void setBlockPartOfModel(Block* zBlock, bool partOfModel);
-    Framework::Point chunkCenter();
-
-public:
-    ChunkModelBuilder(FactoryCraftModel* target, Chunk* zChunk, int type);
-    ~ChunkModelBuilder();
-    virtual void buildModel() = 0;
-    virtual bool updateLightning() = 0;
-    FactoryCraftModel* zModel() const;
-    int getType() const;
-    virtual bool isTransparent() const = 0;
-    virtual bool isPartOfModel(Block* zBlock) const = 0;
-};

+ 1 - 1
FactoryCraft/ClosestHit.hlsl

@@ -3,5 +3,5 @@
 [shader("closesthit")]
 void ClosestHit(inout HitInfo rayPayload : SV_RayPayload, Attributes attrib)
 {
-    rayPayload.colorAndDistance = float4(0.f, 0.f, 1.f, RayTCurrent());
+    rayPayload.colorAndDistance = float4(0.f, 0.5f, 1.f, RayTCurrent());
 }

+ 2 - 0
FactoryCraft/Common.hlsl

@@ -4,6 +4,8 @@
 // and that its size must be declared in the corresponding
 // D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
 
+#pragma pack_matrix(row_major)
+
 struct [raypayload] HitInfo
 {
     float4 colorAndDistance : write(caller, closesthit, miss) : read(caller);

+ 8 - 3
FactoryCraft/CustomDX12API.cpp

@@ -16,6 +16,7 @@ CustomDX12API::CustomDX12API()
 
 void CustomDX12API::initializePipeline()
 {
+    /*
     DX12Shader* rayGenShader
         = new DX12Shader(CustomRayGenShader, sizeof(CustomRayGenShader));
     // RayGen from RayGen.hlsl
@@ -58,7 +59,8 @@ void CustomDX12API::initializePipeline()
 
     pipeline->setMaxRecursionDepth(10);
 
-    pipeline->createPipelineState(device, pfnD3D12SerializeRootSignature);
+    pipeline->createPipelineState(device, pfnD3D12SerializeRootSignature);*/
+    DirectX12::initializePipeline();
 }
 
 void CustomDX12API::initializeGlobalDescriptorHeap()
@@ -69,7 +71,10 @@ void CustomDX12API::initializeGlobalDescriptorHeap()
 void CustomDX12API::fillShaderBindingTable(
     Framework::DX12ShaderBindingTable* zShaderBindingTable,
     Framework::Model3D* zModel,
-    int objectIndex)
+    int objectIndex,
+    const Framework::DX12BLAS* zBLAS,
+    int& lastHitGroupIndex)
 {
-    DirectX12::fillShaderBindingTable(zShaderBindingTable, zModel, objectIndex);
+    DirectX12::fillShaderBindingTable(
+        zShaderBindingTable, zModel, objectIndex, zBLAS, lastHitGroupIndex);
 }

+ 3 - 1
FactoryCraft/CustomDX12API.h

@@ -12,5 +12,7 @@ public:
     void fillShaderBindingTable(
         Framework::DX12ShaderBindingTable* zShaderBindingTable,
         Framework::Model3D* zModel,
-        int objectIndex) override;
+        int objectIndex,
+        const Framework::DX12BLAS* zBLAS,
+        int& lastHitGroupIndex) override;
 };

+ 272 - 0
FactoryCraft/DX12ChunkData.cpp

@@ -0,0 +1,272 @@
+#include "Dx12ChunkData.h"
+
+#include <DX12CommandQueue.h>
+
+#include "Constants.h"
+
+DX12ChunkData::DX12ChunkData(Framework::Point center)
+    : ReferenceCounter(),
+      aabbs(0),
+      chunkInfoBuffer(0),
+      blasScratchBuffer(0),
+      blasBuffer(0),
+      blockIndexBuffer(0),
+      textureIdBuffer(0),
+      chunkCenter(center),
+      blockIndices(),
+      textureIds(),
+      changed(0),
+      bufferChanged(0)
+{}
+
+DX12ChunkData::~DX12ChunkData()
+{
+    if (aabbs)
+    {
+        aabbs->release();
+    }
+    if (chunkInfoBuffer)
+    {
+        chunkInfoBuffer->release();
+    }
+    if (blasScratchBuffer)
+    {
+        blasScratchBuffer->release();
+    }
+    if (blasBuffer)
+    {
+        blasBuffer->release();
+    }
+    if (blockIndexBuffer)
+    {
+        blockIndexBuffer->release();
+    }
+    if (textureIdBuffer)
+    {
+        textureIdBuffer->release();
+    }
+}
+
+Framework::DX12Buffer* DX12ChunkData::zChunkInfoBuffer() const
+{
+    return chunkInfoBuffer;
+}
+
+Framework::DX12Buffer* DX12ChunkData::zBlasBuffer() const
+{
+    return blasBuffer;
+}
+
+Framework::DX12Buffer* DX12ChunkData::zBlockIndexBuffer() const
+{
+    return blockIndexBuffer;
+}
+
+Framework::DX12Buffer* DX12ChunkData::zTextureIdBuffer() const
+{
+    return textureIdBuffer;
+}
+
+void DX12ChunkData::setBlock(int index, Block* zBlock)
+{
+    if (zBlock)
+    {
+        ArrayIterator<int> it = blockIndices.begin();
+        ArrayIterator<int> textureIt = textureIds.begin();
+        int pos = 0;
+        while (it)
+        {
+            if (it.val() == index)
+            {
+                for (int i = 0; i < 6; ++i)
+                {
+                    textureIt.set(
+                        zBlock->zTexture()->zPolygonTexture(i)->getId());
+                    ++textureIt;
+                }
+                changed = 1;
+                return;
+            }
+            ++it;
+            ++pos;
+            for (int i = 0; i < 6; ++i)
+            {
+                ++textureIt;
+            }
+        }
+        blockIndices.add(index);
+        for (int i = 0; i < 6; ++i)
+        {
+            textureIds.add(zBlock->zTexture()->zPolygonTexture(i)->getId());
+        }
+        changed = 1;
+    }
+    else
+    {
+        ArrayIterator<int> it = blockIndices.begin();
+        ArrayIterator<int> textureIt = textureIds.begin();
+        while (it)
+        {
+            if (it.val() == index)
+            {
+                for (int i = 0; i < 6; ++i)
+                {
+                    textureIt.remove();
+                }
+                it.remove();
+                changed = 1;
+                return;
+            }
+            ++it;
+            for (int i = 0; i < 6; ++i)
+            {
+                ++textureIt;
+            }
+        }
+    }
+}
+
+void DX12ChunkData::updateBuffers(
+    ID3D12Device5* zDevice, Framework::DX12CommandQueue* zQueue)
+{
+    if (!aabbs)
+    {
+        aabbs = new DX12Buffer(sizeof(D3D12_RAYTRACING_AABB),
+            zDevice,
+            dynamic_cast<Framework::DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_NONE);
+        aabbs->setLength(sizeof(D3D12_RAYTRACING_AABB));
+        D3D12_RAYTRACING_AABB data = {chunkCenter.x - 8.f,
+            chunkCenter.y - 8.f,
+            0,
+            chunkCenter.x + 8.f,
+            chunkCenter.y + 8.f,
+            WORLD_HEIGHT};
+        aabbs->setData(&data, 1);
+        aabbs->copyToGPU();
+    }
+    if (!blasBuffer)
+    {
+        D3D12_RAYTRACING_GEOMETRY_DESC geometryDesc = {};
+        geometryDesc.Type
+            = D3D12_RAYTRACING_GEOMETRY_TYPE_PROCEDURAL_PRIMITIVE_AABBS;
+        geometryDesc.Flags = D3D12_RAYTRACING_GEOMETRY_FLAG_NONE;
+        geometryDesc.AABBs.AABBCount = 1;
+        geometryDesc.AABBs.AABBs.StartAddress
+            = aabbs->zBuffer()->GetGPUVirtualAddress();
+        geometryDesc.AABBs.AABBs.StrideInBytes = sizeof(D3D12_RAYTRACING_AABB);
+
+        D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS prebuildDesc;
+        prebuildDesc.Type
+            = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL;
+        prebuildDesc.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY;
+        prebuildDesc.NumDescs = 1;
+        prebuildDesc.pGeometryDescs = &geometryDesc;
+        prebuildDesc.Flags
+            = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_NONE;
+
+        D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO info = {};
+        zDevice->GetRaytracingAccelerationStructurePrebuildInfo(
+            &prebuildDesc, &info);
+
+        blasBuffer = new DX12Buffer(1,
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
+        blasBuffer->setLength(
+            ROUND_UP_POWER_OF_2(info.ResultDataMaxSizeInBytes, 256));
+        blasBuffer->createBufferWithoutData(
+            D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE);
+
+        blasScratchBuffer = new DX12Buffer(1,
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
+        blasScratchBuffer->setLength(
+            ROUND_UP_POWER_OF_2(info.ScratchDataSizeInBytes, 256));
+        blasScratchBuffer->createBufferWithoutData(D3D12_RESOURCE_STATE_COMMON);
+
+        D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC buildDesc;
+        buildDesc.Inputs.Type
+            = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL;
+        buildDesc.Inputs.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY;
+        buildDesc.Inputs.NumDescs = 1;
+        buildDesc.Inputs.pGeometryDescs = &geometryDesc;
+        buildDesc.DestAccelerationStructureData
+            = {blasBuffer->zBuffer()->GetGPUVirtualAddress()};
+        buildDesc.ScratchAccelerationStructureData
+            = {blasScratchBuffer->zBuffer()->GetGPUVirtualAddress()};
+        buildDesc.SourceAccelerationStructureData = 0;
+        buildDesc.Inputs.Flags
+            = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_NONE;
+
+        zQueue->zCommandList()->BuildRaytracingAccelerationStructure(
+            &buildDesc, 0, nullptr);
+    }
+    if (blockIndexBuffer
+        && blockIndexBuffer->getElementCount() < blockIndices.getEntryCount())
+    {
+        blockIndexBuffer->release();
+        blockIndexBuffer = 0;
+    }
+    if (!blockIndexBuffer)
+    {
+        blockIndexBuffer = new DX12Buffer(sizeof(int),
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_NONE);
+        blockIndexBuffer->setLength(blockIndices.getEntryCount() * sizeof(int));
+        bufferChanged = 1;
+    }
+    if (textureIdBuffer
+        && textureIdBuffer->getElementCount() < textureIds.getEntryCount())
+    {
+        textureIdBuffer->release();
+        textureIdBuffer = 0;
+    }
+    if (!textureIdBuffer)
+    {
+        textureIdBuffer = new DX12Buffer(sizeof(int),
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_NONE);
+        textureIdBuffer->setLength(textureIds.getEntryCount() * sizeof(int));
+        bufferChanged = 1;
+    }
+    if (!chunkInfoBuffer)
+    {
+        chunkInfoBuffer = new DX12Buffer(sizeof(ChunkShaderInfo),
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_NONE);
+        chunkInfoBuffer->setLength(sizeof(ChunkShaderInfo));
+    }
+    if (changed)
+    {
+        int* blockIndexData = new int[blockIndices.getEntryCount()];
+        int* textureIdData = new int[textureIds.getEntryCount()];
+        ArrayIterator<int> it = blockIndices.begin();
+        ArrayIterator<int> textureIt = textureIds.begin();
+        int index = 0;
+        while (it)
+        {
+            blockIndexData[index] = it.val();
+            for (int i = 0; i < 6; i++)
+            {
+                textureIdData[index * 6 + i] = textureIt.val();
+                ++textureIt;
+            }
+            ++it;
+        }
+        blockIndexBuffer->setData(blockIndexData, 1);
+        textureIdBuffer->setData(textureIdData, 1);
+        blockIndexBuffer->copyToGPU(sizeof(int) * blockIndices.getEntryCount());
+        textureIdBuffer->copyToGPU(sizeof(int) * textureIds.getEntryCount());
+        delete[] blockIndexData;
+        delete[] textureIdData;
+        ChunkShaderInfo info
+            = {chunkCenter, (unsigned int)blockIndices.getEntryCount()};
+        chunkInfoBuffer->setData(&info, 1);
+        chunkInfoBuffer->copyToGPU();
+    }
+}

+ 40 - 0
FactoryCraft/DX12ChunkData.h

@@ -0,0 +1,40 @@
+#pragma once
+
+#include <d3d12.h>
+#include <DX12Buffer.h>
+#include <Point.h>
+
+#include "Block.h"
+
+struct ChunkShaderInfo
+{
+    Framework::Point pos;
+    unsigned int blockCount;
+};
+
+class DX12ChunkData : public ReferenceCounter
+{
+private:
+    Framework::DX12Buffer* aabbs;
+    Framework::DX12Buffer* chunkInfoBuffer;
+    Framework::DX12Buffer* blasScratchBuffer;
+    Framework::DX12Buffer* blasBuffer;
+    Framework::DX12Buffer* blockIndexBuffer;
+    Framework::DX12Buffer* textureIdBuffer;
+    Framework::Point chunkCenter;
+    Framework::Array<int> blockIndices;
+    Framework::Array<int> textureIds;
+    bool changed;
+    bool bufferChanged;
+
+public:
+    DX12ChunkData(Framework::Point center);
+    ~DX12ChunkData();
+    Framework::DX12Buffer* zChunkInfoBuffer() const;
+    Framework::DX12Buffer* zBlasBuffer() const;
+    Framework::DX12Buffer* zBlockIndexBuffer() const;
+    Framework::DX12Buffer* zTextureIdBuffer() const;
+    void setBlock(int index, Block* zBlock);
+    void updateBuffers(
+        ID3D12Device5* zDevice, Framework::DX12CommandQueue* zQueue);
+};

+ 1 - 0
FactoryCraft/Dimension.h

@@ -2,6 +2,7 @@
 
 #include <Array.h>
 #include <Critical.h>
+#include <Model3DCollection.h>
 #include <Trie.h>
 
 #include "Chunk.h"

+ 8 - 8
FactoryCraft/FactoryCraft.vcxproj

@@ -182,10 +182,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="ChatMessage.cpp" />
     <ClCompile Include="ChatOptions.cpp" />
     <ClCompile Include="Chunk.cpp" />
-    <ClCompile Include="ChunkFluidModel.cpp" />
-    <ClCompile Include="ChunkGroundModel.cpp" />
     <ClCompile Include="ChunkMap.cpp" />
-    <ClCompile Include="ChunkModelBuilder.cpp" />
     <ClCompile Include="CraftingGrid.cpp" />
     <ClCompile Include="CraftingRecipies.cpp" />
     <ClCompile Include="CustomDX12API.cpp" />
@@ -194,6 +191,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="AddServerMenu.cpp" />
     <ClCompile Include="DimensionMap.cpp" />
     <ClCompile Include="DragElement.cpp" />
+    <ClCompile Include="DX12ChunkData.cpp" />
     <ClCompile Include="Entity.cpp" />
     <ClCompile Include="EntityType.cpp" />
     <ClCompile Include="Equipment.cpp" />
@@ -224,7 +222,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="PlayerKam.cpp" />
     <ClCompile Include="ShapedRecipie.cpp" />
     <ClCompile Include="StatusBars.cpp" />
-    <ClCompile Include="TransparentChunkGroundModel.cpp" />
     <ClCompile Include="UIMLCraftingProgress.cpp" />
     <ClCompile Include="UIMLFuelState.cpp" />
     <ClCompile Include="UIMLProgressAndStateView.cpp" />
@@ -242,10 +239,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="ChatMessage.h" />
     <ClInclude Include="ChatOptions.h" />
     <ClInclude Include="Chunk.h" />
-    <ClInclude Include="ChunkFluidModel.h" />
-    <ClInclude Include="ChunkGroundModel.h" />
     <ClInclude Include="ChunkMap.h" />
-    <ClInclude Include="ChunkModelBuilder.h" />
     <ClInclude Include="Constants.h" />
     <ClInclude Include="CraftingGrid.h" />
     <ClInclude Include="CraftingRecipies.h" />
@@ -256,6 +250,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="DimensionMap.h" />
     <ClInclude Include="DragController.h" />
     <ClInclude Include="DragElement.h" />
+    <ClInclude Include="DX12ChunkData.h" />
     <ClInclude Include="Entity.h" />
     <ClInclude Include="EntityType.h" />
     <ClInclude Include="Equipment.h" />
@@ -286,7 +281,6 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="PlayerKam.h" />
     <ClInclude Include="ShapedRecipie.h" />
     <ClInclude Include="StatusBars.h" />
-    <ClInclude Include="TransparentChunkGroundModel.h" />
     <ClInclude Include="UIMLCraftingProgress.h" />
     <ClInclude Include="UIMLFuelState.h" />
     <ClInclude Include="UIMLProgressAndStateView.h" />
@@ -304,6 +298,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
       <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
       </ObjectFileOutput>
       <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </EntryPointName>
     </FxCompile>
     <None Include="Common.hlsl">
       <FileType>Document</FileType>
@@ -316,6 +312,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
       <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
       </ObjectFileOutput>
       <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </EntryPointName>
     </FxCompile>
     <FxCompile Include="RayGen.hlsl">
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
@@ -325,6 +323,8 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
       <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
       </ObjectFileOutput>
       <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </EntryPointName>
     </FxCompile>
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 6 - 24
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -220,18 +220,6 @@
     <ClCompile Include="Chunk.cpp">
       <Filter>world\chunk</Filter>
     </ClCompile>
-    <ClCompile Include="ChunkGroundModel.cpp">
-      <Filter>world\chunk</Filter>
-    </ClCompile>
-    <ClCompile Include="ChunkModelBuilder.cpp">
-      <Filter>world\chunk</Filter>
-    </ClCompile>
-    <ClCompile Include="ChunkFluidModel.cpp">
-      <Filter>world\chunk</Filter>
-    </ClCompile>
-    <ClCompile Include="TransparentChunkGroundModel.cpp">
-      <Filter>world\chunk</Filter>
-    </ClCompile>
     <ClCompile Include="ListView.cpp">
       <Filter>Menu\uiml\general</Filter>
     </ClCompile>
@@ -256,6 +244,9 @@
     <ClCompile Include="UIMLProgressAndStateView.cpp">
       <Filter>Menu\uiml\machines</Filter>
     </ClCompile>
+    <ClCompile Include="DX12ChunkData.cpp">
+      <Filter>world\chunk</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -402,18 +393,6 @@
     <ClInclude Include="Chunk.h">
       <Filter>world\chunk</Filter>
     </ClInclude>
-    <ClInclude Include="ChunkModelBuilder.h">
-      <Filter>world\chunk</Filter>
-    </ClInclude>
-    <ClInclude Include="ChunkGroundModel.h">
-      <Filter>world\chunk</Filter>
-    </ClInclude>
-    <ClInclude Include="ChunkFluidModel.h">
-      <Filter>world\chunk</Filter>
-    </ClInclude>
-    <ClInclude Include="TransparentChunkGroundModel.h">
-      <Filter>world\chunk</Filter>
-    </ClInclude>
     <ClInclude Include="ListView.h">
       <Filter>Menu\uiml\general</Filter>
     </ClInclude>
@@ -438,6 +417,9 @@
     <ClInclude Include="UIMLProgressAndStateView.h">
       <Filter>Menu\uiml\machines</Filter>
     </ClInclude>
+    <ClInclude Include="DX12ChunkData.h">
+      <Filter>world\chunk</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="RayGen.hlsl">

+ 1 - 1
FactoryCraft/Miss.hlsl

@@ -3,5 +3,5 @@
 [shader("miss")]
 void Miss(inout HitInfo rayPayload : SV_RayPayload)
 {
-    rayPayload.colorAndDistance = float4(0.5f, 0.f, 0.f, -1.f);
+    rayPayload.colorAndDistance = float4(0.2f, 0.2f, 0.2f, -1.f);
 }

+ 1 - 0
FactoryCraft/PlayerKam.cpp

@@ -34,6 +34,7 @@ PlayerKam::PlayerKam(Framework::Screen3D* zScreen)
     entityId = -1;
     movementFlags = 0;
     lastMovementFlags = 0;
+    setMaxDistance(10000);
 }
 
 void PlayerKam::setDirection(Framework::Vec3<float> direction)

+ 4 - 3
FactoryCraft/RayGen.hlsl

@@ -33,11 +33,12 @@ void RayGen()
     
     if (useRays)
     {
-        float2 d = (((dispatchIndex.xy + 0.5f) / dispatchDimensions.xy) * 2.f - 1.f);
+        float2 d = (dispatchPercentage * 2.f - 1.f);
         RayDesc ray;
         ray.Origin = mul(inverseView, float4(0, 0, 0, 1)).xyz;
-        float4 target = mul(inverseProjection, float4(d.x, -d.y, 1, 1));
-        ray.Direction = mul(inverseView, float4(target.xyz, 0)).xyz;
+        float4 target = mul(inverseProjection, float4(d.x, d.y, -1, 1));
+        target.w = 1;
+        ray.Direction = mul(inverseView, target).xyz - ray.Origin;
         ray.TMin = minDistance;
         ray.TMax = maxDistance;
         TraceRay(TLAS, /*RayFlags*/0, /*InstanceInclusionMask*/0xFF, /*RayContributionToHitGroupIndex*/0,

+ 0 - 243
FactoryCraft/TransparentChunkGroundModel.cpp

@@ -1,243 +0,0 @@
-#include "TransparentChunkGroundModel.h"
-
-#include <Trie.h>
-
-#include "Area.h"
-#include "Block.h"
-#include "Constants.h"
-#include "FactoryCraftModel.h"
-#include "Globals.h"
-
-using namespace Framework;
-
-TransparentChunkGroundModel::TransparentChunkGroundModel(
-    FactoryCraftModel* target, Chunk* zChunk)
-    : ChunkModelBuilder(
-          target, zChunk, Chunk::CombinedModels::TRANSPARENT_GROUND)
-{}
-
-__int64 TransparentChunkGroundModel::calculateLight(
-    Framework::Vec3<float> vertexPos,
-    Framework::Vec3<int> blockPos,
-    Direction direction)
-{
-    __int64 result = 0;
-    int sumCount = 1;
-    short lightSum[6];
-    Block* current = blocks()[Chunk::index(blockPos)];
-    const unsigned char* light = current->getLightData(direction);
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (short)light[i];
-    }
-    Vec3<int> vertexDirs(vertexPos.x < 0 ? -1 : 1,
-        vertexPos.y < 0 ? -1 : 1,
-        vertexPos.z < 0 ? -1 : 1);
-    Directions dirs = getDirectionsFromVector(vertexDirs) & ~direction;
-    Vec3<int> neighborDirs[3];
-    int neighborIndex = 0;
-    for (int i = 0; i < 6; i++)
-    {
-        Direction dir = getDirectionFromIndex(i);
-        if ((dirs | dir) == dirs)
-        {
-            neighborDirs[neighborIndex++] = getDirection(dir);
-            if (neighborIndex == 2) break;
-        }
-    }
-    neighborDirs[2] = neighborDirs[0] + neighborDirs[1];
-    for (int i = 0; i < 3; i++)
-    {
-        neighborDirs[i] += blockPos;
-        if (neighborDirs[i].x >= 0 && neighborDirs[i].y >= 0
-            && neighborDirs[i].z >= 0 && neighborDirs[i].x < CHUNK_SIZE
-            && neighborDirs[i].y < CHUNK_SIZE
-            && neighborDirs[i].z < WORLD_HEIGHT)
-        {
-            int neighborIndex = Chunk::index(neighborDirs[i]);
-            Block* neighbor = blocks()[neighborIndex];
-            if (neighbor)
-            {
-                const unsigned char* neighborLight
-                    = neighbor->getLightData(direction);
-                if ((neighborLight[0] | neighborLight[1] | neighborLight[2]
-                        | neighborLight[3] | neighborLight[4]
-                        | neighborLight[5])
-                    != 0)
-                {
-                    sumCount++;
-                    for (int j = 0; j < 6; j++)
-                    {
-                        lightSum[j] += (short)neighborLight[j];
-                    }
-                }
-            }
-        }
-        else
-        { // TODO: get light from neighbor chunk
-        }
-    }
-    for (int i = 0; i < 6; i++)
-    {
-        lightSum[i] = (lightSum[i] / sumCount) & 0xFF;
-    }
-    result = ((__int64)lightSum[0] << 24) | ((__int64)lightSum[1] << 16)
-           | ((__int64)lightSum[2] << 8) | ((__int64)lightSum[3] << 56)
-           | ((__int64)lightSum[4] << 48) | ((__int64)lightSum[5] << 40);
-    return result;
-}
-
-void TransparentChunkGroundModel::buildModel()
-{
-    Model3DData* chunkModel = target->zModelData();
-    // remove old model
-    while (chunkModel->getPolygonCount() > 0)
-    {
-        chunkModel->removePolygon(0);
-    }
-    // calculate verticies
-    Trie<GroundModelPart*> groundModelBuidler;
-    Array<GroundModelPart*> groundPartArray;
-    Vertex3D* groundVerticies = new Vertex3D[10000];
-    __int64* lightBuffer = new __int64[10000];
-    int groundVertexCount = 0;
-    int groundVertexArraySize = 10000;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i])
-        {
-            if (isPartOfModel(blocks()[i]))
-            {
-                setBlockPartOfModel(blocks()[i], 1);
-                __int64 light = blocks()[i]->getMaxLight();
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
-                {
-                    if (!groundModelBuidler.get(
-                            *textureName, textureName->getLength()))
-                    {
-                        GroundModelPart* part = new GroundModelPart();
-                        part->indexList = new int[10000];
-                        part->indexCount = 0;
-                        part->indexArraySize = 10000;
-                        part->name = *textureName;
-                        groundModelBuidler.set(
-                            *textureName, textureName->getLength(), part);
-                        groundPartArray.add(part);
-                    }
-                    GroundModelPart* part = groundModelBuidler.get(
-                        *textureName, textureName->getLength());
-                    const Vertex3D* vBuffer
-                        = blocks()[i]->zModelData()->zVertexBuffer();
-                    Polygon3D* polygon
-                        = blocks()[i]->zModelData()->getPolygon(index);
-                    if (part->indexCount + polygon->indexAnz
-                        > part->indexArraySize)
-                    {
-                        int* tmp = new int[part->indexArraySize + 10000];
-                        memcpy(tmp, part->indexList, part->indexCount * 4);
-                        delete[] part->indexList;
-                        part->indexList = tmp;
-                        part->indexArraySize += 10000;
-                    }
-                    if (groundVertexCount + polygon->indexAnz
-                        > groundVertexArraySize)
-                    {
-                        Vertex3D* tmp
-                            = new Vertex3D[groundVertexArraySize + 10000];
-                        memcpy(tmp,
-                            groundVerticies,
-                            groundVertexCount * sizeof(Vertex3D));
-                        delete[] groundVerticies;
-                        groundVerticies = tmp;
-                        groundVertexArraySize += 10000;
-                        __int64* lTmp = new __int64[groundVertexArraySize];
-                        memcpy(lTmp,
-                            lightBuffer,
-                            groundVertexCount * sizeof(__int64));
-                        delete[] lightBuffer;
-                        lightBuffer = lTmp;
-                    }
-                    for (int vi = 0; vi < polygon->indexAnz; vi++)
-                    {
-                        lightBuffer[groundVertexCount] = light;
-                        part->indexList[part->indexCount++] = groundVertexCount;
-                        groundVerticies[groundVertexCount++]
-                            = vBuffer[polygon->indexList[vi]];
-                        groundVerticies[groundVertexCount - 1].pos
-                            += blocks()[i]->getPos()
-                             - Vec3<float>((float)chunkCenter().x,
-                                 (float)chunkCenter().y,
-                                 (float)WORLD_HEIGHT / 2.f);
-                        groundVerticies[groundVertexCount - 1].id
-                            = groundVertexCount - 1;
-                    }
-                    index++;
-                }
-            }
-            else
-            {
-                setBlockPartOfModel(blocks()[i], 0);
-            }
-        }
-    }
-    Model3DTexture* texture = new Model3DTexture();
-    int pi = 0;
-    for (GroundModelPart* part : groundPartArray)
-    {
-        Polygon3D* polygon = new Polygon3D();
-        polygon->indexAnz = part->indexCount;
-        polygon->indexList = part->indexList;
-        target->zModelData()->addPolygon(polygon);
-        texture->setPolygonTexture(pi,
-            uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTexture(
-                part->name));
-        pi++;
-        delete part;
-    }
-    target->zModelData()->setVertecies(groundVerticies, groundVertexCount);
-    target->setModelTextur(texture);
-    target->setVertexLightBuffer(lightBuffer, groundVertexCount);
-}
-
-bool TransparentChunkGroundModel::updateLightning()
-{
-    __int64* lightBuffer = target->zLightBuffer();
-    int groundVertexCount = 0;
-    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
-    {
-        if (blocks()[i])
-        {
-            if (isPartOfModel(blocks()[i]))
-            {
-                __int64 light = blocks()[i]->getMaxLight();
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->getCurrentModelInfo().getTexturNames())
-                {
-                    const Vertex3D* vBuffer
-                        = blocks()[i]->zModelData()->zVertexBuffer();
-                    Polygon3D* polygon
-                        = blocks()[i]->zModelData()->getPolygon(index);
-                    for (int vi = 0; vi < polygon->indexAnz; vi++)
-                    {
-                        lightBuffer[groundVertexCount++] = light;
-                    }
-                }
-            }
-        }
-    }
-    target->copyLightToGPU();
-    return 1;
-}
-
-bool TransparentChunkGroundModel::isTransparent() const
-{
-    return true;
-}
-
-bool TransparentChunkGroundModel::isPartOfModel(Block* zBlock) const
-{
-    return zBlock->getCurrentModelInfo().getModelName().isEqual("grass");
-}

+ 0 - 18
FactoryCraft/TransparentChunkGroundModel.h

@@ -1,18 +0,0 @@
-#pragma once
-#include "ChunkModelBuilder.h"
-#include "Area.h"
-
-class TransparentChunkGroundModel : public ChunkModelBuilder
-{
-private:
-    __int64 calculateLight(Framework::Vec3<float> vertexPos,
-        Framework::Vec3<int> blockPos,
-        Direction direction);
-
-public:
-    TransparentChunkGroundModel(FactoryCraftModel* target, Chunk* zChunk);
-    void buildModel() override;
-    bool updateLightning() override;
-    bool isTransparent() const override;
-    bool isPartOfModel(Block* zBlock) const override;
-};

+ 1 - 1
FactoryCraft/World.cpp

@@ -460,7 +460,7 @@ void World::setTarget(Framework::Model3D* zTarget)
             selectionModel->setPosition(
                 zTarget->getPos().x, zTarget->getPos().y, zTarget->getPos().z);
             Block* b = dynamic_cast<Block*>(zTarget);
-            if (b && b->getPartOfModels())
+            if (b)
             {
                 selectionModel->setDestroyedState(b->getEffectPercentage());
             }