@@ -47,7 +47,7 @@ void terrainGenerator::Terrain::createTexture() {
4747 // minHeight,
4848 // maxHeight);
4949
50- double height = terrainMap [i][n - j - 1 ]. height ;
50+ double height = bufferHeights [i][n - j - 1 ];
5151
5252 double heightColor[3 ] = {height * 255 , height * 255 , height * 255 };
5353 chunkCanvas.draw_rectangle (iDraw * tileSize * 2 , jDraw * tileSize * 2 ,
@@ -95,8 +95,8 @@ void terrainGenerator::Terrain::createTexture() {
9595 heightFilter.channels (0 , 3 );
9696 // heightFilter.blur_box(10.0f,10.0f,1.0f);
9797
98- // chunkCanvas.draw_image(0, 0, heightFilter, 0.1 );
99- // multiptyImages(chunkCanvas, heightFilter, 1.0f);
98+ // chunkCanvas.draw_image(0, 0, heightFilter, 1.0 );
99+ multiptyImages (chunkCanvas, heightFilter, 1 .0f );
100100
101101 chunkCanvas.save (
102102 (" Resources/Chunks/TextureChunks/fieldTexture" + std::to_string (chunkID) + " .png" ).c_str ());
@@ -243,11 +243,30 @@ terrainGenerator::TileType terrainGenerator::Terrain::tileByHeight(double height
243243void terrainGenerator::Terrain::multiptyImages (cimg_library::CImg<double > &A, cimg_library::CImg<double > &mul,
244244 float coef) {
245245 cimg_forXY (A, x, y) {
246- if (A (x, y, 0 ) != white[0 ] &&
247- A (x, y, 1 ) != white[1 ] &&
246+ if (A (x, y, 0 ) != white[0 ] ||
247+ A (x, y, 1 ) != white[1 ] ||
248248 A (x, y, 2 ) != white[2 ]) {
249249 for (int i = 0 ; i < 3 ; i++) {
250- A (x, y, i) += mul (x, y, i) * coef;
250+ auto aColor = A (x, y, i);
251+ auto mulColor = mul (x, y, 0 );
252+ auto type = tileByHeight (mulColor / 255.0 );
253+
254+ double res;
255+ switch (type) {
256+ case TileType::grass:
257+ res = aColor * (0.25 + (mulColor / 255.0 ) * coef);
258+ break ;
259+ case TileType::water:
260+ res = aColor * (0.9 + (mulColor / 255.0 ) * coef);
261+ break ;
262+ case TileType::sand:
263+ res = aColor * (0.8 + (mulColor / 255.0 ) * coef);
264+ break ;
265+ case TileType::dirt:
266+ res = aColor * (0.6 + (mulColor / 255.0 ) * coef);
267+ break ;
268+ }
269+ A (x, y, i) = (res <= 255.0 ) ? (res) : 255.0 ;
251270 }
252271 }
253272 }
0 commit comments