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:
Areloch 2019-06-30 23:04:16 -05:00
parent a2aa241c92
commit e87dc787ee
18 changed files with 426 additions and 375 deletions

View file

@ -388,10 +388,9 @@ void AdvancedLightManager::setLightInfo( ProcessedMaterial *pmat,
lsc->mLightPositionSC,
lsc->mLightDiffuseSC,
lsc->mLightAmbientSC,
lsc->mLightInvRadiusSqSC,
lsc->mLightConfigDataSC,
lsc->mLightSpotDirSC,
lsc->mLightSpotAngleSC,
lsc->mLightSpotFalloffSC,
lsc->mLightSpotParamsSC,
shaderConsts );
// Static

View file

@ -304,10 +304,9 @@ BasicLightManager::LightingShaderConstants::LightingShaderConstants()
mLightPosition( NULL ),
mLightDiffuse( NULL ),
mLightAmbient( NULL ),
mLightInvRadiusSq( NULL ),
mLightConfigDataSC( NULL ),
mLightSpotDir( NULL ),
mLightSpotAngle( NULL ),
mLightSpotFalloff( NULL )
mLightSpotParamsSC( NULL )
{
}
@ -333,11 +332,10 @@ void BasicLightManager::LightingShaderConstants::init(GFXShader* shader)
mLightPosition = shader->getShaderConstHandle( ShaderGenVars::lightPosition );
mLightDiffuse = shader->getShaderConstHandle( ShaderGenVars::lightDiffuse);
mLightInvRadiusSq = shader->getShaderConstHandle( ShaderGenVars::lightInvRadiusSq );
mLightConfigDataSC = shader->getShaderConstHandle( ShaderGenVars::lightConfigData );
mLightAmbient = shader->getShaderConstHandle( ShaderGenVars::lightAmbient );
mLightSpotDir = shader->getShaderConstHandle( ShaderGenVars::lightSpotDir );
mLightSpotAngle = shader->getShaderConstHandle( ShaderGenVars::lightSpotAngle );
mLightSpotFalloff = shader->getShaderConstHandle( ShaderGenVars::lightSpotFalloff );
mLightSpotParamsSC = shader->getShaderConstHandle( ShaderGenVars::lightSpotParams );
mInit = true;
}
@ -399,9 +397,8 @@ void BasicLightManager::setLightInfo( ProcessedMaterial* pmat,
mLastConstants->mLightPosition,
mLastConstants->mLightDiffuse,
mLastConstants->mLightAmbient,
mLastConstants->mLightInvRadiusSq,
mLastConstants->mLightConfigDataSC,
mLastConstants->mLightSpotDir,
mLastConstants->mLightSpotAngle,
mLastConstants->mLightSpotFalloff,
mLastConstants->mLightSpotParamsSC,
shaderConsts );
}

View file

@ -88,10 +88,9 @@ protected:
GFXShaderConstHandle *mLightPosition;
GFXShaderConstHandle *mLightDiffuse;
GFXShaderConstHandle *mLightAmbient;
GFXShaderConstHandle *mLightInvRadiusSq;
GFXShaderConstHandle *mLightConfigDataSC;
GFXShaderConstHandle *mLightSpotDir;
GFXShaderConstHandle *mLightSpotAngle;
GFXShaderConstHandle *mLightSpotFalloff;
GFXShaderConstHandle *mLightSpotParamsSC;
LightingShaderConstants();
~LightingShaderConstants();

View file

@ -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

View file

@ -177,8 +177,7 @@ protected:
GFXShaderConstHandle *lightAmbientSC,
GFXShaderConstHandle *lightInvRadiusSqSC,
GFXShaderConstHandle *lightSpotDirSC,
GFXShaderConstHandle *lightSpotAngleSC,
GFXShaderConstHandle *lightSpotFalloffSC,
GFXShaderConstHandle * lightSpotParamsSC,
GFXShaderConstBuffer *shaderConsts );
/// A dummy default light used when no lights

View file

@ -460,10 +460,8 @@ LightingShaderConstants::LightingShaderConstants()
mLightPositionSC(NULL),
mLightDiffuseSC(NULL),
mLightAmbientSC(NULL),
mLightInvRadiusSqSC(NULL),
mLightConfigDataSC(NULL),
mLightSpotDirSC(NULL),
mLightSpotAngleSC(NULL),
mLightSpotFalloffSC(NULL),
mShadowMapSC(NULL),
mDynamicShadowMapSC(NULL),
mShadowMapSizeSC(NULL),
@ -524,10 +522,8 @@ void LightingShaderConstants::init(GFXShader* shader)
mLightPositionSC = shader->getShaderConstHandle( ShaderGenVars::lightPosition );
mLightDiffuseSC = shader->getShaderConstHandle( ShaderGenVars::lightDiffuse );
mLightAmbientSC = shader->getShaderConstHandle( ShaderGenVars::lightAmbient );
mLightInvRadiusSqSC = shader->getShaderConstHandle( ShaderGenVars::lightInvRadiusSq );
mLightConfigDataSC = shader->getShaderConstHandle( ShaderGenVars::lightConfigData);
mLightSpotDirSC = shader->getShaderConstHandle( ShaderGenVars::lightSpotDir );
mLightSpotAngleSC = shader->getShaderConstHandle( ShaderGenVars::lightSpotAngle );
mLightSpotFalloffSC = shader->getShaderConstHandle( ShaderGenVars::lightSpotFalloff );
mShadowMapSC = shader->getShaderConstHandle("$shadowMap");
mDynamicShadowMapSC = shader->getShaderConstHandle("$dynamicShadowMap");

View file

@ -87,10 +87,8 @@ struct LightingShaderConstants
GFXShaderConstHandle *mLightPositionSC;
GFXShaderConstHandle *mLightDiffuseSC;
GFXShaderConstHandle *mLightAmbientSC;
GFXShaderConstHandle *mLightInvRadiusSqSC;
GFXShaderConstHandle *mLightConfigDataSC;
GFXShaderConstHandle *mLightSpotDirSC;
GFXShaderConstHandle *mLightSpotAngleSC;
GFXShaderConstHandle *mLightSpotFalloffSC;
GFXShaderConstHandle* mShadowMapSC;
GFXShaderConstHandle* mDynamicShadowMapSC;

View file

@ -317,10 +317,10 @@ void RenderProbeMgr::addElement(RenderInst *inst)
ProbeRenderInst* RenderProbeMgr::registerProbe()
{
ProbeRenderInst newProbe;
mRegisteredProbes.increment();
ProbeRenderInst* newProbe = &mRegisteredProbes.last();
mRegisteredProbes.push_back(newProbe);
newProbe.mProbeIdx = mRegisteredProbes.size();
newProbe->mProbeIdx = mRegisteredProbes.size() - 1;
const U32 cubeIndex = _findNextEmptyCubeSlot();
if (cubeIndex == INVALID_CUBE_SLOT)
@ -349,18 +349,18 @@ ProbeRenderInst* RenderProbeMgr::registerProbe()
mCubeSlotCount += PROBE_ARRAY_SLOT_BUFFER_SIZE;
}
newProbe.mCubemapIndex = cubeIndex;
newProbe->mCubemapIndex = cubeIndex;
//mark cubemap slot as taken
mCubeMapSlots[cubeIndex] = true;
mCubeMapCount++;
#ifdef TORQUE_DEBUG
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", newProbe.mProbeIdx, cubeIndex);
Con::warnf("RenderProbeMgr::registerProbe: Registered probe %u to cubeIndex %u", newProbe->mProbeIdx, cubeIndex);
#endif
mProbesDirty = true;
return &mRegisteredProbes.last();
return newProbe;
}
void RenderProbeMgr::unregisterProbe(U32 probeIdx)
@ -378,6 +378,12 @@ void RenderProbeMgr::unregisterProbe(U32 probeIdx)
mRegisteredProbes.erase(probeIdx);
//recalculate all the probe's indicies just to be sure
for (U32 i = 0; i < mRegisteredProbes.size(); i++)
{
mRegisteredProbes[i].mProbeIdx == i;
}
//rebuild our probe data
mProbesDirty = true;
}
@ -750,7 +756,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
mProbeArrayEffect->setCubemapArrayTexture(5, mIrradianceArray);
mProbeArrayEffect->setShaderConst("$numProbes", (S32)mEffectiveProbeCount);
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", mSkylightCubemapIdx);
mProbeArrayEffect->setShaderConst("$skylightCubemapIdx", (S32)mSkylightCubemapIdx);
mProbeArrayEffect->setShaderConst("$cubeMips", (float)mMipCount);

View file

@ -818,6 +818,74 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector<ShaderComponent*> &compon
return outTex;
}
Var* ShaderFeatureHLSL::getSurface(Vector<ShaderComponent*>& componentList, MultiLine* meta)
{
ShaderConnector* connectComp = dynamic_cast<ShaderConnector*>(componentList[C_CONNECTOR]);
Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var* matinfo = (Var*)LangElement::find("PBRConfig");
if (!matinfo)
{
Var* metalness = (Var*)LangElement::find("metalness");
if (!metalness)
{
metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
}
Var* smoothness = (Var*)LangElement::find("smoothness");
if (!smoothness)
{
smoothness = new Var("smoothness", "float");
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
}
matinfo = new Var("PBRConfig", "float4");
LangElement* colorDecl = new DecOp(matinfo);
meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening
}
Var* inTex = getInTexCoord("texCoord", "float2", componentList);
if (!inTex)
return nullptr;
Var* wsNormal = (Var*)LangElement::find("wsNormal");
if (!wsNormal)
{
wsNormal = connectComp->getElement(RT_TEXCOORD);
wsNormal->setName("wsNormal");
wsNormal->setStructName("IN");
wsNormal->setType("float3");
// If we loaded the normal its our responsibility
// to normalize it... the interpolators won't.
//
// Note we cast to half here to get partial precision
// optimized code which is an acceptable loss of
// precision for normals and performs much better
// on older Geforce cards.
//
meta->addStatement(new GenOp(" @ = normalize( half3( @ ) );\r\n", wsNormal, wsNormal));
}
Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
Var* wsPosition = getInWsPosition(componentList);
Var* wsView = getWsView(wsPosition, meta);
Var* surface = (Var*)LangElement::find("surface");
if (!surface)
{
surface = new Var("surface", "Surface");
meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, wsNormal, matinfo,
inTex, wsPosition, wsEyePos, wsView));
}
return surface;
}
//****************************************************************************
// Base Texture
//****************************************************************************
@ -2157,10 +2225,10 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
Var *wsView = getWsView( wsPosition, meta );
// Create temporaries to hold results of lighting.
Var *rtShading = new Var( "rtShading", "float4" );
Var *specular = new Var( "specular", "float4" );
meta->addStatement( new GenOp( " @; @;\r\n",
new DecOp( rtShading ), new DecOp( specular ) ) );
//Var *rtShading = new Var( "rtShading", "float4" );
//Var *specular = new Var( "specular", "float4" );
//meta->addStatement( new GenOp( " @; @;\r\n",
// new DecOp( rtShading ), new DecOp( specular ) ) );
// Look for a light mask generated from a previous
// feature (this is done for BL terrain lightmaps).
@ -2171,12 +2239,13 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
// Get all the light constants.
Var *inLightPos = new Var( "inLightPos", "float4" );
inLightPos->uniform = true;
inLightPos->arraySize = 3;
inLightPos->arraySize = 4;
inLightPos->constSortPos = cspPotentialPrimitive;
Var *inLightInvRadiusSq = new Var( "inLightInvRadiusSq", "float4" );
inLightInvRadiusSq->uniform = true;
inLightInvRadiusSq->constSortPos = cspPotentialPrimitive;
Var * inLightConfigData = new Var( "inLightConfigData", "float4" );
inLightConfigData->uniform = true;
inLightConfigData->arraySize = 4;
inLightConfigData->constSortPos = cspPotentialPrimitive;
Var *inLightColor = new Var( "inLightColor", "float4" );
inLightColor->uniform = true;
@ -2185,19 +2254,23 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
Var *inLightSpotDir = new Var( "inLightSpotDir", "float4" );
inLightSpotDir->uniform = true;
inLightSpotDir->arraySize = 3;
inLightSpotDir->arraySize = 4;
inLightSpotDir->constSortPos = cspPotentialPrimitive;
Var *inLightSpotAngle = new Var( "inLightSpotAngle", "float4" );
inLightSpotAngle->uniform = true;
inLightSpotAngle->constSortPos = cspPotentialPrimitive;
Var * lightSpotParams = new Var( "lightSpotParams", "float4" );
lightSpotParams->uniform = true;
lightSpotParams->arraySize = 4;
lightSpotParams->constSortPos = cspPotentialPrimitive;
Var *lightSpotFalloff = new Var( "inLightSpotFalloff", "float4" );
lightSpotFalloff->uniform = true;
lightSpotFalloff->constSortPos = cspPotentialPrimitive;
Var* surface = getSurface(componentList, meta);
if (!surface)
{
Con::errorf("ShaderGen::RTLightingFeatHLSL() - failed to generate surface!");
return;
}
Var *smoothness = (Var*)LangElement::find("smoothness");
if (!fd.features[MFT_SpecularMap])
/*if (!fd.features[MFT_SpecularMap])
{
if (!smoothness)
{
@ -2205,10 +2278,10 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
}
}
}*/
Var *metalness = (Var*)LangElement::find("metalness");
if (!fd.features[MFT_SpecularMap])
/*if (!fd.features[MFT_SpecularMap])
{
if (!metalness)
{
@ -2216,7 +2289,7 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
}
}
}*/
Var *albedo = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
@ -2225,16 +2298,24 @@ void RTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
ambient->constSortPos = cspPass;
// Calculate the diffuse shading and specular powers.
meta->addStatement( new GenOp( " compute4Lights( @, @, @, @,\r\n"
/*meta->addStatement( new GenOp( " compute4Lights( @, @, @, @,\r\n"
" @, @, @, @, @, @, @, @, @,\r\n"
" @, @ );\r\n",
wsView, wsPosition, wsNormal, lightMask,
inLightPos, inLightInvRadiusSq, inLightColor, inLightSpotDir, inLightSpotAngle, lightSpotFalloff, smoothness, metalness, albedo,
inLightPos, inLightConfigData, inLightColor, inLightSpotDir, inLightSpotAngle, lightSpotFalloff, smoothness, metalness, albedo,
rtShading, specular ) );
// Apply the lighting to the diffuse color.
LangElement *lighting = new GenOp( "float4( @.rgb + @.rgb, 1 )", rtShading, ambient );
meta->addStatement( new GenOp( " @;\r\n", assignColor( lighting, Material::Mul ) ) );
meta->addStatement( new GenOp( " @;\r\n", assignColor( lighting, Material::Mul ) ) );*/
Var* lighting = new Var("lighting", "float4");
meta->addStatement(new GenOp(" @ = compute4Lights( @, @, @, @,\r\n"
" @, @, @);\r\n",
new DecOp(lighting), surface, lightMask, inLightPos, inLightConfigData, inLightColor, inLightSpotDir, lightSpotParams));
meta->addStatement(new GenOp(" @;\r\n", assignColor(lighting, Material::Add)));
output = meta;
}
@ -3051,6 +3132,14 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
irradianceCubemapARTex->uniform = true;
irradianceCubemapARTex->texture = true;
irradianceCubemapARTex->constNum = irradianceCubemapAR->constNum;
Var* surface = getSurface(componentList, meta);
if (!surface)
{
Con::errorf("ShaderGen::ReflectionProbeFeatHLSL() - failed to generate surface!");
return;
}
Var *inTex = getInTexCoord("texCoord", "float2", componentList);
if (!inTex)
@ -3059,55 +3148,15 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
Var *diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var *matinfo = (Var*)LangElement::find("PBRConfig");
if (!matinfo)
{
Var* metalness = (Var*)LangElement::find("metalness");
if (!metalness)
{
metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
}
Var* smoothness = (Var*)LangElement::find("smoothness");
if (!smoothness)
{
smoothness = new Var("smoothness", "float");
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
}
matinfo = new Var("PBRConfig", "float4");
LangElement* colorDecl = new DecOp(matinfo);
meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening
}
Var* metalness = (Var*)LangElement::find("metalness");
Var* smoothness = (Var*)LangElement::find("smoothness");
Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
Var* worldToTangent = getInWorldToTangent(componentList);
Var* wsNormal = (Var*)LangElement::find("wsNormal");
if (!wsNormal)
{
wsNormal = connectComp->getElement(RT_TEXCOORD);
wsNormal->setName("wsNormal");
wsNormal->setStructName("IN");
wsNormal->setType("float3");
// If we loaded the normal its our responsibility
// to normalize it... the interpolators won't.
//
// Note we cast to half here to get partial precision
// optimized code which is an acceptable loss of
// precision for normals and performs much better
// on older Geforce cards.
//
meta->addStatement(new GenOp(" @ = normalize( half3( @ ) );\r\n", wsNormal, wsNormal));
}
//Reflection vec
Var* surface = new Var("surface", "Surface");
meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, wsNormal, matinfo,
inTex, wsPosition, wsEyePos, wsView));
String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t");
computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n");

View file

@ -135,6 +135,8 @@ public:
bool useInstancing,
MultiLine *meta );
Var* getSurface(Vector<ShaderComponent*>& componentList, MultiLine* meta);
// ShaderFeature
Var* getVertTexCoord( const String &name );
LangElement* setupTexSpaceMat( Vector<ShaderComponent*> &componentList, Var **texSpaceMat );

View file

@ -61,10 +61,9 @@ const String ShaderGenVars::oneOverTargetSize("$oneOverTargetSize");
const String ShaderGenVars::lightPosition("$inLightPos");
const String ShaderGenVars::lightDiffuse("$inLightColor");
const String ShaderGenVars::lightAmbient("$ambient");
const String ShaderGenVars::lightInvRadiusSq("$inLightInvRadiusSq");
const String ShaderGenVars::lightConfigData("$inLightConfigData");
const String ShaderGenVars::lightSpotDir("$inLightSpotDir");
const String ShaderGenVars::lightSpotAngle("$inLightSpotAngle");
const String ShaderGenVars::lightSpotFalloff("$inLightSpotFalloff");
const String ShaderGenVars::lightSpotParams("$lightSpotParams");
const String ShaderGenVars::specularColor("$specularColor");
const String ShaderGenVars::smoothness("$smoothness");
const String ShaderGenVars::metalness("$metalness");

View file

@ -74,10 +74,9 @@ struct ShaderGenVars
const static String lightPosition;
const static String lightDiffuse;
const static String lightAmbient;
const static String lightInvRadiusSq;
const static String lightConfigData;
const static String lightSpotDir;
const static String lightSpotAngle;
const static String lightSpotFalloff;
const static String lightSpotParams;
const static String specularColor;
const static String smoothness;
const static String metalness;

View file

@ -28,12 +28,12 @@
// These are the uniforms used by most lighting shaders.
uniform float4 inLightPos[3];
uniform float4 inLightInvRadiusSq;
uniform float4 inLightPos[4];
uniform float4 inLightConfigData[4];
uniform float4 inLightColor[4];
#ifndef TORQUE_BL_NOSPOTLIGHT
uniform float4 inLightSpotDir[3];
uniform float4 inLightSpotDir[4];
uniform float4 inLightSpotAngle;
uniform float4 inLightSpotFalloff;
#endif
@ -48,6 +48,8 @@ uniform float4 albedo;
#define MAX_PROBES 50
#define MAX_FORWARD_PROBES 4
#define MAX_FORWARD_LIGHT 4
inline float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
{
float denum = dot( plane.xyz, direction.xyz );
@ -65,146 +67,6 @@ inline float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 directio
return direction.xyz * t;
}
//TODO fix compute 4 lights
void compute4Lights( float3 wsView,
float3 wsPosition,
float3 wsNormal,
float4 shadowMask,
#ifdef TORQUE_SHADERGEN
float4 inLightPos[3],
float4 inLightInvRadiusSq,
float4 inLightColor[4],
float4 inLightSpotDir[3],
float4 inLightSpotAngle,
float4 inLightSpotFalloff,
float smoothness,
float metalness,
float4 albedo,
#endif // TORQUE_SHADERGEN
out float4 outDiffuse,
out float4 outSpecular )
{
// NOTE: The light positions and spotlight directions
// are stored in SoA order, so inLightPos[0] is the
// x coord for all 4 lights... inLightPos[1] is y... etc.
//
// This is the key to fully utilizing the vector units and
// saving a huge amount of instructions.
//
// For example this change saved more than 10 instructions
// over a simple for loop for each light.
int i;
float4 lightVectors[3];
for ( i = 0; i < 3; i++ )
lightVectors[i] = wsPosition[i] - inLightPos[i];
float4 squareDists = 0;
for ( i = 0; i < 3; i++ )
squareDists += lightVectors[i] * lightVectors[i];
// Accumulate the dot product between the light
// vector and the normal.
//
// The normal is negated because it faces away from
// the surface and the light faces towards the
// surface... this keeps us from needing to flip
// the light vector direction which complicates
// the spot light calculations.
//
// We normalize the result a little later.
//
float4 nDotL = 0;
for ( i = 0; i < 3; i++ )
nDotL += lightVectors[i] * -wsNormal[i];
float4 rDotL = 0;
#ifndef TORQUE_BL_NOSPECULAR
// We're using the Phong specular reflection model
// here where traditionally Torque has used Blinn-Phong
// which has proven to be more accurate to real materials.
//
// We do so because its cheaper as do not need to
// calculate the half angle for all 4 lights.
//
// Advanced Lighting still uses Blinn-Phong, but the
// specular reconstruction it does looks fairly similar
// to this.
//
float3 R = reflect( wsView, -wsNormal );
for ( i = 0; i < 3; i++ )
rDotL += lightVectors[i] * R[i];
#endif
// Normalize the dots.
//
// Notice we're using the half type here to get a
// much faster sqrt via the rsq_pp instruction at
// the loss of some precision.
//
// Unless we have some extremely large point lights
// i don't believe the precision loss will matter.
//
half4 correction = (half4)rsqrt( squareDists );
nDotL = saturate( nDotL * correction );
rDotL = clamp( rDotL * correction, 0.00001, 1.0 );
// First calculate a simple point light linear
// attenuation factor.
//
// If this is a directional light the inverse
// radius should be greater than the distance
// causing the attenuation to have no affect.
//
float4 atten = saturate( 1.0 - ( squareDists * inLightInvRadiusSq ) );
#ifndef TORQUE_BL_NOSPOTLIGHT
// The spotlight attenuation factor. This is really
// fast for what it does... 6 instructions for 4 spots.
float4 spotAtten = 0;
for ( i = 0; i < 3; i++ )
spotAtten += lightVectors[i] * inLightSpotDir[i];
float4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
atten *= saturate( cosAngle * inLightSpotFalloff );
#endif
// Finally apply the shadow masking on the attenuation.
atten *= shadowMask;
// Get the final light intensity.
float4 intensity = nDotL * atten;
// Combine the light colors for output.
outDiffuse = 0;
for ( i = 0; i < 4; i++ )
outDiffuse += intensity[i] * inLightColor[i];
// Output the specular power.
float4 specularIntensity = pow( rDotL, float4(1,1,1,1) ) * atten;
// Apply the per-light specular attenuation.
float4 specular = float4(0,0,0,1);
for ( i = 0; i < 4; i++ )
specular += float4( inLightColor[i].rgb * inLightColor[i].a * specularIntensity[i], 1 );
// Add the final specular intensity values together
// using a single dot product operation then get the
// final specular lighting color.
outSpecular = float4(1,1,1,1) * specular;
}
struct Surface
{
float3 P; // world space position
@ -372,6 +234,57 @@ inline float3 getPunctualLight(in Surface surface, in SurfaceToLight surfaceToLi
return final;
}
float4 compute4Lights( Surface surface,
float4 shadowMask,
float4 inLightPos[4],
float4 inLightConfigData[4],
float4 inLightColor[4],
float4 inLightSpotDir[4],
float4 lightSpotParams[4] )
{
float3 finalLighting = 0.0.xxx;
int i;
for(i = 0; i < MAX_FORWARD_LIGHT; i++)
{
float3 L = inLightPos[i].xyz - surface.P;
float dist = length(L);
float lightRange = inLightConfigData[i].z;
SurfaceToLight surfaceToLight = createSurfaceToLight(surface, L);
float shadowed = 1.0;
float3 lightCol = inLightColor[i].rgb;
float lightBrightness = inLightConfigData[i].y;
float lightInvSqrRange= inLightConfigData[i].a;
float3 lighting = 0.0.xxx;
[branch]
if(dist < lightRange)
{
[branch]
if(inLightConfigData[i].x == 0) //point
{
//get punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
}
else //spot
{
//get Punctual light contribution
lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadowed);
//get spot angle attenuation
lighting *= getSpotAngleAtt(-surfaceToLight.L, inLightSpotDir[i].xyz, lightSpotParams[i].xy );
}
}
finalLighting += lighting;
}
return float4(finalLighting,1);
}
//Probe IBL stuff
float defineSphereSpaceInfluence(float3 wsPosition, float3 wsProbePosition, float radius)
{

View file

@ -32,7 +32,7 @@ uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
uniform float4 probeContribColors[MAX_PROBES];
#endif
uniform float skylightCubemapIdx;
uniform int skylightCubemapIdx;
float4 main(PFXVertToPix IN) : SV_TARGET
{
@ -140,7 +140,7 @@ float4 main(PFXVertToPix IN) : SV_TARGET
//Skylight coloration for anything not covered by probes above
if(skylightCubemapIdx != -1)
finalContribColor += float3(0.3, 0.3, 0.3) * contribAlpha;
finalContribColor += float3(0, 1, 0) * contribAlpha;
return float4(finalContribColor, 1);
#endif

View file

@ -7,8 +7,8 @@ singleton Material(Grid_512_Orange)
specular[0] = "0.8 0.8 0.8 1";
specularPower[0] = "0.25";
specularStrength[0] = "25";
translucentBlendOp = "Add";
smoothness[0] = "0.941176";
translucentBlendOp = "LerpAlpha";
smoothness[0] = "1";
metalness[0] = "1";
DiffuseMapAsset0 = "StaticShapeTest:Grid_512_orange_ALBEDO";
specularStrength0 = "25";

View file

@ -1,59 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<EditorSettings>
<Group name="Theme">
<Setting name="tooltipDividerColor">72 70 68 255</Setting>
<Setting name="headerTextColor">236 234 232 255</Setting>
<Setting name="tabsSELColor">59 58 57 255</Setting>
<Setting name="fieldBGHLColor">72 70 68 255</Setting>
<Setting name="tooltipTextColor">255 255 255 255</Setting>
<Setting name="fieldTextColor">178 175 172 255</Setting>
<Setting name="windowBackgroundColor">32 31 30 255</Setting>
<Setting name="headerColor">50 49 48 255</Setting>
<Setting name="dividerDarkColor">17 16 15 255</Setting>
<Setting name="fieldBGColor">59 58 57 255</Setting>
<Setting name="tooltipBGColor">43 43 43 255</Setting>
<Setting name="fieldTextSELColor">240 240 240 255</Setting>
<Setting name="fieldBGSELColor">100 98 96 255</Setting>
<Setting name="tabsColor">37 36 35 255</Setting>
<Setting name="dividerLightColor">96 94 92 255</Setting>
<Setting name="fieldTextHLColor">234 232 230 255</Setting>
<Setting name="tabsHLColor">50 49 48 255</Setting>
<Setting name="dividerMidColor">50 49 48 255</Setting>
</Group>
<Group name="GuiEditor">
<Setting name="previewResolution">1024 768</Setting>
<Setting name="lastPath">tools/gui</Setting>
<Group name="EngineDevelopment">
<Setting name="showEditorProfiles">0</Setting>
<Setting name="toggleIntoEditor">0</Setting>
<Setting name="showEditorGuis">0</Setting>
</Group>
<Group name="Help">
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
</Group>
<Group name="Selection">
<Setting name="fullBox">0</Setting>
</Group>
<Group name="Snapping">
<Setting name="snap2Grid">0</Setting>
<Setting name="snapToCanvas">1</Setting>
<Setting name="snapToGuides">1</Setting>
<Setting name="sensitivity">2</Setting>
<Setting name="snapToEdges">1</Setting>
<Setting name="snapToCenters">1</Setting>
<Setting name="snapToControls">1</Setting>
<Setting name="snap2GridSize">8</Setting>
</Group>
<Group name="Rendering">
<Setting name="drawBorderLines">1</Setting>
<Setting name="drawGuides">1</Setting>
</Group>
<Group name="Library">
<Setting name="viewType">Categorized</Setting>
</Group>
</Group>
<Group name="AxisGizmo">
<Setting name="rotationSnap">15</Setting>
<Setting name="mouseRotateScalar">0.8</Setting>
@ -63,95 +9,149 @@
<Setting name="mouseScaleScalar">0.8</Setting>
<Setting name="renderInfoText">1</Setting>
<Group name="Grid">
<Setting name="renderPlane">0</Setting>
<Setting name="gridColor">255 255 255 20</Setting>
<Setting name="gridSize">10 10 10</Setting>
<Setting name="planeDim">500</Setting>
<Setting name="gridColor">255 255 255 20</Setting>
<Setting name="renderPlaneHashes">0</Setting>
<Setting name="renderPlane">0</Setting>
<Setting name="snapToGrid">0</Setting>
<Setting name="renderPlaneHashes">0</Setting>
</Group>
</Group>
<Group name="Theme">
<Setting name="tooltipDividerColor">72 70 68 255</Setting>
<Setting name="fieldTextColor">178 175 172 255</Setting>
<Setting name="fieldBGHLColor">72 70 68 255</Setting>
<Setting name="fieldTextSELColor">240 240 240 255</Setting>
<Setting name="dividerMidColor">50 49 48 255</Setting>
<Setting name="windowBackgroundColor">32 31 30 255</Setting>
<Setting name="dividerLightColor">96 94 92 255</Setting>
<Setting name="dividerDarkColor">17 16 15 255</Setting>
<Setting name="fieldBGColor">59 58 57 255</Setting>
<Setting name="tooltipBGColor">43 43 43 255</Setting>
<Setting name="tabsColor">37 36 35 255</Setting>
<Setting name="tabsHLColor">50 49 48 255</Setting>
<Setting name="headerTextColor">236 234 232 255</Setting>
<Setting name="headerColor">50 49 48 255</Setting>
<Setting name="fieldBGSELColor">100 98 96 255</Setting>
<Setting name="tabsSELColor">59 58 57 255</Setting>
<Setting name="fieldTextHLColor">234 232 230 255</Setting>
<Setting name="tooltipTextColor">255 255 255 255</Setting>
</Group>
<Group name="WorldEditor">
<Setting name="orthoFOV">50</Setting>
<Setting name="displayType">6</Setting>
<Setting name="forceLoadDAE">0</Setting>
<Setting name="dropType">screenCenter</Setting>
<Setting name="undoLimit">40</Setting>
<Setting name="currentEditor">WorldEditorInspectorPlugin</Setting>
<Setting name="forceLoadDAE">0</Setting>
<Setting name="torsionPath">AssetWork_Debug.exe</Setting>
<Setting name="orthoShowGrid">1</Setting>
<Group name="Tools">
<Setting name="objectsUseBoxCenter">1</Setting>
<Setting name="dropAtScreenCenterScalar">1</Setting>
<Setting name="snapGround">0</Setting>
<Setting name="snapSoft">0</Setting>
<Setting name="dropAtScreenCenterMax">100</Setting>
<Setting name="boundingBoxCollision">0</Setting>
<Setting name="snapSoftSize">2</Setting>
</Group>
<Group name="Color">
<Setting name="objMouseOverColor">0 255 0 255</Setting>
<Setting name="selectionBoxColor">255 255 0 255</Setting>
<Setting name="objectTextColor">255 255 255 255</Setting>
<Setting name="objSelectColor">255 0 0 255</Setting>
<Setting name="popupBackgroundColor">100 100 100 255</Setting>
<Setting name="objMouseOverSelectColor">0 0 255 255</Setting>
<Setting name="dragRectColor">255 255 0 255</Setting>
<Setting name="displayType">6</Setting>
<Setting name="orthoFOV">50</Setting>
<Setting name="dropType">screenCenter</Setting>
<Group name="ObjectIcons">
<Setting name="fadeIconsEndAlpha">0</Setting>
<Setting name="fadeIcons">1</Setting>
<Setting name="fadeIconsStartDist">8</Setting>
<Setting name="fadeIconsEndDist">20</Setting>
<Setting name="fadeIconsStartAlpha">255</Setting>
</Group>
<Group name="Grid">
<Setting name="gridSnap">0</Setting>
<Setting name="gridMinorColor">51 51 51 100</Setting>
<Setting name="gridColor">102 102 102 100</Setting>
<Setting name="gridSize">1</Setting>
<Setting name="gridMinorColor">51 51 51 100</Setting>
<Setting name="gridOriginColor">255 255 255 100</Setting>
<Setting name="gridColor">102 102 102 100</Setting>
<Setting name="gridSnap">0</Setting>
</Group>
<Group name="Images">
<Setting name="selectHandle">tools/worldEditor/images/SelectHandle</Setting>
<Setting name="defaultHandle">tools/worldEditor/images/DefaultHandle</Setting>
<Setting name="lockedHandle">tools/worldEditor/images/LockedHandle</Setting>
</Group>
<Group name="Render">
<Setting name="renderPopupBackground">1</Setting>
<Setting name="renderObjHandle">1</Setting>
<Setting name="showMousePopupInfo">1</Setting>
<Setting name="renderObjText">1</Setting>
<Setting name="renderSelectionBox">1</Setting>
</Group>
<Group name="Tools">
<Setting name="snapSoft">0</Setting>
<Setting name="snapSoftSize">2</Setting>
<Setting name="dropAtScreenCenterScalar">1</Setting>
<Setting name="objectsUseBoxCenter">1</Setting>
<Setting name="snapGround">0</Setting>
<Setting name="boundingBoxCollision">0</Setting>
<Setting name="dropAtScreenCenterMax">100</Setting>
</Group>
<Group name="Color">
<Setting name="popupBackgroundColor">100 100 100 255</Setting>
<Setting name="objMouseOverSelectColor">0 0 255 255</Setting>
<Setting name="objMouseOverColor">Lime</Setting>
<Setting name="selectionBoxColor">255 255 0 255</Setting>
<Setting name="objectTextColor">255 255 255 255</Setting>
<Setting name="dragRectColor">255 255 0 255</Setting>
<Setting name="objSelectColor">255 0 0 255</Setting>
</Group>
<Group name="Theme">
<Setting name="windowTitleBGHLColor">48 48 48 255</Setting>
<Setting name="windowTitleBGNAColor">180 180 180 255</Setting>
<Setting name="windowTitleBGColor">50 50 50 255</Setting>
<Setting name="windowTitleFontColor">215 215 215 255</Setting>
<Setting name="windowTitleFontHLColor">255 255 255 255</Setting>
</Group>
<Group name="Docs">
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="forumURL">http://www.garagegames.com/products/torque-3d/forums</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
<Setting name="forumURL">http://www.garagegames.com/products/torque-3d/forums</Setting>
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
</Group>
<Group name="ObjectIcons">
<Setting name="fadeIconsEndAlpha">0</Setting>
<Setting name="fadeIconsStartAlpha">255</Setting>
<Setting name="fadeIconsEndDist">20</Setting>
<Setting name="fadeIconsStartDist">8</Setting>
<Setting name="fadeIcons">1</Setting>
</Group>
<Group name="GuiEditor">
<Setting name="previewResolution">1024 768</Setting>
<Setting name="lastPath">tools/gui</Setting>
<Group name="Rendering">
<Setting name="drawGuides">1</Setting>
<Setting name="drawBorderLines">1</Setting>
</Group>
<Group name="Render">
<Setting name="renderObjHandle">1</Setting>
<Setting name="renderObjText">1</Setting>
<Setting name="showMousePopupInfo">1</Setting>
<Setting name="renderSelectionBox">1</Setting>
<Setting name="renderPopupBackground">1</Setting>
<Group name="EngineDevelopment">
<Setting name="showEditorProfiles">0</Setting>
<Setting name="showEditorGuis">0</Setting>
<Setting name="toggleIntoEditor">0</Setting>
</Group>
<Group name="Theme">
<Setting name="windowTitleFontHLColor">255 255 255 255</Setting>
<Setting name="windowTitleBGHLColor">48 48 48 255</Setting>
<Setting name="windowTitleBGColor">50 50 50 255</Setting>
<Setting name="windowTitleBGNAColor">180 180 180 255</Setting>
<Setting name="windowTitleFontColor">215 215 215 255</Setting>
<Group name="Snapping">
<Setting name="snapToGuides">1</Setting>
<Setting name="snap2GridSize">8</Setting>
<Setting name="snapToEdges">1</Setting>
<Setting name="snapToCanvas">1</Setting>
<Setting name="snapToControls">1</Setting>
<Setting name="sensitivity">2</Setting>
<Setting name="snapToCenters">1</Setting>
<Setting name="snap2Grid">0</Setting>
</Group>
<Group name="Images">
<Setting name="defaultHandle">tools/worldEditor/images/DefaultHandle</Setting>
<Setting name="selectHandle">tools/worldEditor/images/SelectHandle</Setting>
<Setting name="lockedHandle">tools/worldEditor/images/LockedHandle</Setting>
<Group name="Help">
<Setting name="documentationLocal">../../../Documentation/Official Documentation.html</Setting>
<Setting name="documentationReference">../../../Documentation/Torque 3D - Script Manual.chm</Setting>
<Setting name="documentationURL">http://www.garagegames.com/products/torque-3d/documentation/user</Setting>
</Group>
<Group name="Library">
<Setting name="viewType">Categorized</Setting>
</Group>
<Group name="Selection">
<Setting name="fullBox">0</Setting>
</Group>
</Group>
<Group name="LevelInformation">
<Setting name="levelsDirectory">data/FPSGameplay/levels</Setting>
<Group name="levels">
<Group name="BlankRoom.mis">
<Setting name="cameraSpeed">25</Setting>
</Group>
<Group name="PbrMatTest.mis">
<Setting name="cameraSpeed">5</Setting>
</Group>
</Group>
</Group>
<Group name="NavEditor">
<Setting name="SpawnClass">AIPlayer</Setting>
</Group>
<Group name="LevelInformation">
<Setting name="levelsDirectory">data/FPSGameplay/levels</Setting>
<Group name="levels">
<Group name="PbrMatTest.mis">
<Setting name="cameraSpeed">5</Setting>
</Group>
<Group name="BlankRoom.mis">
<Setting name="cameraSpeed">25</Setting>
</Group>
</Group>
</Group>
<Group name="ConvexEditor">
<Setting name="materialName">Grid_512_Orange</Setting>
</Group>