Env projectedtexture: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Re-added parenting fix, it works. Also updated the shadow scissor fix.)
(moved bug fix section to own page)
Line 6: Line 6:


{{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|[[Model]]s will not receive their own shadows correctly unless using [[$bumpmap]]. Even a flat bump map will fix the problem.}}


==Bug fixes==
==Bug fixes==


=== Enabling multiple shadow maps ===
See [[env_projectedtexture/fixes]].
 
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 ''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>
 
{{warning|A new [[render texture]] will be created for each shadow map you enable support for, regardless of whether it's used. Having too many RTs hurts performance, so keep your limit within reason (ideally something below 10).}}
 
=== 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 <code>else</code> block containing an assert and some commented code. Replace the whole block with this:
 
<source lang=cpp>else
{
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>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 );
}</source>
 
=== Fixing cuts in projected texture ===
 
{{warning|Having this set will reduce your performance, but only by a small fraction, though noticeable.}}
 
[[Image:Cut.jpg|thumb|Projected texture being cut.]]
 
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
 
<source lang=cpp>ConVarRef scissor( "r_flashlightscissor" );
scissor.SetValue( "0" );</source>
 
=== Fixing Parenting ===
 
By default, this entity's position only gets updated when it gets turned on. Thus, parenting does not work. To fix this, open ''c_env_projectedtexture.cpp'' and in line 225, comment out 3 lines like this:
 
<source lang=cpp> // if ( bForceUpdate == false )
// {
g_pClientShadowMgr->UpdateProjectedTexture( m_LightHandle, true );
// }</source>
 
In line 233 in the Simulate function, change the argument ''false'' to ''true'' like this:
 
<source lang=cpp>    UpdateLight( true );</source>
 
=== 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):
 
<source lang=cpp>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 );
}</source>
 
In <code>C_EnvProjectedTexture::UpdateLight</code>, change the first line to read:
 
<source lang=cpp>if ( m_bState == false || !ShouldDraw() )</source>
 
{{bug|This can cause the light to not draw under certain visleaf conditions. A better solution might be to test the entity's PVS?}}
 
=== 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 <code>ShouldReceiveProjectedTextures</code> function and make it return <code>true</code>.
 
For example:
 
<source lang=cpp>virtual bool ShouldReceiveProjectedTextures( int flags )
{
return true;
}</source>
 
This change also works for other renderables like detail models. Just search the solution for <code>ShouldReceiveProjectedTextures</code>.
 
You could also simply comment out the entire <code>ShouldReceiveProjectedTextures</code> function, instead of changing it to return true.


==Keyvalues==
==Keyvalues==
Line 164: Line 47:


==Inputs==
==Inputs==
; <code>TurnOn</code>
; <code>TurnOff</code>
: Enable or disable the light.
; <code>FOV <[[float]]></code>
: See lightfov keyvalue above.
{{I Parentname}}
{{I Targetname}}


=== Inputs not in FGD ===
''These inputs are accepted by the entity but not known to Hammer:''
 
These inputs are accepted by the entity but not known to Hammer:


; <code>target <[[string]]></code>
; <code>target <[[string]]></code>
Line 190: Line 64:
; <code>SpotlightTexture <VTF/string></code>
; <code>SpotlightTexture <VTF/string></code>
: 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>.
''These inputs are known to Hammer:''
; <code>TurnOn</code>
; <code>TurnOff</code>
: Enable or disable the light.
; <code>FOV <[[float]]></code>
: See lightfov keyvalue above.
{{I Parentname}}
{{I Targetname}}


==Outputs==
==Outputs==

Revision as of 11:25, 27 January 2010

Projecting a colourful texture.

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

Note.pngNote:Shadows are only drawn when the user is running with "High" shadow detail.
Icon-Bug.pngBug:Does not accept a configurable texture value from Hammer - will always default to the flashlight. You must use the SpotlightTexture input instead.  [todo tested in ?]
Icon-Bug.pngBug:Models will not receive their own shadows correctly unless using $bumpmap. Even a flat bump map will fix the problem.  [todo tested in ?]

Bug fixes

See env_projectedtexture/fixes.

Keyvalues

target <string>
The entity will rotate to point at its target, no matter where it is in the world. See also lightonlytarget.
Icon-Bug.pngBug:Does not work with stock SDK code. See #Fixing targeting.  [todo tested in ?]
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 (
Todo: 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 #000000
Tint of projected texture.
Parentname:
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.
Icon-Bug.pngBug:Does not work with stock SDK code. See #Fixing targeting.  [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 or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Flags

  • Enabled

Inputs

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.
Icon-Bug.pngBug:Non-functional.  [todo tested in ?]
LightWorld <bool>
See above keyvalues.
Icon-Bug.pngBug: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.

These inputs are known to Hammer:

TurnOn
TurnOff
Enable or disable the light.
FOV <float>
See lightfov keyvalue above.
Parentname:
SetParent <stringRedirectInput/string>
Move with this entity. See Entity Hierarchy (parenting).
SetParentAttachment <stringRedirectInput/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 <stringRedirectInput/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.


Outputs