Env projectedtexture: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(cleanup)
(whoops)
Line 2: Line 2:
[[Image:Projected texture.jpg|thumb|Projecting a colourful [[texture]].]]
[[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.
{{base_point_ep2}} It creates a dynamic [[Wikipedia:Shadow mapping|shadow-mapping]] light 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!}}
{{warning|Using this entity incorrectly can send your [[fillrate]] (i.e. swap buffers) through the roof!}}
Line 130: Line 130:
==Outputs==
==Outputs==
* {{O Targetname}}
* {{O Targetname}}
{{wrongtitle|title=env_projectedtexture}} [[Category:Snippets]]

Revision as of 04:03, 18 June 2009

Casting shadows.
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.

Warning.pngWarning:Using this entity incorrectly can send your fillrate (i.e. swap buffers) through the roof!
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 ?]

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

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.

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: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.
Icon-Bug.pngBug: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 #000000
Projected color
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: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 or target).
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.
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.

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.
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.

Outputs

Template:Wrongtitle