| 510 | } |
| 511 | |
| 512 | void blTerrainProxy::lightVector(LightInfo * light) |
| 513 | { |
| 514 | // Grab our terrain object |
| 515 | TerrainBlock* terrain = getObject(); |
| 516 | if (!terrain) |
| 517 | return; |
| 518 | |
| 519 | // Get the direction to the light (the inverse of the direction |
| 520 | // the light is pointing) |
| 521 | Point3F lightDir = -light->getDirection(); |
| 522 | lightDir.normalize(); |
| 523 | |
| 524 | // Get the ratio between the light map pixel and world space (used below) |
| 525 | F32 lmTerrRatio = (F32)mTerrainBlockSize / (F32) mLightMapSize; |
| 526 | lmTerrRatio *= terrain->getSquareSize(); |
| 527 | |
| 528 | U32 i = 0; |
| 529 | for (U32 y = 0; y < mLightMapSize; y++) |
| 530 | { |
| 531 | for (U32 x = 0; x < mLightMapSize; x++) |
| 532 | { |
| 533 | // Get the relative pixel position and scale it |
| 534 | // by the ratio between lightmap and world space |
| 535 | Point2F pixelPos(x, y); |
| 536 | pixelPos *= lmTerrRatio; |
| 537 | |
| 538 | // Start with a default normal of straight up |
| 539 | Point3F normal(0.0f, 0.0f, 1.0f); |
| 540 | |
| 541 | // Try to get the actual normal from the terrain. |
| 542 | // Note: this won't change the default normal if |
| 543 | // it can't find a normal. |
| 544 | terrain->getNormal(pixelPos, &normal); |
| 545 | |
| 546 | // The terrain lightmap only contains shadows. |
| 547 | F32 shadowed = 0.0f; |
| 548 | |
| 549 | // Get the height at the lightmap pixel's position |
| 550 | F32 height = 0.0f; |
| 551 | terrain->getHeight(pixelPos, &height); |
| 552 | |
| 553 | // Calculate the 3D position of the pixel |
| 554 | Point3F pixelPos3F(pixelPos.x, pixelPos.y, height); |
| 555 | |
| 556 | // Translate that position by the terrain's transform |
| 557 | terrain->getTransform().mulP(pixelPos3F); |
| 558 | |
| 559 | // Offset slighting along the normal so that we don't |
| 560 | // raycast into ourself |
| 561 | pixelPos3F += (normal * 0.1f); |
| 562 | |
| 563 | // Calculate the light's position. |
| 564 | // If it is a vector light like the sun (no position |
| 565 | // just direction) then translate along that direction |
| 566 | // a reasonable distance to get a point sufficiently |
| 567 | // far away |
| 568 | Point3F lightPos = light->getPosition(); |
| 569 | if(light->getType() == LightInfo::Vector) |
nothing calls this directly
no test coverage detected