| 1419 | #endif |
| 1420 | float tr = 0.05; |
| 1421 | // Note: check where does nullptr texture come from |
| 1422 | if (texture) |
| 1423 | { |
| 1424 | tr = texture->Roughness(); |
| 1425 | } |
| 1426 | return bump * tr * bumpy; |
| 1427 | } |
| 1428 | |
| 1429 | float Landscape::BumpySurfaceY(float xC, float zC, float& rdX, float& rdY, Texture*& texture, float bumpy, |
| 1430 | float& bump) const |
| 1431 | { |
| 1432 | // fine rectangles are not used - use rough instead |
| 1433 | // calculate surface level on given coordinates |
| 1434 | float xRel = xC * _invTerrainGrid; |
| 1435 | float zRel = zC * _invTerrainGrid; |
| 1436 | int x = toIntFloor(xRel); |
| 1437 | int z = toIntFloor(zRel); |
| 1438 | float xIn = xRel - x; // relative 0..1 in square |
| 1439 | float zIn = zRel - z; |
| 1440 | |
| 1441 | bump = 0; |
| 1442 | #if !USE_SWIZZLED_ARRAYS |
| 1443 | if (!this_TerrainInRange(z, x) || !this_TerrainInRange(z + 1, x + 1)) |
| 1444 | { |
| 1445 | return YOutsideMap; // no bump outside landscape |
| 1446 | } |
| 1447 | float y00 = GetData(x, z); |
| 1448 | float y01 = GetData(x + 1, z); |
| 1449 | float y10 = GetData(x, z + 1); |
| 1450 | float y11 = GetData(x + 1, z + 1); |
| 1451 | #else |
| 1452 | if (!this_TerrainInRange(z, x) || !this_TerrainInRange(z + 1, x + 1)) |
| 1453 | return YOutsideMap; // no bump outside landscape |
| 1454 | RawType y4[2][2]; |
| 1455 | _data.GetFour(y4, x, z); |
| 1456 | float y00 = RawToHeight(y4[0][0]); |
| 1457 | float y01 = RawToHeight(y4[0][1]); |
| 1458 | float y10 = RawToHeight(y4[1][0]); |
| 1459 | float y11 = RawToHeight(y4[1][1]); |
| 1460 | #endif |
| 1461 | |
| 1462 | // each face is divided to two triangles |
| 1463 | // determine which triangle contains point |
| 1464 | float y; |
| 1465 | if (xIn <= 1 - zIn) |
| 1466 | { // triangle 00,01,10 |
| 1467 | rdX = (y01 - y00) * _invTerrainGrid; |
| 1468 | rdY = (y10 - y00) * _invTerrainGrid; |
| 1469 | y = y00 + (y10 - y00) * zIn + (y01 - y00) * xIn; |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1473 | // triangle 01,10,11 |
| 1474 | rdX = (y11 - y10) * _invTerrainGrid; |
| 1475 | rdY = (y11 - y01) * _invTerrainGrid; |
| 1476 | y = y11 + (y10 - y11) * (1 - xIn) + (y01 - y11) * (1 - zIn); |
| 1477 | } |
| 1478 | // depending on surface texture use roughness |