Fading Values: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(I tried to Cleanup and fix the POV. Feel free to improve it. Thomas)
(cleanup)
Line 1: Line 1:
The author wants to share an advanced effect he has stumbled upon while designing a level in the Source engine.
This article describes an advanced effect in the [[Source]] engine, used to fade fog between different values, but it can be used for any entity that has a color value to change over time. You might also use that article to shift the Z-plane on a map to reduce the visibility, etc.
This effect is used to fade fog between different values, but it can be used for any entity that has a color value to change over time. You might also use that article to shift the Z-plane on a map, to reduce the visibility etc.


This article is quite powerful, as it allows you to alter values that we usually leave static on a map: it would add game immersion.
This trick is quite powerful, as it allows you to alter values that we usually leave static on a map: it would add game immersion.


Well, now let's go. Note that setup is quite simple. We will need for those entities only:
==Entities required==


* logic_relay - This entitiy is perfect to change game values or to abstract the routine. It also makes it much easier to duplicate the effect in other maps.
* <code>[[logic_relay]]</code> &mdash; This entity is perfect to change game values or to abstract the routine. It also makes it much easier to duplicate the effect in other maps.
* logic_timer This is the basis of the effect, this entities is designed for measuring the time ticks.
* <code>[[logic_timer]]</code> &mdash; This is the basis of the effect, this entities is designed for measuring the time ticks.
* math_counter - This keeps track of the evolution of the values uppon time for our effect.
* <code>[[math_counter]]</code> &mdash; This keeps track of the evolution of the values uppon time for our effect.
* math_colorblend or math_remap - Both these entities do essentially the same thing: they remap a value based on the input value.
* <code>[[math_colorblend]]</code> or <code>[[math_remap]]</code> &mdash; Both these entities do essentially the same thing: they remap a value based on the input value.


Here is the list of the I/O rigging here, so you can duplicate it easily for your map. You'll find information about all those I/O  at the end of the list.
==Entity setup==


  Logic_relay
  Logic_relay
Line 37: Line 36:
  OutColor env_fog_controller SetColor
  OutColor env_fog_controller SetColor


Analysis on what it's doing:
==Process description==
You trigger the logic_relay with another entity, or from the console with:
ent_fire fade_value1 trigger
This will start the sequence. The logic_relay starts the timer going, and resets the math_counter to 0. The timer refires every .2 seconds, firing it's output, OnTimer, which adds .01 to the math_counter's stored value. The math_counter fires it's OutValue output whenever it's value is changed, which is in turn input into the math_colorblend. The math_colorblend takes the input value, which is a range from 0-1, and changes the colors based on that.


This range allows for 100 steps. The values that are setup are a compromise between making the blend really smooth and performance. It's slightly "steppy" because it happens 5 times a second. It would be a lot smoother if you increased it to happen more often, with less of a step. You could do that by only adding .005 or a smaller value than the .01 I'm adding right now.
You trigger the <code>logic_relay</code> with another entity, or from the [[console]] with <code>ent_fire fade_value1 trigger</code>. This will start the sequence. The <code>logic_relay</code> starts the <code>logic_timer</code> and resets the <code>math_counter</code>. The <code>logic_timer</code> refires every .2 seconds, firing its output <code>OnTimer</code>, which adds .01 to the <code>math_counter</code>'s stored value. The <code>math_counter</code> outputs its <code>OutValue</code> whenever its value is changed, which is in turn put into the <code>math_colorblend</code>. The <code>math_colorblend</code> takes the input value, which is a range from 0-1, and changes the colors based on that.


Once the math_counter hits it's max value (1) it will fire an output telling the logic_timer to disable. This effectively stops the sequence until the logic_relay is fired again.
This range allows for 100 steps. The values that are setup are a compromise between making the blend really smooth and performance. It's slightly "steppy" because it happens only 5 times a second. It would be a lot smoother if you increased it to happen more often, with less of a step. You could do that by only adding .005 or a smaller value than the default .01.


OutColor and OutValue outputs both accept a parameter in Hammer, but make sure you do '''NOT''' specify one. The parameter they pass will be dynamically generated by the entity itself.
Once the <code>math_counter</code> hits its maximum value (1) it will fire an output telling the <code>logic_timer</code> to disable. This effectively stops the sequence until the <code>logic_relay</code> is fired again.


You can change OutColor on the math_colorblend to target any entity that will accept a colorvalue, and it should work just the same. This entity rig can be further adapted to work with a math_remap, and used to fade between any two values, allowing you to affect the values of pretty much any entity in the game, and change them over time.
<code>OutColor</code> and <code>OutValue</code> outputs both accept a parameter in [[Hammer]], but make sure you do not specify one. The parameter they pass will be dynamically generated by the entity itself.
 
You can change <code>OutColor</code> on the <code>math_colorblend</code> to target any entity that will accept a color value, and it should work just the same. This entity rig can be further adapted to work with a <code>math_remap</code>, and used to fade between any two values, allowing you to affect the values of pretty much any entity in the game, and change them over time.


[[Category:Level Design Tutorials]]
[[Category:Level Design Tutorials]]

Revision as of 09:47, 30 April 2006

This article describes an advanced effect in the Source engine, used to fade fog between different values, but it can be used for any entity that has a color value to change over time. You might also use that article to shift the Z-plane on a map to reduce the visibility, etc.

This trick is quite powerful, as it allows you to alter values that we usually leave static on a map: it would add game immersion.

Entities required

  • logic_relay — This entity is perfect to change game values or to abstract the routine. It also makes it much easier to duplicate the effect in other maps.
  • logic_timer — This is the basis of the effect, this entities is designed for measuring the time ticks.
  • math_counter — This keeps track of the evolution of the values uppon time for our effect.
  • math_colorblend or math_remap — Both these entities do essentially the same thing: they remap a value based on the input value.

Entity setup

Logic_relay
targetname fade_value1
OnTrigger counter SetValue 0
OnTrigger timer 
OnTrigger timer Enable
Logic_timer
targetname timer
RefireTime .2
StartDisabled 1
OnTimer counter Add .01
math_counter
targetname counter
max 1
OnHitMax timer Disable
OutValue colorblend InValue
math_colorblend
targetname colorblend
colormin "0 0 0"
colormax "255 255 255"
OutColor env_fog_controller SetColor

Process description

You trigger the logic_relay with another entity, or from the console with ent_fire fade_value1 trigger. This will start the sequence. The logic_relay starts the logic_timer and resets the math_counter. The logic_timer refires every .2 seconds, firing its output OnTimer, which adds .01 to the math_counter's stored value. The math_counter outputs its OutValue whenever its value is changed, which is in turn put into the math_colorblend. The math_colorblend takes the input value, which is a range from 0-1, and changes the colors based on that.

This range allows for 100 steps. The values that are setup are a compromise between making the blend really smooth and performance. It's slightly "steppy" because it happens only 5 times a second. It would be a lot smoother if you increased it to happen more often, with less of a step. You could do that by only adding .005 or a smaller value than the default .01.

Once the math_counter hits its maximum value (1) it will fire an output telling the logic_timer to disable. This effectively stops the sequence until the logic_relay is fired again.

OutColor and OutValue outputs both accept a parameter in Hammer, but make sure you do not specify one. The parameter they pass will be dynamically generated by the entity itself.

You can change OutColor on the math_colorblend to target any entity that will accept a color value, and it should work just the same. This entity rig can be further adapted to work with a math_remap, and used to fade between any two values, allowing you to affect the values of pretty much any entity in the game, and change them over time.