mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Corrected probe init'ing so they don't fight for the cubemap idx order
Also correct deleting behavior so it updates indicies when a probe is removed Updated forward lighting to utilize the same math as deferred
This commit is contained in:
parent
a2aa241c92
commit
e87dc787ee
18 changed files with 426 additions and 375 deletions
|
|
@ -306,10 +306,9 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
|
|||
GFXShaderConstHandle *lightPositionSC,
|
||||
GFXShaderConstHandle *lightDiffuseSC,
|
||||
GFXShaderConstHandle *lightAmbientSC,
|
||||
GFXShaderConstHandle *lightInvRadiusSqSC,
|
||||
GFXShaderConstHandle *lightConfigDataSC,
|
||||
GFXShaderConstHandle *lightSpotDirSC,
|
||||
GFXShaderConstHandle *lightSpotAngleSC,
|
||||
GFXShaderConstHandle *lightSpotFalloffSC,
|
||||
GFXShaderConstHandle *lightSpotParamsSC,
|
||||
GFXShaderConstBuffer *shaderConsts )
|
||||
{
|
||||
PROFILE_SCOPE( LightManager_Update4LightConsts );
|
||||
|
|
@ -317,14 +316,110 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
|
|||
// Skip over gathering lights if we don't have to!
|
||||
if ( lightPositionSC->isValid() ||
|
||||
lightDiffuseSC->isValid() ||
|
||||
lightInvRadiusSqSC->isValid() ||
|
||||
lightConfigDataSC->isValid() ||
|
||||
lightSpotDirSC->isValid() ||
|
||||
lightSpotAngleSC->isValid() ||
|
||||
lightSpotFalloffSC->isValid() )
|
||||
lightSpotParamsSC->isValid() )
|
||||
{
|
||||
PROFILE_SCOPE( LightManager_Update4LightConsts_setLights );
|
||||
|
||||
static AlignedArray<Point4F> lightPositions( 3, sizeof( Point4F ) );
|
||||
//new setup
|
||||
const U32 MAX_FORWARD_LIGHTS = 4;
|
||||
|
||||
static AlignedArray<Point4F> lightPositions(MAX_FORWARD_LIGHTS, sizeof(Point4F));
|
||||
static AlignedArray<Point4F> lightSpotDirs(MAX_FORWARD_LIGHTS, sizeof(Point4F));
|
||||
static AlignedArray<Point4F> lightColors(MAX_FORWARD_LIGHTS, sizeof(Point4F));
|
||||
static AlignedArray<Point4F> lightConfigData(MAX_FORWARD_LIGHTS, sizeof(Point4F)); //type, brightness, range, invSqrRange : rgba
|
||||
static AlignedArray<Point4F> lightSpotParams(MAX_FORWARD_LIGHTS, sizeof(Point4F));
|
||||
|
||||
dMemset(lightPositions.getBuffer(), 0, lightPositions.getBufferSize());
|
||||
dMemset(lightSpotDirs.getBuffer(), 0, lightSpotDirs.getBufferSize());
|
||||
dMemset(lightColors.getBuffer(), 0, lightColors.getBufferSize());
|
||||
dMemset(lightConfigData.getBuffer(), 0, lightConfigData.getBufferSize());
|
||||
dMemset(lightSpotParams.getBuffer(), 0, lightSpotParams.getBufferSize());
|
||||
|
||||
//sun-only
|
||||
F32 vectorLightBrightness;
|
||||
static Point4F vectorLightDirection;
|
||||
static Point4F vectorLightColor;
|
||||
static Point4F vectorLightAmbientColor;
|
||||
int hasVectorLight = 0;
|
||||
|
||||
vectorLightBrightness = 0;
|
||||
vectorLightDirection = Point4F::Zero;
|
||||
vectorLightColor = Point4F::Zero;
|
||||
vectorLightAmbientColor = Point4F::Zero;
|
||||
|
||||
// Gather the data for the first 4 lights.
|
||||
const LightInfo* light;
|
||||
for (U32 i = 0; i < MAX_FORWARD_LIGHTS; i++)
|
||||
{
|
||||
light = sgData.lights[i];
|
||||
if (!light)
|
||||
break;
|
||||
|
||||
if (light->getType() == LightInfo::Vector)
|
||||
{
|
||||
if (hasVectorLight != 0)
|
||||
continue;
|
||||
|
||||
vectorLightBrightness = light->getBrightness();
|
||||
vectorLightDirection = light->getDirection();
|
||||
vectorLightColor = Point4F(light->getColor());
|
||||
vectorLightAmbientColor = Point4F(light->getAmbient());
|
||||
hasVectorLight = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// The light positions and spot directions are
|
||||
// in SoA order to make optimal use of the GPU.
|
||||
const Point3F& lightPos = light->getPosition();
|
||||
lightPositions[i].x = lightPos.x;
|
||||
lightPositions[i].y = lightPos.y;
|
||||
lightPositions[i].z = lightPos.z;
|
||||
lightPositions[i].w = 0;
|
||||
|
||||
const VectorF& lightDir = light->getDirection();
|
||||
lightSpotDirs[i].x = lightDir.x;
|
||||
lightSpotDirs[i].y = lightDir.y;
|
||||
lightSpotDirs[i].z = lightDir.z;
|
||||
lightSpotDirs[i].w = 0;
|
||||
|
||||
lightColors[i] = Point4F(light->getColor());
|
||||
|
||||
if (light->getType() == LightInfo::Point)
|
||||
{
|
||||
lightConfigData[i].x = 0;
|
||||
}
|
||||
else if (light->getType() == LightInfo::Spot)
|
||||
{
|
||||
lightConfigData[i].x = 1;
|
||||
|
||||
const F32 outerCone = light->getOuterConeAngle();
|
||||
const F32 innerCone = getMin(light->getInnerConeAngle(), outerCone);
|
||||
const F32 outerCos = mCos(mDegToRad(outerCone / 2.0f));
|
||||
const F32 innerCos = mCos(mDegToRad(innerCone / 2.0f));
|
||||
Point2F spotParams(outerCos, innerCos - outerCos);
|
||||
|
||||
lightSpotParams[i].x = spotParams.x;
|
||||
lightSpotParams[i].y = spotParams.y;
|
||||
}
|
||||
|
||||
lightConfigData[i].y = light->getBrightness();
|
||||
|
||||
F32 range = light->getRange().x;
|
||||
lightConfigData[i].z = range;
|
||||
lightConfigData[i].w = 1.0f / (range * range);
|
||||
}
|
||||
|
||||
shaderConsts->setSafe(lightPositionSC, lightPositions);
|
||||
shaderConsts->setSafe(lightDiffuseSC, lightColors);
|
||||
shaderConsts->setSafe(lightSpotDirSC, lightSpotDirs);
|
||||
shaderConsts->setSafe(lightConfigDataSC, lightConfigData);
|
||||
shaderConsts->setSafe(lightSpotParamsSC, lightSpotParams);
|
||||
|
||||
//================================================================
|
||||
//old setup
|
||||
/*static AlignedArray<Point4F> lightPositions( 3, sizeof( Point4F ) );
|
||||
static AlignedArray<Point4F> lightSpotDirs( 3, sizeof( Point4F ) );
|
||||
static AlignedArray<Point4F> lightColors( 4, sizeof( Point4F ) );
|
||||
static Point4F lightInvRadiusSq;
|
||||
|
|
@ -343,7 +438,7 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
|
|||
|
||||
// Gather the data for the first 4 lights.
|
||||
const LightInfo *light;
|
||||
for ( U32 i=0; i < 4; i++ )
|
||||
for ( U32 i=0; i < MAX_FORWARD_LIGHTS; i++ )
|
||||
{
|
||||
light = sgData.lights[i];
|
||||
if ( !light )
|
||||
|
|
@ -382,7 +477,7 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
|
|||
|
||||
shaderConsts->setSafe( lightSpotDirSC, lightSpotDirs );
|
||||
shaderConsts->setSafe( lightSpotAngleSC, lightSpotAngle );
|
||||
shaderConsts->setSafe( lightSpotFalloffSC, lightSpotFalloff );
|
||||
shaderConsts->setSafe( lightSpotFalloffSC, lightSpotFalloff );*/
|
||||
}
|
||||
|
||||
// Setup the ambient lighting from the first
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue