diff --git a/Engine/source/lighting/advanced/advancedLightManager.cpp b/Engine/source/lighting/advanced/advancedLightManager.cpp index 7773b7b48..548a2d36c 100644 --- a/Engine/source/lighting/advanced/advancedLightManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightManager.cpp @@ -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 diff --git a/Engine/source/lighting/basic/basicLightManager.cpp b/Engine/source/lighting/basic/basicLightManager.cpp index 9b13f023c..c943deec3 100644 --- a/Engine/source/lighting/basic/basicLightManager.cpp +++ b/Engine/source/lighting/basic/basicLightManager.cpp @@ -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 ); } diff --git a/Engine/source/lighting/basic/basicLightManager.h b/Engine/source/lighting/basic/basicLightManager.h index 6641ac39d..2712d6677 100644 --- a/Engine/source/lighting/basic/basicLightManager.h +++ b/Engine/source/lighting/basic/basicLightManager.h @@ -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(); diff --git a/Engine/source/lighting/lightManager.cpp b/Engine/source/lighting/lightManager.cpp index 74b4e5cb9..d3cefba42 100644 --- a/Engine/source/lighting/lightManager.cpp +++ b/Engine/source/lighting/lightManager.cpp @@ -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 lightPositions( 3, sizeof( Point4F ) ); + //new setup + const U32 MAX_FORWARD_LIGHTS = 4; + + static AlignedArray lightPositions(MAX_FORWARD_LIGHTS, sizeof(Point4F)); + static AlignedArray lightSpotDirs(MAX_FORWARD_LIGHTS, sizeof(Point4F)); + static AlignedArray lightColors(MAX_FORWARD_LIGHTS, sizeof(Point4F)); + static AlignedArray lightConfigData(MAX_FORWARD_LIGHTS, sizeof(Point4F)); //type, brightness, range, invSqrRange : rgba + static AlignedArray 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 lightPositions( 3, sizeof( Point4F ) ); static AlignedArray lightSpotDirs( 3, sizeof( Point4F ) ); static AlignedArray 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 diff --git a/Engine/source/lighting/lightManager.h b/Engine/source/lighting/lightManager.h index fb54fe850..711a5ddd8 100644 --- a/Engine/source/lighting/lightManager.h +++ b/Engine/source/lighting/lightManager.h @@ -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 diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.cpp b/Engine/source/lighting/shadowMap/lightShadowMap.cpp index 7e18abbb8..c9f9b7c9c 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.cpp +++ b/Engine/source/lighting/shadowMap/lightShadowMap.cpp @@ -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"); diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.h b/Engine/source/lighting/shadowMap/lightShadowMap.h index 72137c651..b699ba9df 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.h +++ b/Engine/source/lighting/shadowMap/lightShadowMap.h @@ -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; diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index a383586ea..ee3fdc0b5 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -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); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index f88f5d8b1..a191aaee7 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -818,6 +818,74 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &compon return outTex; } +Var* ShaderFeatureHLSL::getSurface(Vector& componentList, MultiLine* meta) +{ + ShaderConnector* connectComp = dynamic_cast(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 &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 &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 &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 &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 &componentList, metalness->uniform = true; metalness->constSortPos = cspPotentialPrimitive; } - } + }*/ Var *albedo = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); @@ -2225,16 +2298,24 @@ void RTLightingFeatHLSL::processPix( Vector &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 &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 &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"); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h index 1aac22fc6..d720d6915 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h @@ -135,6 +135,8 @@ public: bool useInstancing, MultiLine *meta ); + Var* getSurface(Vector& componentList, MultiLine* meta); + // ShaderFeature Var* getVertTexCoord( const String &name ); LangElement* setupTexSpaceMat( Vector &componentList, Var **texSpaceMat ); diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index 9b08be0f9..df42fe371 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -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"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index a4d1df39b..1856181b7 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -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; diff --git a/Templates/BaseGame/game/core/gui/scripts/fonts/Arial 14 (ansi).uft b/Templates/BaseGame/game/core/gui/scripts/fonts/Arial 14 (ansi).uft index acbb4bed2..02bf5fbe6 100644 Binary files a/Templates/BaseGame/game/core/gui/scripts/fonts/Arial 14 (ansi).uft and b/Templates/BaseGame/game/core/gui/scripts/fonts/Arial 14 (ansi).uft differ diff --git a/Templates/BaseGame/game/core/gui/scripts/fonts/Arial Bold 18 (ansi).uft b/Templates/BaseGame/game/core/gui/scripts/fonts/Arial Bold 18 (ansi).uft index 72aba583d..3e3ce6aa5 100644 Binary files a/Templates/BaseGame/game/core/gui/scripts/fonts/Arial Bold 18 (ansi).uft and b/Templates/BaseGame/game/core/gui/scripts/fonts/Arial Bold 18 (ansi).uft differ diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 18949ad4f..14560fe60 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -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) { diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index 486902e60..e10446767 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -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 diff --git a/Templates/BaseGame/game/data/StaticShapeTest/Shapes/materials.cs b/Templates/BaseGame/game/data/StaticShapeTest/Shapes/materials.cs index 4754ef45f..988debb42 100644 --- a/Templates/BaseGame/game/data/StaticShapeTest/Shapes/materials.cs +++ b/Templates/BaseGame/game/data/StaticShapeTest/Shapes/materials.cs @@ -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"; diff --git a/Templates/BaseGame/game/tools/settings.xml b/Templates/BaseGame/game/tools/settings.xml index 18cd9e3ec..3c5aea189 100644 --- a/Templates/BaseGame/game/tools/settings.xml +++ b/Templates/BaseGame/game/tools/settings.xml @@ -1,59 +1,5 @@ - - 72 70 68 255 - 236 234 232 255 - 59 58 57 255 - 72 70 68 255 - 255 255 255 255 - 178 175 172 255 - 32 31 30 255 - 50 49 48 255 - 17 16 15 255 - 59 58 57 255 - 43 43 43 255 - 240 240 240 255 - 100 98 96 255 - 37 36 35 255 - 96 94 92 255 - 234 232 230 255 - 50 49 48 255 - 50 49 48 255 - - - 1024 768 - tools/gui - - 0 - 0 - 0 - - - ../../../Documentation/Official Documentation.html - http://www.garagegames.com/products/torque-3d/documentation/user - ../../../Documentation/Torque 3D - Script Manual.chm - - - 0 - - - 0 - 1 - 1 - 2 - 1 - 1 - 1 - 8 - - - 1 - 1 - - - Categorized - - 15 0.8 @@ -63,95 +9,149 @@ 0.8 1 + 0 + 255 255 255 20 10 10 10 500 - 255 255 255 20 - 0 - 0 0 + 0 + + 72 70 68 255 + 178 175 172 255 + 72 70 68 255 + 240 240 240 255 + 50 49 48 255 + 32 31 30 255 + 96 94 92 255 + 17 16 15 255 + 59 58 57 255 + 43 43 43 255 + 37 36 35 255 + 50 49 48 255 + 236 234 232 255 + 50 49 48 255 + 100 98 96 255 + 59 58 57 255 + 234 232 230 255 + 255 255 255 255 + - 50 - 6 - 0 - screenCenter 40 WorldEditorInspectorPlugin + 0 AssetWork_Debug.exe 1 - - 1 - 1 - 0 - 0 - 100 - 0 - 2 - - - 0 255 0 255 - 255 255 0 255 - 255 255 255 255 - 255 0 0 255 - 100 100 100 255 - 0 0 255 255 - 255 255 0 255 + 6 + 50 + screenCenter + + 0 + 1 + 8 + 20 + 255 - 0 - 51 51 51 100 - 102 102 102 100 1 + 51 51 51 100 255 255 255 100 + 102 102 102 100 + 0 + + + tools/worldEditor/images/SelectHandle + tools/worldEditor/images/DefaultHandle + tools/worldEditor/images/LockedHandle + + + 1 + 1 + 1 + 1 + 1 + + + 0 + 2 + 1 + 1 + 0 + 0 + 100 + + + 100 100 100 255 + 0 0 255 255 + Lime + 255 255 0 255 + 255 255 255 255 + 255 255 0 255 + 255 0 0 255 + + + 48 48 48 255 + 180 180 180 255 + 50 50 50 255 + 215 215 215 255 + 255 255 255 255 http://www.garagegames.com/products/torque-3d/documentation/user - ../../../Documentation/Official Documentation.html - http://www.garagegames.com/products/torque-3d/forums ../../../Documentation/Torque 3D - Script Manual.chm + http://www.garagegames.com/products/torque-3d/forums + ../../../Documentation/Official Documentation.html - - 0 - 255 - 20 - 8 - 1 + + + 1024 768 + tools/gui + + 1 + 1 - - 1 - 1 - 1 - 1 - 1 + + 0 + 0 + 0 - - 255 255 255 255 - 48 48 48 255 - 50 50 50 255 - 180 180 180 255 - 215 215 215 255 + + 1 + 8 + 1 + 1 + 1 + 2 + 1 + 0 - - tools/worldEditor/images/DefaultHandle - tools/worldEditor/images/SelectHandle - tools/worldEditor/images/LockedHandle + + ../../../Documentation/Official Documentation.html + ../../../Documentation/Torque 3D - Script Manual.chm + http://www.garagegames.com/products/torque-3d/documentation/user + + + Categorized + + + 0 + + + + data/FPSGameplay/levels + + + 25 + + + 5 + AIPlayer - - data/FPSGameplay/levels - - - 5 - - - 25 - - - Grid_512_Orange