@@ -283,83 +283,88 @@ MeshNoisePreview::Chunk::MeshData MeshNoisePreview::Chunk::BuildMeshData( const
283
283
vertexData.clear ();
284
284
indicies.clear ();
285
285
286
- Vector3 light = LIGHT_DIR.normalized () * (1 .0f - AMBIENT_LIGHT) + Vector3 ( AMBIENT_LIGHT );
286
+ #if FASTNOISE_CALC_MIN_MAX
287
+ if ( minMax.min <= buildData.isoSurface && minMax.max >= buildData.isoSurface )
288
+ #endif
289
+ {
290
+ Vector3 light = LIGHT_DIR.normalized () * (1 .0f - AMBIENT_LIGHT) + Vector3 ( AMBIENT_LIGHT );
287
291
288
- float xLight = abs ( light.x () );
289
- Color3 colorRight = buildData.color * xLight;
290
- Color3 colorLeft = buildData.color * (1 .0f - xLight);
292
+ float xLight = abs ( light.x () );
293
+ Color3 colorRight = buildData.color * xLight;
294
+ Color3 colorLeft = buildData.color * (1 .0f - xLight);
291
295
292
- float yLight = abs ( light.y () );
293
- Color3 colorUp = buildData.color * yLight;
294
- Color3 colorDown = buildData.color * (1 .0f - yLight);
296
+ float yLight = abs ( light.y () );
297
+ Color3 colorUp = buildData.color * yLight;
298
+ Color3 colorDown = buildData.color * (1 .0f - yLight);
295
299
296
- float zLight = abs ( light.z () );
297
- Color3 colorForward = buildData.color * zLight;
298
- Color3 colorBack = buildData.color * (1 .0f - zLight);
300
+ float zLight = abs ( light.z () );
301
+ Color3 colorForward = buildData.color * zLight;
302
+ Color3 colorBack = buildData.color * (1 .0f - zLight);
299
303
300
- constexpr int32_t STEP_X = 1 ;
301
- constexpr int32_t STEP_Y = SIZE_GEN;
302
- constexpr int32_t STEP_Z = SIZE_GEN * SIZE_GEN;
304
+ constexpr int32_t STEP_X = 1 ;
305
+ constexpr int32_t STEP_Y = SIZE_GEN;
306
+ constexpr int32_t STEP_Z = SIZE_GEN * SIZE_GEN;
303
307
304
- int32_t noiseIdx = STEP_X + STEP_Y + STEP_Z;
308
+ int32_t noiseIdx = STEP_X + STEP_Y + STEP_Z;
305
309
306
- for ( uint32_t z = 0 ; z < SIZE; z++ )
307
- {
308
- float zf = z + (float )buildData.pos .z ();
309
-
310
- for ( uint32_t y = 0 ; y < SIZE; y++ )
310
+ for ( uint32_t z = 0 ; z < SIZE; z++ )
311
311
{
312
- float yf = y + (float )buildData.pos .y ();
312
+ float zf = z + (float )buildData.pos .z ();
313
313
314
- for ( uint32_t x = 0 ; x < SIZE; x ++ )
314
+ for ( uint32_t y = 0 ; y < SIZE; y ++ )
315
315
{
316
- float xf = x + (float )buildData.pos .x ();
316
+ float yf = y + (float )buildData.pos .y ();
317
317
318
- if ( densityValues[noiseIdx] <= buildData. isoSurface ) // isSolid
318
+ for ( uint32_t x = 0 ; x < SIZE; x++ )
319
319
{
320
- if ( densityValues[noiseIdx + STEP_X] > buildData.isoSurface ) // Right
321
- {
322
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_X, STEP_Y, STEP_Z, colorRight,
323
- Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf + 1 , yf + 1 , zf ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf, zf + 1 ) );
324
- }
325
-
326
- if ( densityValues[noiseIdx - STEP_X] > buildData.isoSurface ) // Left
327
- {
328
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_X, -STEP_Y, STEP_Z, colorLeft,
329
- Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf, yf, zf ), Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf, yf + 1 , zf + 1 ) );
330
- }
331
-
332
- if ( densityValues[noiseIdx + STEP_Y] > buildData.isoSurface ) // Up
333
- {
334
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_Y, STEP_Z, STEP_X, colorUp,
335
- Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf, yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf ) );
336
- }
337
-
338
- if ( densityValues[noiseIdx - STEP_Y] > buildData.isoSurface ) // Down
339
- {
340
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_Y, -STEP_Z, STEP_X, colorDown,
341
- Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf, yf, zf ), Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf + 1 , yf, zf + 1 ) );
342
- }
320
+ float xf = x + (float )buildData.pos .x ();
343
321
344
- if ( densityValues[noiseIdx + STEP_Z] > buildData.isoSurface ) // Forward
322
+ if ( densityValues[noiseIdx] <= buildData.isoSurface ) // isSolid
345
323
{
346
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_Z, STEP_X, STEP_Y, colorForward,
347
- Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf + 1 , yf, zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf, yf + 1 , zf + 1 ) );
348
- }
349
-
350
- if ( densityValues[noiseIdx - STEP_Z] > buildData.isoSurface ) // Back
351
- {
352
- AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_Z, -STEP_X, STEP_Y, colorBack,
353
- Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf, yf, zf ), Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf + 1 , yf + 1 , zf ) );
324
+ if ( densityValues[noiseIdx + STEP_X] > buildData.isoSurface ) // Right
325
+ {
326
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_X, STEP_Y, STEP_Z, colorRight,
327
+ Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf + 1 , yf + 1 , zf ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf, zf + 1 ) );
328
+ }
329
+
330
+ if ( densityValues[noiseIdx - STEP_X] > buildData.isoSurface ) // Left
331
+ {
332
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_X, -STEP_Y, STEP_Z, colorLeft,
333
+ Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf, yf, zf ), Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf, yf + 1 , zf + 1 ) );
334
+ }
335
+
336
+ if ( densityValues[noiseIdx + STEP_Y] > buildData.isoSurface ) // Up
337
+ {
338
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_Y, STEP_Z, STEP_X, colorUp,
339
+ Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf, yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf ) );
340
+ }
341
+
342
+ if ( densityValues[noiseIdx - STEP_Y] > buildData.isoSurface ) // Down
343
+ {
344
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_Y, -STEP_Z, STEP_X, colorDown,
345
+ Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf, yf, zf ), Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf + 1 , yf, zf + 1 ) );
346
+ }
347
+
348
+ if ( densityValues[noiseIdx + STEP_Z] > buildData.isoSurface ) // Forward
349
+ {
350
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, STEP_Z, STEP_X, STEP_Y, colorForward,
351
+ Vector3 ( xf, yf, zf + 1 ), Vector3 ( xf + 1 , yf, zf + 1 ), Vector3 ( xf + 1 , yf + 1 , zf + 1 ), Vector3 ( xf, yf + 1 , zf + 1 ) );
352
+ }
353
+
354
+ if ( densityValues[noiseIdx - STEP_Z] > buildData.isoSurface ) // Back
355
+ {
356
+ AddQuadAO ( vertexData, indicies, densityValues, buildData.isoSurface , noiseIdx, -STEP_Z, -STEP_X, STEP_Y, colorBack,
357
+ Vector3 ( xf + 1 , yf, zf ), Vector3 ( xf, yf, zf ), Vector3 ( xf, yf + 1 , zf ), Vector3 ( xf + 1 , yf + 1 , zf ) );
358
+ }
354
359
}
360
+ noiseIdx++;
355
361
}
356
- noiseIdx++;
362
+
363
+ noiseIdx += STEP_X * 2 ;
357
364
}
358
365
359
- noiseIdx += STEP_X * 2 ;
366
+ noiseIdx += STEP_Y * 2 ;
360
367
}
361
-
362
- noiseIdx += STEP_Y * 2 ;
363
368
}
364
369
365
370
MeshData meshData ( buildData.pos , minMax, vertexData, indicies );
0 commit comments