Ver Fonte

add shaped noise for rivers

Kolja Strohm há 1 ano atrás
pai
commit
114faa45d1

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -142,6 +142,7 @@
     <ClInclude Include="RecipieLoader.h" />
     <ClInclude Include="Server.h" />
     <ClInclude Include="Dimension.h" />
+    <ClInclude Include="ShapedNoise.h" />
     <ClInclude Include="StaticRegistry.h" />
     <ClInclude Include="StoneTool.h" />
     <ClInclude Include="TickOrganizer.h" />
@@ -200,6 +201,7 @@
     <ClCompile Include="Recipie.cpp" />
     <ClCompile Include="RecipieLoader.cpp" />
     <ClCompile Include="Server.cpp" />
+    <ClCompile Include="ShapedNoise.cpp" />
     <ClCompile Include="Start.cpp" />
     <ClCompile Include="StaticInitializerOrder.cpp" />
     <ClCompile Include="StoneTool.cpp" />

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -252,6 +252,9 @@
     <ClInclude Include="RandNoise.h">
       <Filter>world\generator\noise</Filter>
     </ClInclude>
+    <ClInclude Include="ShapedNoise.h">
+      <Filter>world\generator\noise</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Server.cpp">
@@ -425,5 +428,8 @@
     <ClCompile Include="RandNoise.cpp">
       <Filter>world\generator\noise</Filter>
     </ClCompile>
+    <ClCompile Include="ShapedNoise.cpp">
+      <Filter>world\generator\noise</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 31 - 0
FactoryCraft/ShapedNoise.cpp

@@ -0,0 +1,31 @@
+#include "ShapedNoise.h"
+
+ShapedNoise::ShapedNoise(Noise* delegateNoise)
+    : delegateNoise(delegateNoise),
+      neighborOffset(1)
+{}
+
+ShapedNoise ::~ShapedNoise()
+{
+    delegateNoise->release();
+}
+
+void ShapedNoise::setNeighborOffset(double offset)
+{
+    neighborOffset = offset;
+}
+
+double ShapedNoise::getNoise(double x, double y, double z)
+{
+    double max = 0;
+    double noise = delegateNoise->getNoise(x, y, z);
+    max = MAX(max, abs(noise - delegateNoise->getNoise(x + neighborOffset, y, z)));
+    max = MAX(max, abs(noise - delegateNoise->getNoise(x, y + neighborOffset, z)));
+    max = MAX(max, abs(noise - delegateNoise->getNoise(x, y, z + neighborOffset)));
+    return max;
+}
+
+int ShapedNoise::getSeed() const
+{
+	return delegateNoise->getSeed();
+}

+ 17 - 0
FactoryCraft/ShapedNoise.h

@@ -0,0 +1,17 @@
+#pragma once
+
+#include "Noise.h"
+
+class ShapedNoise : public Noise
+{
+private:
+    Noise* delegateNoise;
+    double neighborOffset;
+
+public:
+    ShapedNoise(Noise* delegateNoise);
+    ~ShapedNoise();
+    void setNeighborOffset(double offset);
+    double getNoise(double x, double y, double z) override;
+    int getSeed() const override;
+};

+ 56 - 15
Windows Version/Start.cpp

@@ -10,6 +10,7 @@
 #include "FastNoiseLite.h"
 #include "FastNoiseWrapper.h"
 #include "RandNoise.h"
+#include "ShapedNoise.h"
 
 using namespace Framework;
 
@@ -20,6 +21,8 @@ int zoom = 1;
 bool exitF = 0;
 Noise* wrapper;
 float border = 0.5;
+float border2 = -1;
+bool showValue = 1;
 
 void updateView()
 {
@@ -38,20 +41,31 @@ void updateView()
             pos -= Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0);
             pos /= zoom;
             pos += position;
-            if (wrapper->getNoise(pos.x, pos.y, pos.z) < border)
+			double noise = wrapper->getNoise(pos.x, pos.y, pos.z);
+            if (showValue)
             {
-                img->setPixelDP(i, j, 0xFFFFFFFF);
-                counter++;
+                int value = (int)(noise * 255);
+                img->setPixelDP(
+                    i, j, 0xFF000000 | (value << 16) | (value << 8) | value);
             }
             else
             {
-                img->setPixelDP(i, j, 0xFF000000);
+                if (noise < border && noise > border2)
+                {
+                    img->setPixelDP(i, j, 0xFFFFFFFF);
+                    counter++;
+                }
+                else
+                {
+                    img->setPixelDP(i, j, 0xFF000000);
+                }
             }
         }
     }
     float percentage = ((float)counter / (img->getBreite() * img->getHeight())) * 100;
     std::cout << "Showing " << minP.x << " " << minP.y << " to " << maxP.x
               << " " << maxP.y << " at height " << position.z << " with border "
+              << border2 << " to "
               << border << " true for " << percentage << "% of "
               << (img->getBreite() / zoom) * (img->getHeight() / zoom) << " blocks"
               << std::endl;
@@ -64,15 +78,26 @@ int main()
     noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
     noise->SetFrequency(3.f);
     wrapper = new FastNoiseWrapper(noise, 0);*/
-   // FastNoiseLite* n = new FastNoiseLite(0);
-   // n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_OpenSimplex2);
-    //n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
-    //n->SetFrequency(0.001f);
-    //n->SetFractalOctaves(0);
-    //n->SetFractalType(FastNoiseLite::FractalType::FractalType_None);
-    //n->SetDomainWarpAmp(0.f);
-    //wrapper = new FastNoiseWrapper(n, 0);
-    wrapper = new RandNoise(0);
+    FastNoiseLite* n = new FastNoiseLite(0);
+    n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Cellular);
+    n->SetFrequency(0.005f);
+    n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
+    n->SetCellularDistanceFunction(FastNoiseLite::CellularDistanceFunction::
+            CellularDistanceFunction_Hybrid);
+    n->SetCellularJitter(1.f);
+    n->SetCellularReturnType(
+        FastNoiseLite::CellularReturnType::CellularReturnType_CellValue);
+    n->SetFractalType(
+        FastNoiseLite::FractalType::FractalType_DomainWarpIndependent);
+    n->SetDomainWarpType(
+        FastNoiseLite::DomainWarpType::DomainWarpType_OpenSimplex2);
+    n->SetDomainWarpAmp(100.f);
+    n->SetFractalOctaves(3.f);
+    n->SetFractalLacunarity(2.f);
+    n->SetFractalGain(0.5f);
+    wrapper = new FastNoiseWrapper(n, 0);
+    wrapper = new ShapedNoise(wrapper);
+    ((ShapedNoise*)wrapper)->setNeighborOffset(4.f);
 
 
     img = new Bild();
@@ -137,6 +162,13 @@ int main()
 				border = (float)*x;
 				updateView();
 				x->release();
+            }
+            if (txt.positionVon("border2 ") == 0)
+            {
+                Text* x = txt.getTeilText(7);
+                border2 = (float)*x;
+                updateView();
+                x->release();
             }
 			if (txt.positionVon("zoom ") == 0)
 			{
@@ -144,7 +176,17 @@ int main()
 				zoom = (int)*x;
 				updateView();
 				x->release();
-			}
+            }
+            if (txt.positionVon("show value") == 0)
+            {
+                showValue = 1;
+                updateView();
+            }
+            if (txt.positionVon("show border") == 0)
+            {
+                showValue = 0;
+                updateView();
+            }
         }
     });
 
@@ -155,7 +197,6 @@ int main()
     rth->beenden();
     window->setBildschirm(0);
     rth->release();
-    img->release();
     Framework::releaseFramework();
     return 0;
 }

+ 2 - 0
Windows Version/Windows Version.vcxproj

@@ -144,6 +144,7 @@
     <ClCompile Include="..\FactoryCraft\Noise.cpp" />
     <ClCompile Include="..\FactoryCraft\NoiseInterpolator.cpp" />
     <ClCompile Include="..\FactoryCraft\RandNoise.cpp" />
+    <ClCompile Include="..\FactoryCraft\ShapedNoise.cpp" />
     <ClCompile Include="Start.cpp" />
   </ItemGroup>
   <ItemGroup>
@@ -152,6 +153,7 @@
     <ClInclude Include="..\FactoryCraft\Noise.h" />
     <ClInclude Include="..\FactoryCraft\NoiseInterpolator.h" />
     <ClInclude Include="..\FactoryCraft\RandNoise.h" />
+    <ClInclude Include="..\FactoryCraft\ShapedNoise.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 6 - 0
Windows Version/Windows Version.vcxproj.filters

@@ -39,6 +39,9 @@
     <ClCompile Include="..\FactoryCraft\RandNoise.cpp">
       <Filter>world\generator\noise</Filter>
     </ClCompile>
+    <ClCompile Include="..\FactoryCraft\ShapedNoise.cpp">
+      <Filter>world\generator\noise</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\FactoryCraft\FastNoiseWrapper.h">
@@ -56,5 +59,8 @@
     <ClInclude Include="..\FactoryCraft\RandNoise.h">
       <Filter>world\generator\noise</Filter>
     </ClInclude>
+    <ClInclude Include="..\FactoryCraft\ShapedNoise.h">
+      <Filter>world\generator\noise</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>