env_projectedtexture
From Valve Developer Community
env_projectedtexture is a point entity is available in all Orange Box games. It creates a dynamic shadow-mapping light that affects all objects in the world. It is used to create the Episode Two flashlight.
SpotlightTexture input instead.Contents |
Bug fixes
Enabling multiple shadow maps
Valve's games only allow one projected texture to cast shadows at a time - including the player's flashlight! To surmount this, shadow casting can be disabled on each entity with the enableshadows KV, or for a proper solution a programmer can perform this C++ fix:
In CClientShadowMgr::Init() (Clientshadowmgr.cpp around line 1293), replace:
bool bTools = CommandLine()->CheckParm( "-tools" ) != NULL; m_nMaxDepthTextureShadows = bTools ? 4 : 1; // Just one shadow depth texture in games, more in tools
With:
m_nMaxDepthTextureShadows = YOUR_CHOSEN_MAX; //with your number
Fixing targeting
Because the targeting code isn't finished in the SDK, A projected texture will flicker when bound to a target. To fix this, open c_env_projectedtexture.cpp and around line 174 there is an else block containing an assert and some commented code. Replace the whole block with this:
else { Vector vecToTarget = m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin(); QAngle vecAngles; VectorAngles( vecToTarget, vecAngles ); AngleVectors( vecAngles, &vForward, &vRight, &vUp ); }
The server needs code to update the entity with angles on a target as well. Open env_projectedtexture.cpp and around line 245 edit the InitialThink() function to recalculate angles towards the target:
void CEnvProjectedTexture::InitialThink( void ) { if ( m_hTargetEntity == NULL && m_target != NULL_STRING ) m_hTargetEntity = gEntList.FindEntityByName( NULL, m_target ); if ( m_hTargetEntity == NULL ) return; Vector vecToTarget = (m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin()); QAngle vecAngles; VectorAngles( vecToTarget, vecAngles ); SetAbsAngles( vecAngles ); SetNextThink( gpGlobals->curtime + 0.1 ); }
Fixing cuts in projected texture
When using multiple env_projectedtexture, projected textures might be cut at certain viewing angles. To fix this, force r_flashlightscissor 0 for your mod or map.
You can do this by adding the following code block into the constructor of c_basehlplayer.cpp
ConVar *r_flashlightscissor = cvar->FindVar( "r_flashlightscissor" ); if ( r_flashlightscissor->GetBool() ) { r_flashlightscissor->SetValue( 0 ); }
Enabling visibility tests
Projected textures are not tested for visibility. Being constantly enabled creates issues like shadows bleeding through walls. To fix them, head into c_env_projectedtexture.cpp, and make these changes:
Add a new function (remember to declare it in the header):
bool C_EnvProjectedTexture::ShouldDraw() { //No need to check the flashlight for visibility. if( m_bCameraSpace ) return true; //Trace forward to the nearest brush face to get a good leaf test vector. Vector vForward; GetVectors( &vForward, NULL, NULL ); Vector vTraceStart = GetAbsOrigin(); Vector vTraceEnd = GetAbsOrigin() + vForward * m_flFarZ; trace_t tr; CTraceFilterWorldOnly filter; UTIL_TraceLine( vTraceStart, vTraceEnd, CONTENTS_SOLID && CONTENTS_OPAQUE, &filter, &tr ); //Check to see if our end vector is in a visible leaf. int LeafNum = enginetrace->GetLeafContainingPoint( tr.endpos ); return render->AreAnyLeavesVisible( &LeafNum,1 ); }
In C_EnvProjectedTexture::UpdateLight, change the first line to read:
if ( m_bState == false || !ShouldDraw() )
Enabling shadow receiving on the view model
Shadow receiving is disabled on various types of renderables. If you want to have shadows cast upon the view model then head into baseviewmodel_shared.h, find the ShouldReceiveProjectedTextures function and make it return true.
For example:
virtual bool ShouldReceiveProjectedTextures( int flags ) { return true; }
This change also works for other renderables like detail models. Just search the solution for ShouldReceiveProjectedTextures.
You could also simply comment out the entire ShouldReceiveProjectedTextures function, instead of changing it to return true.
Keyvalues
- target
<string> - The entity will rotate to point at its target, no matter where it is in the world. See also
lightonlytarget.
Bug:Does not work with stock SDK code. See #Fixing targeting. - FOV
<float> - The angle at which the texture is projected. The projection is square, but the texture can make it appear of any shape.
- Remember the default Player FOV is 75°.
- NearZ
<float> - Near Z for projected texture. Default value is 4.0.
- Objects closer than this will not receive the projection.
- FarZ
<float> - Far Z for projected texture. Default value is 750.0.
- Objects beyond this distance will not receive the projection. Think of it as the range limit.
- Enable Shadows
<bool> - Should I cast shadows?
- Shadow Quality
<bool> - Quality of shadows (
To do: what's the difference?)
- Light Only Target
<bool> - Should I light only the entity that is my
target? The world will still be lit. - Light World
<bool> - Should I light the world?
- Camera Space
<bool> - Display relative to player's view. Breaks things horribly unless the entity moves with the player.
- Light Color
<color255> - Tint of projected texture.
Parentname:
- Parent
<targetname> - Specifies the targetname of this entity's movement parent. Entities with parents move with their parent.
-
Bug:Does not work with stock SDK code. See #Fixing targeting.
Angles:
- Pitch Yaw Roll (Y Z X)
<angle> - This entity's angular orientation in the world.
Targetname:
- Name <string>
- The targetname other entities refer to this entity by.
Flags
- Enabled
Inputs
-
TurnOn -
TurnOff - Enable or disable the light.
-
FOV <float> - See lightfov keyvalue above.
Parentname:
-
SetParent <targetname> - Move with this entity. See Entity Hierarchy (parenting).
-
SetParentAttachment <string> - Attach to a named attachment on the current parent. The entity will teleport so that the position of its root bone matches that of the attachment.
-
SetParentAttachmentMaintainOffset <string> - As above, but without teleporting. The entity retains its position relative to the attachment at the time of the input being received.
-
ClearParent - Removes this entity from its current movement hierarchy.
Targetname:
-
Kill - Removes this entity from the world.
-
KillHierarchy - Removes this entity and all its children from the world.
-
AddOutput <string> - Evaluates a keyvalue/output on this entity. It can be potentially very dangerous, use with care.
- Format:
<key> <value> - Format:
<output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire, -1 means infinite> -
FireUser1toFireUser4 - Fire the
OnUseroutputs; see User Inputs and Outputs.
Inputs not in FGD
These inputs are accepted by the entity but not known to Hammer:
-
target <string> - Specify a new target entity to point at.
-
cameraspace <bool> - See above keyvalues.
-
LightOnlyTarget <bool> - See above keyvalues.
Bug:Non-functional. -
LightWorld <bool> - See above keyvalues.
Bug:Cannot be re-enabled. -
EnableShadows <bool> - See above keyvalues.
-
Ambient <float> - Allows for an ambiance light, much like the shadow color for it.
-
SpotlightTexture <VTF/string> - A VTF file (not VMT), relative to
/materials.
Outputs
Targetname:
-
OnUser1toOnUser4 - Fired in response to the
FireUserinputs; see User Inputs and Outputs. -
OnKilled(New with Left 4 Dead) - Fired when the entity is killed and removed from the game.
