Env projectedtexture: Difference between revisions
m (Robot: fixing template case.) |
TomEdwards (talk | contribs) (cleanup) |
||
Line 1: | Line 1: | ||
[[Image:Shadowmap.jpg|thumb|Casting shadows.]] | |||
[[Image:Projected texture.jpg|thumb|Projecting a colourful [[texture]].]] | |||
{{base_point_ep2}} It creates a dynamic shadow-casting light (using shadowmapping) that affects all objects in the world. It is used to create the [[Episode Two]] flashlight. | |||
[[ | |||
{{warning|Using this entity incorrectly can send your [[fillrate]] (i.e. swap buffers) through the roof!}} | |||
{{note|Shadows are only drawn when the user is running with "High" shadow detail.}} | |||
{{bug|Does not accept a configurable texture value from Hammer - will always default to the flashlight. You must use the <code>SpotlightTexture</code> [[input]] instead.}} | {{bug|Does not accept a configurable texture value from Hammer - will always default to the flashlight. You must use the <code>SpotlightTexture</code> [[input]] instead.}} | ||
==Bug fixes== | ==Bug fixes== | ||
=== Enabling multiple shadow maps === | === 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 <code>enableshadows</code> KV, or for a proper solution a programmer can perform this C++ fix: | 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 <code>enableshadows</code> KV, or for a proper solution a programmer can perform this C++ fix: | ||
In | In ''CClientShadowMgr::Init()'' (Clientshadowmgr.cpp around line 1293), replace: | ||
<source lang=cpp>bool bTools = CommandLine()->CheckParm( "-tools" ) != NULL; | |||
m_nMaxDepthTextureShadows = bTools ? 4 : 1; // Just one shadow depth texture in games, more in tools</source> | |||
With: | |||
<source lang=cpp>m_nMaxDepthTextureShadows = YOUR_CHOSEN_MAX; //with your number</source> | |||
=== Fixing targeting === | |||
Because the targeting code isn't finished in the SDK, env_projectedtexture will flicker when bound to a target. To fix this, open ''c_env_projectedtexture.cpp'' and around line 174 there is a lot of code already commented out. Comment out the rest (vForward stuff) and instead add clientside computation of the correct angles like this (it will give smooth movement): | |||
<source lang=cpp>// JasonM ... | |||
// VectorNormalize( vRight ); | |||
// VectorNormalize( vUp ); | |||
Vector vecToTarget = (m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin()); | |||
QAngle vecAngles; | |||
VectorAngles( vecToTarget, vecAngles ); | |||
AngleVectors( vecAngles, &vForward, &vRight, &vUp ); | |||
}</source> | |||
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 <code>InitialThink()</code> function to recalculate angles towards the target: | |||
<source lang=cpp>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 );</source> | |||
=== Fixing cuts in projected texture === | === Fixing cuts in projected texture === | ||
[[Image:Cut.jpg|thumb|Projected texture being cut.]] | [[Image:Cut.jpg|thumb|Projected texture being cut.]] | ||
When using multiple env_projectedtexture, projected textures might be cut at certain viewing angles. | 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. | To fix this, force ''r_flashlightscissor 0'' for your mod or map. | ||
==Keyvalues== | ==Keyvalues== | ||
[[ | ; target <[[string]]> | ||
: The entity will rotate to point at its target, no matter where it is in the world. See also <code>lightonlytarget</code>. | : The entity will rotate to point at its target, no matter where it is in the world. See also <code>lightonlytarget</code>. | ||
: {{bug|Can get glitchy. Refer to bug fix section.}} | : {{bug|Can get glitchy. Refer to bug fix section.}} | ||
; lightfov <[[float]]> | |||
: The angle at which the texture is projected. The projection is square, but the texture can make it appear of any shape. | : 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°. | : Remember the default Player FOV is 75°. | ||
; nearz <float> | |||
: Near Z for projected texture. Default value is 4.0. | : Near Z for projected texture. Default value is 4.0. | ||
: Objects closer than this will not receive the projection. | : Objects closer than this will not receive the projection. | ||
; farz <float> | |||
: Far Z for projected texture. Default value is 750.0. | : 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. | : Objects beyond this distance will not receive the projection. Think of it as the range limit. | ||
; enableshadows <[[bool]]> | |||
: Should I cast (dynamic) shadows? | : Should I cast (dynamic) shadows? | ||
: 0 = No, 1 = Yes. | : 0 = No, 1 = Yes. | ||
; shadowquality <bool> | |||
: Quality of (dynamic) shadows? | : Quality of (dynamic) shadows? | ||
: 0 = Low, 1 = High. | : 0 = Low, 1 = High. | ||
; lightonlytarget <bool> | |||
: Should I light only the entity that is my <code>target</code>? | : Should I light only the entity that is my <code>target</code>? | ||
: 0 = No, 1 = Yes. | : 0 = No, 1 = Yes. | ||
: {{bug|Non-functional.}} | : {{bug|Non-functional.}} | ||
; lightworld <bool> | |||
: Should I light world [[brush]]es? | : Should I light world [[brush]]es? | ||
; cameraspace <bool> | |||
: Display relative to player's view. Breaks things horribly unless the entity moves with the player. | : Display relative to player's view. Breaks things horribly unless the entity moves with the player. | ||
; lightcolor {{color}} | |||
: Projected color | : Projected color | ||
<!-- : {{bug|Non-functional.}} // appears to be fixed in ep2 test --> | <!-- : {{bug|Non-functional.}} // appears to be fixed in ep2 test --> | ||
Line 99: | Line 97: | ||
==Flags== | ==Flags== | ||
* 1 : Enabled | * '''1''': Enabled | ||
==Inputs== | ==Inputs== | ||
; TurnOn | |||
; TurnOff | |||
; FOV <[[float]]> | |||
: See lightfov keyvalue above. | : See lightfov keyvalue above. | ||
* {{I Parentname}} | * {{I Parentname}} | ||
* {{I Targetname}} | * {{I Targetname}} | ||
Line 116: | Line 111: | ||
These inputs are not known to Hammer, but are still accepted by the entity: | These inputs are not known to Hammer, but are still accepted by the entity: | ||
; target <[[string]]> | |||
: Specify a new | : Specify a new target entity to point at. | ||
; cameraspace <[[bool]]> | |||
: See above keyvalues. | : See above keyvalues. | ||
; LightOnlyTarget <bool> | |||
: See above keyvalues. | : See above keyvalues. | ||
: {{bug|Non-functional.}} | : {{bug|Non-functional.}} | ||
; LightWorld <bool> | |||
: See above keyvalues. | : See above keyvalues. | ||
: {{bug|Cannot be re-enabled.}} | : {{bug|Cannot be re-enabled.}} | ||
; EnableShadows <bool> | |||
: See above keyvalues. | : See above keyvalues. | ||
;Ambient <[[float]]> | |||
: Allows for an ambiance light, much like the shadow color for it. | : Allows for an ambiance light, much like the shadow color for it. | ||
;SpotlightTexture <VTF/string> | |||
:A [[Valve Texture Format|VTF]] file (not VMT), relative to <code>/materials</code>. | :A [[Valve Texture Format|VTF]] file (not VMT), relative to <code>/materials</code>. | ||
==Outputs== | ==Outputs== | ||
* {{O Targetname}} | * {{O Targetname}} |
Revision as of 03:51, 18 June 2009

Template:Base point ep2 It creates a dynamic shadow-casting light (using shadowmapping) that affects all objects in the world. It is used to create the Episode Two flashlight.


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, env_projectedtexture will flicker when bound to a target. To fix this, open c_env_projectedtexture.cpp and around line 174 there is a lot of code already commented out. Comment out the rest (vForward stuff) and instead add clientside computation of the correct angles like this (it will give smooth movement):
// JasonM ...
// VectorNormalize( vRight );
// VectorNormalize( vUp );
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:
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.
Keyvalues
- target <string>
- The entity will rotate to point at its target, no matter where it is in the world. See also
lightonlytarget
. Bug:Can get glitchy. Refer to bug fix section. [todo tested in ?]
- lightfov <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.
- enableshadows <bool>
- Should I cast (dynamic) shadows?
- 0 = No, 1 = Yes.
- shadowquality <bool>
- Quality of (dynamic) shadows?
- 0 = Low, 1 = High.
- lightonlytarget <bool>
- Should I light only the entity that is my
target
? - 0 = No, 1 = Yes.
Bug:Non-functional. [todo tested in ?]
- lightworld <bool>
- Should I light world brushes?
- cameraspace <bool>
- Display relative to player's view. Breaks things horribly unless the entity moves with the player.
- lightcolor ⇆#000000rgb(0,0,0)⇆
- Projected color
- Parent (parentname) <targetname>
- Specifies a movement parent. An entity will maintain its initial offset from its parent. An attachment point can be added to the end of the name, separated by a comma.
Bug:Parenting does not work. Refer to bug fix section [todo tested in ?]
- Pitch Yaw Roll (Y Z X) (angles) <QAngle>
- This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.
- Name (targetname) <string>[ Edit ]
- The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g.
parentname
ortarget
).
Also displayed in Hammer's 2D views and Entity Report.See also: Generic Keyvalues, Inputs and Outputs available to all entities
Flags
- 1: Enabled
Inputs
- TurnOn
- TurnOff
- FOV <float>
- See lightfov keyvalue above.
- SetParent <string >
- Move with this entity. See Entity Hierarchy (parenting).
- SetParentAttachment <string >
- Change this entity to attach to a specific attachment point on its parent. The entity will teleport so that the position of its root bone matches that of the attachment. Entities must be parented before being sent this input.
- 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 the the movement hierarchy, leaving it free to move independently.
Inputs not in FGD
These inputs are not known to Hammer, but are still accepted by the entity:
- target <string>
- Specify a new target entity to point at.
- cameraspace <bool>
- See above keyvalues.
- LightOnlyTarget <bool>
- See above keyvalues.
Bug:Non-functional. [todo tested in ?]
- LightWorld <bool>
- See above keyvalues.
Bug:Cannot be re-enabled. [todo tested in ?]
- 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
.