diff --git a/Engine/source/T3D/spotLight.cpp b/Engine/source/T3D/spotLight.cpp index 3f43305f7..6653a5365 100644 --- a/Engine/source/T3D/spotLight.cpp +++ b/Engine/source/T3D/spotLight.cpp @@ -132,7 +132,7 @@ void SpotLight::_conformLights() mLight->setDynamicRefreshFreq(mDynamicRefreshFreq); mLight->setPriority( mPriority ); - mOuterConeAngle = getMax( 0.01f, mOuterConeAngle ); + mOuterConeAngle = getMin(getMax( 0.01f, mOuterConeAngle ),179.0f); mInnerConeAngle = getMin( mInnerConeAngle, mOuterConeAngle ); mLight->setInnerConeAngle( mInnerConeAngle ); diff --git a/Engine/source/lighting/advanced/advancedLightBinManager.cpp b/Engine/source/lighting/advanced/advancedLightBinManager.cpp index 431ec28ad..24637de6c 100644 --- a/Engine/source/lighting/advanced/advancedLightBinManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightBinManager.cpp @@ -399,9 +399,9 @@ void AdvancedLightBinManager::render( SceneRenderState *state ) sunLight->getCastShadows() && !disableShadows && sunLight->getExtended() ) - vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_PSSM ); + vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_PSSM,false,false ); else - vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_None ); + vectorMatInfo = _getLightMaterial( LightInfo::Vector, ShadowType_None, false, false); // Initialize and set the per-frame parameters after getting // the vector light material as we use lazy creation. diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 504fecaa6..29996cf66 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -71,7 +71,7 @@ public: //----------------------------------------------------------------------- enum Constants { - MAX_TEX_PER_PASS = 8, ///< Number of textures per pass + MAX_TEX_PER_PASS = 16, ///< Number of textures per pass MAX_STAGES = 4, NUM_EFFECT_COLOR_STAGES = 2, ///< Number of effect color definitions for transitioning effects. }; diff --git a/Engine/source/materials/processedCustomMaterial.cpp b/Engine/source/materials/processedCustomMaterial.cpp index 5c16a012e..abca21dd9 100644 --- a/Engine/source/materials/processedCustomMaterial.cpp +++ b/Engine/source/materials/processedCustomMaterial.cpp @@ -360,6 +360,7 @@ void ProcessedCustomMaterial::setTextureStages( SceneRenderState *state, const S break; case Material::Mask: + case Material::PhotometricMask: case Material::Standard: case Material::Bump: case Material::Detail: diff --git a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript index 104056efe..1fcee6079 100644 --- a/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript +++ b/Templates/BaseGame/game/core/lighting/scripts/advancedLighting_Shaders.tscript @@ -118,6 +118,7 @@ singleton GFXStateBlockData( AL_ConvexLightState ) samplerStates[3] = SamplerClampPoint; // colorBuffer samplerStates[4] = SamplerClampPoint; // matInfoBuffer samplerStates[5] = SamplerClampLinear; // Cookie Map + samplerStates[6] = SamplerClampLinear; // iesProfile cullDefined = true; cullMode = GFXCullCW; @@ -142,6 +143,7 @@ singleton shaderData( AL_PointLightShader ) samplerNames[3] = "$colorBuffer"; samplerNames[4] = "$matInfoBuffer"; samplerNames[5] = "$cookieMap"; + samplerNames[6] = "$iesProfile"; pixVersion = 3.0; }; @@ -156,7 +158,7 @@ singleton CustomMaterial( AL_PointLightMaterial ) sampler["cookieMap"] = "$dynamiclightmask"; sampler["colorBuffer"] = "#color"; sampler["matInfoBuffer"] = "#matinfo"; - + sampler["iesProfile"] = "$photometricmask"; target = "AL_FormatToken"; pixVersion = 3.0; @@ -177,6 +179,7 @@ singleton shaderData( AL_SpotLightShader ) samplerNames[3] = "$colorBuffer"; samplerNames[4] = "$matInfoBuffer"; samplerNames[5] = "$cookieMap"; + samplerNames[6] = "$iesProfile"; pixVersion = 3.0; }; @@ -188,10 +191,10 @@ singleton CustomMaterial( AL_SpotLightMaterial ) sampler["deferredBuffer"] = "#deferred"; sampler["shadowMap"] = "$dynamiclight"; + sampler["iesProfile"] = "$photometricmask"; sampler["cookieMap"] = "$dynamiclightmask"; sampler["colorBuffer"] = "#color"; sampler["matInfoBuffer"] = "#matinfo"; - target = "AL_FormatToken"; pixVersion = 3.0; diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl index 7e6984e21..b0b02d226 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/pointLightP.glsl @@ -108,6 +108,7 @@ uniform sampler2D deferredBuffer; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; + #ifdef SHADOW_CUBE /// The texture for cookie rendering. uniform samplerCube cookieMap; @@ -115,11 +116,14 @@ uniform samplerCube cookieMap; uniform sampler2D cookieMap; #endif -uniform sampler2D iesProfile; +#ifdef UES_PHOTOMETRIC_MASK +uniform sampler1D iesProfile; +#endif uniform vec4 rtParams0; uniform vec3 lightPosition; +uniform vec3 lightDirection; uniform vec4 lightColor; uniform float lightBrightness; uniform float lightRange; @@ -230,17 +234,18 @@ void main() OUT_col = vec4(final, 0); return #endif - - //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); + #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + float iesMask = texture(iesProfile,angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get punctual light contribution + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl index f5983eb0d..3585bfde2 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/spotLightP.glsl @@ -19,7 +19,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- - #include "../../../gl/hlslCompat.glsl" #include "farFrustumQuad.glsl" #include "../../shadowMap/shadowMapIO_GLSL.h" @@ -38,8 +37,15 @@ uniform sampler2D shadowMap; #include "softShadow.glsl" uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; + +#ifdef USE_COOKIE_TEX uniform sampler2D cookieMap; -uniform sampler2D iesProfile; +#endif + +#ifdef UES_PHOTOMETRIC_MASK +uniform sampler1D iesProfile; +#endif + uniform vec4 rtParams0; uniform float lightBrightness; @@ -109,7 +115,10 @@ void main() vec3 lightCol = lightColor.rgb; #ifdef USE_COOKIE_TEX // Lookup the cookie sample. - vec4 cookie = texture(cookieMap, shadowCoord); + vec4 pxlPosLightProj = tMul( worldToLightProj, vec4( surface.P, 1 ) ); + vec2 cookieCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 ); + cookieCoord.y = 1.0f - cookieCoord.y; + vec4 cookie = texture(cookieMap, cookieCoord); // Multiply the light with the cookie tex. lightCol *= cookie.rgb; // Use a maximum channel luminance to attenuate @@ -154,16 +163,17 @@ void main() return; #endif - //get spot light contribution - lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = texture(iesProfile, vec2(angle, 0.0)).r; + float iesMask = texture(iesProfile, angle/(lightSpotParams.x-lightSpotParams.y)).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get spot light contribution + lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); } OUT_col = vec4(lighting, 0); diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl index de3d3433f..ab5145849 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/pointLightP.hlsl @@ -107,13 +107,17 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1); #include "softShadow.hlsl" TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4); + /// The texture for cookie rendering. #ifdef SHADOW_CUBE TORQUE_UNIFORM_SAMPLERCUBE(cookieMap, 5); #else TORQUE_UNIFORM_SAMPLER2D(cookieMap, 5); #endif -TORQUE_UNIFORM_SAMPLER2D(iesProfile, 6); + +#ifdef UES_PHOTOMETRIC_MASK +TORQUE_UNIFORM_SAMPLER1D(iesProfile, 6); +#endif uniform float4 rtParams0; uniform float4 lightColor; @@ -223,17 +227,18 @@ float4 main( ConvexConnectP IN ) : SV_TARGET return final; #endif - //get punctual light contribution - lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); - #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r; + float iesMask = TORQUE_TEX1D(iesProfile, angle).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get punctual light contribution + lighting = getPunctualLight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, shadow); + } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl index efd07fa30..c2d8d1e9e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/spotLightP.hlsl @@ -43,8 +43,14 @@ TORQUE_UNIFORM_SAMPLER2D(shadowMap, 1); TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 3); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 4); /// The texture for cookie rendering. + +#ifdef USE_COOKIE_TEX TORQUE_UNIFORM_SAMPLER2D(cookieMap, 5); -TORQUE_UNIFORM_SAMPLER2D(iesProfile, 6); +#endif + +#ifdef UES_PHOTOMETRIC_MASK +TORQUE_UNIFORM_SAMPLER1D(iesProfile, 6); +#endif uniform float4 rtParams0; @@ -153,16 +159,17 @@ float4 main( ConvexConnectP IN ) : SV_TARGET return final; #endif - //get spot light contribution - lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); #ifdef UES_PHOTOMETRIC_MASK // Lookup the cookie sample.d float cosTheta = dot(-surfaceToLight.L, lightDirection); float angle = acos(cosTheta) * ( M_1OVER_PI_F); - float iesMask = TORQUE_TEX2D(iesProfile, float2(angle, 0.0)).r; + float iesMask = TORQUE_TEX1D(iesProfile, angle/(lightSpotParams.x-lightSpotParams.y)).r; // Multiply the light with the iesMask tex. - lighting *= iesMask; + shadow *= iesMask; #endif + + //get spot light contribution + lighting = getSpotlight(surface, surfaceToLight, lightCol, lightBrightness, lightInvSqrRange, lightDirection, lightSpotParams, shadow); } return float4(lighting, 0);