AlliedModders (
-   Scripting (
-   -   Changing loaded material parameters on-the-fly (

Sappykun 09-14-2020 02:45

Changing loaded material parameters on-the-fly
Is it possible to modify parameters on materials that have been loaded on the client?

For example, I want to change the framerate of specific animated decals and have those changes visible by all players on the server.


Disregard this thread, what I'm asking for isn't possible and isn't actually what I want.

Balimbanana 09-16-2020 15:07

Re: Changing loaded material parameters on-the-fly
You won't be able to modify decals, but you *can* modify certain material variables on entities using a material_modify_control:

@PointClass base(Parentname, Targetname) size(-8 -8 -8, 8 8 8 ) = material_modify_control :
        "An entity that can be used to directly control material vars. To use it, you need to read the .vmt of the material you "+
        "intend to change. Parent this entity to a brush model entity or prop who's material you want to control."
        materialName(string) : "Material to modify."
        materialVar(string) : "Material variable to modify."

        // Inputs
        input SetMaterialVar(string) : "Fire to modify a material variable. The argument is the value to set the variable to."
        input SetMaterialVarToCurrentTime(void) : "This sets the material variable to the current time on the server."
        input StartAnimSequence(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>\nSetting <Frame End> to -1 uses the last frame of the texture. <Loop> should be 1 or 0."
        input StartFloatLerp(string) : "Force a material with the MaterialModifyAnimated proxy to lerp a material var between two floating point values. Format is: <Start Value> <End Value> <Transition Time> <Loop>\n<Loop> should be 1 or 0."

Here is an example from Half-Life 2 Episode 1 of some parameters:

"parentname" "monitor_core_status4"
"materialVar" "$frame"
"materialName" "effects/combinedisplay_core_"
"targetname" "Matcontrol_core"
"classname" "material_modify_control"

Then inputs of:
"OnMapSpawn" "Matcontrol_core,StartAnimSequence,0 5 2 1,0,-1"
"OnStartTouch" "Matcontrol_core,StartAnimSequence,12 17 4 1,0,1"
"OnTrigger" "Matcontrol_core,StartAnimSequence,6 11 4 1,10,1"
"OnTrigger" "Matcontrol_core,StartAnimSequence,18 21 8 1,10,-1"

Here is one for the blue vortigaunt with warp effects:
"materialVar" "$WARPPARAM"
"materialName" "models/vortigaunt/eyeball_blue.vmt"
"targetname" "matcontrol_vort"
"parentname" "vort_summon"
"classname" "material_modify_control"

With inputs of:
"OnTimer" "matcontrol_vort,StartFloatLerp,0 1 2 0,1,-1"
"OnSpawn" "matcontrol_vort,SetMaterialVar,0,0,-1"

Here is one for the flesh effect on Alyx in Episode 2:

"targetname" "matcontrol_timestop_alyx"
"parentname" "alyx"
"materialVar" "$FleshScrollSpeed"
"materialName" "models/alyx/alyx_interior_sheet.vmt"
"classname" "material_modify_control"

With inputs of:
"OnTrigger" "matcontrol_timestop_alyx,SetMaterialVar,1,0,-1"
"OnTrigger" "matcontrol_timestop_alyx,SetMaterialVar,0,0,-1"

Even in Portal, in the first room with the clock counting down is a material_modify_control:

"targetname" "mmc_clock_centiseconds_wall"
"parentname" "brush_clock_centiseconds_wall"
"materialVar" "$frame"
"materialName" "signage/clock/clock_centiseconds"
"classname" "material_modify_control"

"targetname" "mmc_clock_centiseconds_cell"
"parentname" "brush_clock_centiseconds_cell"
"materialVar" "$frame"
"materialName" "signage/clock/clock_centiseconds"
"classname" "material_modify_control"

With inputs of:
"OnTrigger" "mmc_clock_centiseconds_wall,SetMaterialVar,59,0,-1"
"OnTrigger" "mmc_clock_centiseconds_cell,SetMaterialVar,59,0,-1"
"OnTimer" "mmc_clock_centiseconds_cell,StartFloatLerp,0 59 1 0,0,-1"
"OnTimer" "mmc_clock_centiseconds_wall,StartFloatLerp,0 59 1 0,0,-1"

There are a lot of things you can do with it, if you know what you are doing. It would be nice if there were some natives written for SourceMod that could easily set some of these things up though.

All times are GMT -4. The time now is 12:40.

Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.