Javascript required
Skip to content Skip to sidebar Skip to footer

Change the Color of a Light Using Lua Garry's Mod

English 简体中文

Env_projectedtexture has different appearances

Portal 2 uses projected textures extensively for world lighting.

Showcase of Portal 2: Community Edition volumetrics in a Portal 2 map.

env_projectedtexture is a point entity available in all Source games since Half-Life 2: Episode One Half-Life 2: Episode One Half-Life 2: Episode One . It projects a texture as a dynamic light that affects all objects in the world, optionally with Shadow Mapping. env_Projectedtexture does not light the world similarly that other light entities which are ray-traced when you compile the map. This light however is real-time and works without RAD.

Warning.png Warning: This is the most expensive light entity in the engine. Use sparingly.

In code, it is represented by the CEnvProjectedTexture class, defined in the env_projectedtexture.cpp file.

Contents

  • 1 Caveats and Fixes
    • 1.1 Source 2007/2009 bugs
  • 2 Flags
  • 3 Keyvalues
  • 4 Inputs
  • 5 Outputs

Caveats and Fixes

Main article: Env_projectedtexture/fixes
  • Valve's games only support one shadow map in the PVS at a time.

Warning.png Warning: Counter-Strike: Global Offensive Only one projected texture can ever be active in the map, regardless of shadow settings

  • Textures used for projected textures require the flags Clamp S, Clamp T and Clamp All to avoid glitchy tiling. Also note, that VTFs are used directly and no VMT is needed.

Note.png Note: In Garry's Mod, there can be up to 9 active env_projectedtextures turned on with shadow mapping at a time. You can also increase this limit by putting -numshadowtextures # in the Steam launch parameters of Garry's Mod, where # is the number of shadow maps the game should allow.

Note.png Note: Portal 2: Community Edition increases this limit to 8.

  • Shadows are only rendered when the user is running with "High" shadow detail. If your options menu does not show the "High" shadow detail setting by default, you can add -force_vendor_id 0x10DE -force_device_id 0x1180 to the game's launch options for it to show up.
  • Note.png Note: In Counter-Strike: Global Offensive, shadows from env_projectedtexture work on "Low" video settings.

  • In multiplayer, mat_supportflashlight must be set to 1 for flashlights to work. By default these ConVars are disabled in Team Fortress 2, so this entity won't work there without special configuration.
  • Viewmodels won't receive light or shadows from projected textures, with the exception of Garry's Mod and Portal 2. You can follow these instructions to fix this bug.

Bug.png Bug: In Portal 2, some Nvidia graphics cards render white specks or squares on certain textures. To fix this, remove the bumpmap ($bumpmap or $ssbump) or $detail textures.

Video of said bug.

Bug.png Bug: In Portal 2, while running in DirectX 9 mode, some graphics cards will not render shadows from env_projectedtexture regardless of the shadow detail setting. To fix this, run the game in Vulkan mode with the launch parameter -vulkan.

Bug.png Bug: Parenting does not work with stock SDK code.

Source 2007/2009 bugs

These have all been fixed in more recent engine builds.

Bug.png Bug: The configurable texture value from Hammer is not accepted - will always default to the flashlight. You must use the SpotlightTexture input or you can also override the actual contents of the default VTF with a new one.

Note.png Note: The SpotlightTexture input has been disabled in the Portal 2 and CS:GO engines, and instead shows an error message: "SetSpotlightTexture is disabled. If you need this feature reimplemented, tell a programmer."

Bug.png Bug: The entity cannot target another entity.

Bug.png Bug: Models will not receive their own shadows correctly unless using $bumpmap. Even a flat bump map is sufficient.

Bug.png Bug: Causes issues if the entity overlaps a portal in Portal 1. Simply the projection overlapping a portal works fine.

Flags

  • 1: Enabled
  • 2: Always Update (moving light)

(in all games since Alien Swarm) (also in <Mapbase>)

Keyvalues

Target (target) <targetname>
The entity will rotate to point at this target. Make sure you check the Always update flag if you set this.
FOV (lightfov) <float>
The field of view cone/pyramid at which the texture is projected.

Confirm: This keyvalue does not work in Alien Swarm.

NearZ (nearz) <float>
Objects closer than this will not receive the light from the projection.
FarZ (farz) <float>
Objects beyond this distance will not receive the light from the projection.
Enable Shadows (enableshadows) <boolean>
Enables/disables shadows from this projected texture. 0 = no, 1 = yes.
Shadow Quality (shadowquality) <choices>
Quality of shadows.
  • 0: Low (sharp, pixelized shadows)
  • 1: High (smooth edged shadows)
Light Only Target (lightonlytarget) <boolean>
Limit flashlight effect to only affect target entity.
Light World (lightworld) <boolean>
Control whether flashlight affects static world geometry. 0 = no, 1 = yes.
Light Color (lightcolor) <color255 + int>
Light color and intensity.
Camera Space (cameraspace) <integer>
Angles are interpreted as being relative to camera.
Texture Name (texturename) <string>!FGD
The texture which this entity projects. Must be a VTF file (not VMT), relative to /materials.
Texture Frame (textureframe) <integer>!FGD
If the texture is animated, this is the frame it should begin on.
Simple Projection (simpleprojection) <boolean>(in all games since Alien Swarm)!FGD
Indicates if this is a simple, non-light casting texture projection.
Simple Projection Size (projection_size) <float>(in all games since Alien Swarm)!FGD
Size of the simple projection.
Simple Projection Rotation (projection_rotation) <float>(in all games since Alien Swarm)!FGD
Brightness Scale (brightnessscale) <float>(in all games since Alien Swarm)
Scale the light color by this brightness.
Color Transition Time (colortransitiontime) <float>(in all games since Alien Swarm)
Amount of time it takes for a color change to occur. Higher numbers cause faster transitions.
Appearance (style) <choices>(in all games since Portal 2)(also in Garry's Mod)
Various Custom Appearance presets.

Note.png Note: Requires input AlwaysUpdateOn to work.

Light Appearances
Literal Value Description Sequence Preview
0 Normal m Sequence 0.gif
10 Fluorescent flicker mmamammmmammamamaaamammma Sequence 10.gif
2 Slow, strong pulse abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba Sequence 2.gif
11 Slow pulse, noblack abcdefghijklmnopqrrqponmlkjihgfedcba Sequence 11.gif
5 Gentle pulse jklmnopqrstuvwxyzyxwvutsrqponmlkj Sequence 5.gif
1 Flicker A mmnmmommommnonmmonqnmmo Sequence 1.gif
6 Flicker B nmonqnmomnmomomno Sequence 6.gif
3 Candle A mmmmmaaaaammmmmaaaaaabcdefgabcdefg Sequence 3.gif
7 Candle B mmmaaaabcdefgmmmmaaaammmaamm Sequence 7.gif
8 Candle C mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa Sequence 8.gif
4 Fast strobe mamamamamama Sequence 4.gif
9 Slow strobe aaaaaaaazzzzzzzz Sequence 9.gif
12 !FGD Underwater light mutation mmnnmmnnnmmnn Sequence 12.gif
Custom Appearance (pattern) <string>(in all games since Portal 2)(also in Garry's Mod)
Set a custom pattern of light brightness for this light. Pattern format is a string of characters, where a is total darkness, z fully bright. i.e. aaggnnttzz would be a steppy fade in from dark to light.
Default Appearance (defaultstyle) <string>(in all games since Portal 2)
Enable Volumetrics (volumetric) <boolean>(only in Portal 2: Community Edition)
Whether or not to use volumetrics for this projected texture.
Volumetric Intensity (volumetricintensity) <float>(only in Portal 2: Community Edition)
Defines the intensity of the volumetrics. (Default is 1. Can go above; no strict limit)

Base:

Name (targetname) <string>
The name that other entities use to refer to this entity.
Parent (parentname) <targetname>
Maintain the same initial offset to this entity. An attachment point can also be used if separated by a comma at the end. (parentname [targetname],[attachment])

Tip.png Tip: Entities transition to the next map with their parents

Tip.png Tip: phys_constraintcan be used as a workaround if parenting fails.

Global Entity Name (globalname) <string>
When the player transitions to a new map, entities in the new map with matching globalnames will have their previous map's states copied over to it.
Origin (X Y Z) (origin) <coordinates>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.

Note.png Note: Hammer does not move the entities accordingly only in the editor.

Pitch Yaw Roll (X Y Z) (angles) <angle>
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.

Note.png Note: This works on brush entities, although Hammer doesn't show the new angles.

Response Contexts (ResponseContext) <string>
Pre-defined response system contexts; Format is [key]:[value],[key]:[value],...and so on.
Classname (classname) <string>!FGD
Determines the characteristics of the entity before it spawns.

Tip.png Tip: Changing classnames using theAddOutputinput can still influence the game's code, like making the classname match one element in the S_PreserveEnts list will make the entity persists on new rounds!

Flags (spawnflags) <integer>!FGD
Toggles exclusive features of an entity, its specific number is determined by the combination of flags added.
Effects (effects) <integer>!FGD
Combination of effect flags to use.
Hammer ID (hammerid) <integer>!FGD
The entity's unique Hammer ID that's auto-generated on map compiles. Mainly used by plugins or debugging commands (like the ent_keyvalue command). Run-time spawned entities don't have a Hammer ID.
Entity Scripts (vscripts) <scriptlist>(in all games since Left 4 Dead 2)
Space delimited list of VScript files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions.
Script think function (thinkfunction) <string>(in all games since Left 4 Dead 2)
Name of a function in this entity's script which will be called automatically every 100 milliseconds (ten times a second) for the duration of the script. It can be used to create timers or to simulate autonomous behavior. The return value (if present) will set the time until the next call. Try to avoid expensive operations in this function, as it may cause performance problems.
Lag Compensation (LagCompensate) <boolean>(in all games since Left 4 Dead 2)!FGD
Set to Yes to lag compensate this entity. Should be used very sparingly!
Disable for Xbox 360 (disableX360) <boolean>(in all games since Left 4 Dead 2)!FGD
If this entity should automatically be given the 'Disable' input on the Xbox 360 version of Source.
Is Automatic-Aim Target (is_autoaim_target) <boolean>(in all games since Counter-Strike: Global Offensive)!FGD
If set to 1, this entity will slow down aiming movement for consoles and joystick controllers when the entity is under the crosshairs.

Inputs

Note.png Note: In some FGDs, only TurnOn, TurnOff and FOV are present.

TurnOn
Turns on the texture.

Confirm: In gmod projected lights always start on even when "enabled" is not checked.

TurnOff
Turns off the texture.
FOV <float>
Sets FOV.
EnableShadows <boolean>
Set the if shadows are enabled. 0 = no, 1 = yes.
SpotlightTexture <string>
Sets the spotlight texture.

Note.png Note: Disabled in Portal 2 onwards. Fixed in Portal 2: Community Edition

Target <string>
Specify a new Target entity to point at.
CameraSpace <boolean>
Sets Camera Space.
LightOnlyTarget <boolean>
Sets Light Only Target.
LightWorld <integer>
Sets Light World. 0 = no, 1 = yes.
AlwaysUpdateOn(in all games since Alien Swarm)
Turn on per frame updating (for moving lights).
AlwaysUpdateOff(in all games since Alien Swarm)
Turn off per frame updating (for moving lights).
LightColor <color255>(in all games since Alien Swarm)
Change the Light Color.
SetLightStyle <integer>(in all games since Portal 2)(also in Garry's Mod)
Sets an Appearance. (see Appearance keyvalue above for possible values)
SetPattern <string>(in all games since Portal 2)(also in Garry's Mod)
Sets Custom Appearance. (see Custom Appearance keyvalue above)
SetNearZ <float>(in all games since Portal 2)(also in Garry's Mod)
Sets NearZ.
SetFarZ <float>(in all games since Portal 2)(also in Garry's Mod)
Sets FarZ.
EnableVolumetrics <boolean>(only in Portal 2: Community Edition)
Enables or disables volumetrics.
SetVolumetricIntensity <float>(only in Portal 2: Community Edition)
Sets the intensity of the volumetrics. (Default is 1. Can go above; no strict limit)
SetBrightnessScale <float>(only in Portal 2: Community Edition)
Sets the brightness.


Base:

AddContext <string>
Adds to the entity's list of response contexts. Format is <key>:<value>.
AddOutput <string>
Assigns a new keyvalue/output on this entity. For keyvalues, some rely on extra necessary code to be ran and won't work if its simply just changed through this input. There is a strict format that must be followed:

Syntax:

                            //              Format              of              changing              KeyValues              :              "AddOutput [key] [value]"              ////              Raw              text              :              "OnUser1"              "!self,AddOutput,targetname new_name"              //              Format              of              adding              an              Output              :              "AddOutput {targetname}:{inputname}:{parameter}:{delay}:{max times to fire, -1 means infinite}"              ////              Raw              text              :              "OnUser1"              "!self:SetParent:!activator:0.0:-1"              //              Arguments              can              be              left              blank              ,              but              the              empty              blank              should              still              be              contained              .              ////              Raw              text              :              "OnUser1"              "!self:ClearParent::0.0:-1"            
ClearContext
Removes all contexts from this entity's list.
ClearParent
Removes this entity from the the movement hierarchy, leaving it free to move independently.
FireUser1 to FireUser4
Fires the respectiveOnUseroutputs; see User Inputs and Outputs.
Kill
Removes this entity and any entities parented to it from the world.
KillHierarchy
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster thanKillinput.
RemoveContext <string>
Remove a context from this entity's list. The name should match the key of an existing context.
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.
Use!FGD
Same as a player invoking +use; no effect in most cases.
DispatchResponse <string>!FGD
Dispatches a response to the entity. See Response and Concept.
DispatchEffect <string>(removed since Left 4 Dead)!FGD
Dispatches a special effect from the entity's origin; see also List of Client Effects. Replaced by the particle system since Left 4 Dead.
RunScriptFile <script>(in all games since Left 4 Dead 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode <string>(in all games since Left 4 Dead 2)
Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console.

Bug.png Bug: In Hammer, using string arguments will corrupt the VMF file's structure, making the file unviewable for the next Hammer session.

Fix: Remove the string argument manually with a text editor.

CallScriptFunction <string>(in all games since Left 4 Dead 2)!FGD
Execute a VScript function in the scope of the receiving entity.
SetLocalOrigin <coordinates>(in all games since Alien Swarm)!FGD
Send this entity to a spot in the map. If the entity is parented to something, it will be offset from the parent by this amount.
SetLocalAngles <angles>(in all games since Alien Swarm)!FGD
Set this entity's angles.

Outputs

Base:

OnUser1 to OnUser4
These outputs each fire in response to the firing of the like-numbered FireUser1 to FireUser4 Input; see User Inputs and Outputs.
OnKilled(only in Left 4 Dead Left 4 Dead 2)
This output fires when the entity is killed and removed from the game.

Change the Color of a Light Using Lua Garry's Mod

Source: https://developer.valvesoftware.com/wiki/Env_projectedtexture