pointLight.cpp
Engine/source/T3D/pointLight.cpp
Public Functions
ConsoleDocClass(PointLight , "@brief Lighting object that radiates light in all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">directions.\n\n</a>" "<a href="/coding/class/classpointlight/">PointLight</a> is one of the two types of lighting objects that can be added " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Torque 3D level, the other being SpotLight. Unlike directional or conical light, " "the <a href="/coding/class/classpointlight/">PointLight</a> emits lighting in all directions. The attenuation is controlled " "by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable:LightObject::radius.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Declaration of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> point light in script, or created by <a href="/coding/file/gizmo_8h/#gizmo_8h_1a10fcd3bee2ea25191e31795e36bdeba1a81f4537631c9ab219ec74de554483adc">World</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editor\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classpointlight/">PointLight</a>(CrystalLight)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " radius=\"10\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " isEnabled = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " color = \"1 0.905882 0 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " brightness = \"0.5\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " castShadows = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " priority = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animate = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animationType = \"SubtlePulseLightAnim\";\n" " animationPeriod = \"3\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animationPhase = \"3\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " flareScale = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " attenuationRatio = \"0 1 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowType = \"DualParaboloidSinglePass\";\n" " texSize = \"512\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " overDarkFactor = \"2000 1000 500 100\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowDistance = \"400\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowSoftness = \"0.15\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " numSplits = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " logWeight = \"0.91\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeStartDistance = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " lastSplitTerrainOnly = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " splitFadeDistances = \"10 20 30 40\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " representedInLightmap = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowDarkenColor = \"0 0 0 -1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " includeLightmappedGeometryInShadow = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " position = \"-61.3866 1.69186 5.1464\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " rotation = \"1 0 0 0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LightBase\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SpotLight\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Lighting\n</a>" )
Detailed Description
Public Functions
ConsoleDocClass(PointLight , "@brief Lighting object that radiates light in all <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">directions.\n\n</a>" "<a href="/coding/class/classpointlight/">PointLight</a> is one of the two types of lighting objects that can be added " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Torque 3D level, the other being SpotLight. Unlike directional or conical light, " "the <a href="/coding/class/classpointlight/">PointLight</a> emits lighting in all directions. The attenuation is controlled " "by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> single <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">variable:LightObject::radius.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Declaration of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> point light in script, or created by <a href="/coding/file/gizmo_8h/#gizmo_8h_1a10fcd3bee2ea25191e31795e36bdeba1a81f4537631c9ab219ec74de554483adc">World</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Editor\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classpointlight/">PointLight</a>(CrystalLight)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " radius=\"10\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " isEnabled = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " color = \"1 0.905882 0 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " brightness = \"0.5\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " castShadows = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " priority = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animate = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animationType = \"SubtlePulseLightAnim\";\n" " animationPeriod = \"3\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " animationPhase = \"3\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " flareScale = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " attenuationRatio = \"0 1 1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowType = \"DualParaboloidSinglePass\";\n" " texSize = \"512\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " overDarkFactor = \"2000 1000 500 100\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowDistance = \"400\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowSoftness = \"0.15\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " numSplits = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " logWeight = \"0.91\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeStartDistance = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " lastSplitTerrainOnly = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " splitFadeDistances = \"10 20 30 40\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " representedInLightmap = \"0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " shadowDarkenColor = \"0 0 0 -1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " includeLightmappedGeometryInShadow = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " position = \"-61.3866 1.69186 5.1464\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " rotation = \"1 0 0 0\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LightBase\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SpotLight\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Lighting\n</a>" )
IMPLEMENT_CO_NETOBJECT_V1(PointLight )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "T3D/pointLight.h" 26 27#include "console/consoleTypes.h" 28#include "core/stream/bitStream.h" 29#include "gfx/gfxDrawUtil.h" 30 31#include "lighting/shadowMap/lightShadowMap.h" 32 33IMPLEMENT_CO_NETOBJECT_V1( PointLight ); 34 35ConsoleDocClass( PointLight, 36 "@brief Lighting object that radiates light in all directions.\n\n" 37 38 "PointLight is one of the two types of lighting objects that can be added " 39 "to a Torque 3D level, the other being SpotLight. Unlike directional or conical light, " 40 "the PointLight emits lighting in all directions. The attenuation is controlled " 41 "by a single variable: LightObject::radius.\n\n" 42 43 "@tsexample\n" 44 "// Declaration of a point light in script, or created by World Editor\n" 45 "new PointLight(CrystalLight)\n" 46 "{\n" 47 " radius = \"10\";\n" 48 " isEnabled = \"1\";\n" 49 " color = \"1 0.905882 0 1\";\n" 50 " brightness = \"0.5\";\n" 51 " castShadows = \"1\";\n" 52 " priority = \"1\";\n" 53 " animate = \"1\";\n" 54 " animationType = \"SubtlePulseLightAnim\";\n" 55 " animationPeriod = \"3\";\n" 56 " animationPhase = \"3\";\n" 57 " flareScale = \"1\";\n" 58 " attenuationRatio = \"0 1 1\";\n" 59 " shadowType = \"DualParaboloidSinglePass\";\n" 60 " texSize = \"512\";\n" 61 " overDarkFactor = \"2000 1000 500 100\";\n" 62 " shadowDistance = \"400\";\n" 63 " shadowSoftness = \"0.15\";\n" 64 " numSplits = \"1\";\n" 65 " logWeight = \"0.91\";\n" 66 " fadeStartDistance = \"0\";\n" 67 " lastSplitTerrainOnly = \"0\";\n" 68 " splitFadeDistances = \"10 20 30 40\";\n" 69 " representedInLightmap = \"0\";\n" 70 " shadowDarkenColor = \"0 0 0 -1\";\n" 71 " includeLightmappedGeometryInShadow = \"1\";\n" 72 " position = \"-61.3866 1.69186 5.1464\";\n" 73 " rotation = \"1 0 0 0\";\n" 74 "};\n" 75 "@endtsexample\n\n" 76 77 "@see LightBase\n\n" 78 "@see SpotLight\n\n" 79 "@ingroup Lighting\n" 80); 81 82PointLight::PointLight() 83 : mRadius( 5.0f ) 84{ 85 // We set the type here to ensure the extended 86 // parameter validation works when setting fields. 87 mLight->setType( LightInfo::Point ); 88 89 //This lets us override the default shadowmap properties for point lights specifically 90 //We'll set the overdark factor to a lower value to mitigate visible aliasing from over-darkening the cubemap 91 //And then use cubemaps as the default shadowmap type 92 ShadowMapParams* p = mLight->getExtended<ShadowMapParams>(); 93 p->overDarkFactor = Point4F(10, 5, 4, 1); 94 p->shadowType = ShadowType::ShadowType_CubeMap; 95} 96 97PointLight::~PointLight() 98{ 99} 100 101void PointLight::initPersistFields() 102{ 103 addGroup( "Light" ); 104 105 addField( "radius", TypeF32, Offset( mRadius, PointLight ), "Controls the falloff of the light emission" ); 106 107 endGroup( "Light" ); 108 109 // We do the parent fields at the end so that 110 // they show up that way in the inspector. 111 Parent::initPersistFields(); 112 113 // Remove the scale field... it's already 114 // defined by the light radius. 115 removeField( "scale" ); 116 117 //These are particular fields for PSSM, so useless for point lights 118 removeField("numSplits"); 119 removeField("logWeight"); 120 removeField("lastSplitTerrainOnly"); 121} 122 123void PointLight::_conformLights() 124{ 125 mLight->setTransform( getRenderTransform() ); 126 127 mLight->setRange( mRadius ); 128 129 mLight->setColor( mColor ); 130 131 mLight->setBrightness( mBrightness ); 132 mLight->setCastShadows( mCastShadows ); 133 mLight->setStaticRefreshFreq(mStaticRefreshFreq); 134 mLight->setDynamicRefreshFreq(mDynamicRefreshFreq); 135 mLight->setPriority( mPriority ); 136 137 // Update the bounds and scale to fit our light. 138 mObjBox.minExtents.set( -1, -1, -1 ); 139 mObjBox.maxExtents.set( 1, 1, 1 ); 140 mObjScale.set( mRadius, mRadius, mRadius ); 141 142 // Skip our transform... it just dirties mask bits. 143 Parent::setTransform( mObjToWorld ); 144} 145 146U32 PointLight::packUpdate(NetConnection *conn, U32 mask, BitStream *stream ) 147{ 148 if ( stream->writeFlag( mask & UpdateMask ) ) 149 stream->write( mRadius ); 150 151 return Parent::packUpdate( conn, mask, stream ); 152} 153 154void PointLight::unpackUpdate( NetConnection *conn, BitStream *stream ) 155{ 156 if ( stream->readFlag() ) // UpdateMask 157 stream->read( &mRadius ); 158 159 Parent::unpackUpdate( conn, stream ); 160} 161 162void PointLight::setScale( const VectorF &scale ) 163{ 164 // Use the average of the three coords. 165 mRadius = ( scale.x + scale.y + scale.z ) / 3.0f; 166 167 // We changed our settings so notify the client. 168 setMaskBits( UpdateMask ); 169 170 // Let the parent do the final scale. 171 Parent::setScale( VectorF( mRadius, mRadius, mRadius ) ); 172} 173 174void PointLight::_renderViz( SceneRenderState *state ) 175{ 176 GFXDrawUtil *draw = GFX->getDrawUtil(); 177 178 GFXStateBlockDesc desc; 179 desc.setZReadWrite( true, false ); 180 desc.setCullMode( GFXCullNone ); 181 desc.setBlend( true ); 182 183 // Base the sphere color on the light color. 184 ColorI color = mColor.toColorI(); 185 color.alpha = 16; 186 187 draw->drawSphere( desc, mRadius, getPosition(), color ); 188} 189