This article's documentation is for anything that uses the Source engine. Click here for more information.

Material modify control: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
(22 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{lang|{{PAGENAME}}}}
{{This is a|logical entity|name=material_modify_control}} It is used to modify arbitrary [[material]] properties in response to [[I/O]] events.
{{Entity|material_modify_control|type=e0}} It is used to modify arbitrary [[material]] properties in response to [[I/O]] events.
{{CD|CMaterialModifyControl|file1=MaterialModifyControl.cpp}} For the entity to work, its target material must have the <code>MaterialModify</code> or <code>MaterialModifyAnimated</code> [[Material Proxies|proxy]] installed, and must be applied to an entity.


For the entity to work, its target material must have the <code>MaterialModify</code> or <code>MaterialModifyAnimated</code> [[Material Proxies|proxy]] installed, and must be applied to an entity.
Does similar things to the {{ent|env_texturetoggle}} entity, which can control brushes or overlays by [[targetname]].


Compare this with the {{ent|env_texturetoggle}} entity, which can control brushes or overlays by [[targetname]].
{{bug|The entity will not work unless it's parented to an object that's in the [[PVS]], is on-screen, and has at least one face facing towards the viewer that's textured with the <tt>Material to modify</tt>.}}
Instances of the Material to Modify on world geometry are controlled by the lowest-ID (first created in Hammer) <tt>material_modify_control</tt>, in addition to instances of the material on the <tt>material_modify_control</tt>'s parent.
Instances of the Material to Modify on world geometry are controlled by the lowest-ID (first created in Hammer) <tt>material_modify_control</tt>, in addition to instances of the material on the <tt>material_modify_control</tt>'s parent.
{{important|Must be parented to an entity which has the material that is going to be modified. Material modification will take effect ''only after the material is rendered'' on the parented entity.}}


== Keyvalues ==
== Keyvalues ==
{{KV|Material to modify|intn=materialName|string|Path to the VMT file you want to modify, relative to <code>materials/</code> folder. Without <code>.vmt</code> suffix.
{{KV Targetname}}
{{bug|Does not work if the VMT is just in <code>materials/</code>. Should be in a subfolder, like <code>materials/effects/</code> for example.}}
{{KV|Material to modify|intn=materialName|material|Path to the VMT file you want to modify, relative to <code>materials/</code> folder. Omit <code>.vmt</code> suffix.
{{bug|When a [[material]] has a {{ent|$envmap}} with <code>env_cubemap</code> as the value, this entity will appear to not work for that material. This is because [[VBSP]] will patch the original material and give it a different name that corresponds to the position of the closest [[cubemap]] to the brush face that has that material. This happens for every occurrence of the material. In order to make it work, you can replace the <code>env_cubemap</code> in your material with the path to the generated image of the closest cubemap. For example: <tt>env_cubemap "maps/yourmap/c124_28_-60"</tt>. This means, however, that you will have to do it for every occurrence of the material you want to change, especially when you want them to use different cubemap images. This will make it so that VBSP will not try to patch the material and thus leave the original name. Another way is to just to directly specify the patched material name that is generated by VBSP, which you can find after unpacking the map file.}} }}
:{{bug|Does not work if the VMT is just in <code>materials/</code>. Should be in a subfolder, like <code>materials/effects/</code> for example.}}
:{{bug|When a [[material]] has a {{ent|$envmap}} with <code>env_cubemap</code> as the value, this entity will appear to not work for that material. This is because [[VBSP]] will patch the original material and give it a different name that corresponds to the position of the closest [[cubemap]] to the brush face that has that material. This happens for every occurrence of the material. In order to make it work, you can replace the <code>env_cubemap</code> in your material with the path to the generated image of the closest cubemap. For example: <tt>env_cubemap "maps/yourmap/c124_28_-60"</tt>. This means, however, that you will have to do it for every occurrence of the material you want to change, especially when you want them to use different cubemap images. This will make it so that VBSP will not try to patch the material and thus leave the original name. Another way is to just to directly specify the patched material name that is generated by VBSP, which you can find after unpacking the map file.}}}}
{{KV|Material variable to modify|intn=materialVar|string|Name of the [[:Category:List of Shader Parameters|shader parameter]] you want to modify. Include the <code>$</code> symbol like how they are written in the VMT.}}
{{KV|Material variable to modify|intn=materialVar|string|Name of the [[:Category:List of Shader Parameters|shader parameter]] you want to modify. Include the <code>$</code> symbol like how they are written in the VMT.}}
{{KV Targetname}}
{{Warning|In {{l4d2}} when using VScript don't modify m_szMaterialName and m_szMaterialVar using NetProps.SetPropString. It won't work properly because of the way it's stored{{confirm}}. Using AddOutputs or Set* inputs of this entity is required. The same applies to using NetProps.GetPropString which won't give you expected results.}}


== Inputs ==
== Inputs ==
{{IO|SetMaterialVar|Sets the chosen material parameter to the specified value.|param=string}}
{{I|SetMaterialVar|Sets the chosen material parameter to the specified value.|param=string}}
{{IO|SetMaterialVarToCurrentTime|This sets the material variable to the current time on the server.}}
:{{warning|At least in {{src13}}, it doesn't convert given values to strings, so it can't accept inputs from entities which output anything else than string, {{ent|math_counter}} or {{ent|math_colorblend}} for example.}}
{{IO|StartAnimSequence|Force an animated material with the <tt>MaterialModifyAnimated</tt> proxy to play a set of animation frames. <br/> Format is: <code><Frame Start> <Frame End> <Frame Rate> <Loop></code> <br/> <code><Loop></code> should be 1 or 0. {{tip|Setting "Frame End" to -1 uses the last frame of the texture.}}|param=string}}
:{{todo|Confirm in other games/engines and find workaround.}}
{{IO|StartFloatLerp|Force a material with the <tt>MaterialModifyAnimated</tt> proxy to linearly interpolate a material var between two floating point values. <br/> Format is: <code><Start Value> <End Value> <Transition Time> <Loop></code> <br/> <code><Loop></code> should be 1 or 0.
{{I|SetMaterialVarToCurrentTime|This sets the material variable to the current time on the server.}}
{{note|For the linear interpolation to work correctly, you need both the <tt>MaterialModify</tt> and <tt>MaterialModifyAnimated</tt> proxies to be present.}}
{{I|StartAnimSequence|Force an animated material with the <tt>MaterialModifyAnimated</tt> proxy to play a set of animation frames. <br/> Format is: <code><Frame Start> <Frame End> <Frame Rate> <Loop></code> <br/> <code><Loop></code> should be 1 or 0. {{tip|Setting "Frame End" to -1 uses the last frame of the texture.}}|param=string}}
{{todo|There are some clarifications needed to be done about some quirks of this input.}}|param=string}}
:{{bug|In {{css}} using -1 will cause a random texture in the map to display as the last frame before it resets to the first frame.}}
:{{warning|This input will crash the game if the material has a <tt>MaterialModify</tt> proxy.}}
{{I|StartFloatLerp|Force a material with the <tt>MaterialModifyAnimated</tt> proxy to linearly interpolate a material var between two floating point values. <br/> Format is: <code><Start Value> <End Value> <Transition Time> <Loop></code> <br/> <code><Loop></code> should be 1 or 0.|param=string}}
:{{note|On an animated texture both the <tt>MaterialModify</tt> and <tt>MaterialModifyAnimated</tt> proxies need to be present for this input to work.}}
:{{bug|<tt>StartFloatLerp</tt> will never loop.|tested={{css}}}}


[[Category:Material System]]
[[Category:Material System]]

Latest revision as of 05:16, 29 April 2025

material_modify_control is a logical entity available in all Source Source games. It is used to modify arbitrary material properties in response to I/O events.

C++ Class hierarchy
CMaterialModifyControl
CBaseEntity
C++ MaterialModifyControl.cpp

For the entity to work, its target material must have the MaterialModify or MaterialModifyAnimated proxy installed, and must be applied to an entity.

Does similar things to the env_texturetoggle entity, which can control brushes or overlays by targetname.

Instances of the Material to Modify on world geometry are controlled by the lowest-ID (first created in Hammer) material_modify_control, in addition to instances of the material on the material_modify_control's parent.

Icon-Important.pngImportant:Must be parented to an entity which has the material that is going to be modified. Material modification will take effect only after the material is rendered on the parented entity.

Keyvalues

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

Material to modify (materialName) <material>
Path to the VMT file you want to modify, relative to materials/ folder. Omit .vmt suffix.
Icon-Bug.pngBug:Does not work if the VMT is just in materials/. Should be in a subfolder, like materials/effects/ for example.  [todo tested in ?]
Icon-Bug.pngBug:When a material has a $envmap with env_cubemap as the value, this entity will appear to not work for that material. This is because VBSP will patch the original material and give it a different name that corresponds to the position of the closest cubemap to the brush face that has that material. This happens for every occurrence of the material. In order to make it work, you can replace the env_cubemap in your material with the path to the generated image of the closest cubemap. For example: env_cubemap "maps/yourmap/c124_28_-60". This means, however, that you will have to do it for every occurrence of the material you want to change, especially when you want them to use different cubemap images. This will make it so that VBSP will not try to patch the material and thus leave the original name. Another way is to just to directly specify the patched material name that is generated by VBSP, which you can find after unpacking the map file.  [todo tested in ?]
Material variable to modify (materialVar) <string>
Name of the shader parameter you want to modify. Include the $ symbol like how they are written in the VMT.
Warning.pngWarning:In Left 4 Dead 2 when using VScript don't modify m_szMaterialName and m_szMaterialVar using NetProps.SetPropString. It won't work properly because of the way it's stored[confirm]. Using AddOutputs or Set* inputs of this entity is required. The same applies to using NetProps.GetPropString which won't give you expected results.

Inputs

SetMaterialVar <stringRedirectInput/string>
Sets the chosen material parameter to the specified value.
Warning.pngWarning:At least in Source 2013, it doesn't convert given values to strings, so it can't accept inputs from entities which output anything else than string, math_counter or math_colorblend for example.
Todo: Confirm in other games/engines and find workaround.
SetMaterialVarToCurrentTime
This sets the material variable to the current time on the server.
StartAnimSequence <stringRedirectInput/string>
Force an animated material with the MaterialModifyAnimated proxy to play a set of animation frames.
Format is: <Frame Start> <Frame End> <Frame Rate> <Loop>
<Loop> should be 1 or 0.
Tip.pngTip:Setting "Frame End" to -1 uses the last frame of the texture.
Icon-Bug.pngBug:In Counter-Strike: Source using -1 will cause a random texture in the map to display as the last frame before it resets to the first frame.  [todo tested in ?]
Warning.pngWarning:This input will crash the game if the material has a MaterialModify proxy.
StartFloatLerp <stringRedirectInput/string>
Force a material with the MaterialModifyAnimated proxy to linearly interpolate a material var between two floating point values.
Format is: <Start Value> <End Value> <Transition Time> <Loop>
<Loop> should be 1 or 0.
Note.pngNote:On an animated texture both the MaterialModify and MaterialModifyAnimated proxies need to be present for this input to work.
Icon-Bug.pngBug:StartFloatLerp will never loop.  (tested in: Counter-Strike: Source)