color changing water

lunarpumpkin

L2: Junior Member
Aug 31, 2016
72
15
is it even possible to achieve color changing water? since the color generally come from the fog in the water
 
May 25, 2015
390
307
Well, you have to do some scripting within your water .vmt file. I forgot to link this as well: https://developer.valvesoftware.com/wiki/Material_proxies
Since fog is using three values as a rgb, you need to set up accordingly. First, you should setup three variables for each of the rgb values. You can create custom variables in .vmt files that can be used by proxies. Something like this:
Code:
"$fogr" "0"
"$fogg" "0"
"$fogb" "0"
On their own, these variables doesn't do anything, but you can write to and read from them at runtime.
Proxies have to be created within the "Proxies" block of your vmt file. You'll have to use an individual proxy for each of your rgb values. For instance, if you want the red value of the fog pulse between 0.0 and 1.0, you should add a Sine proxy. A Sine proxy will cuase the affected variable to constantly oscillate. It should look something like this.
Code:
"Proxies"
{
"Sine"
{
  "resultVar" "$fogr" // This would be the custom variable for the specific fog rgb value you want to change.
  "sineperiod" "5" // How fast you want the value to pulse
  "sinemin" "0.0" // Set the min and max values to the min and max values you want your colors to be.
  "sinemax" " 1.0"
}
}

This will cuase the $fogr value to oscillate between 0.0 (no red) to 1.0 (full red).
Now, you need to read from these variables and add them to your $fogcolor variable, which is what the game actually uses to render the water color. This is accomplished through the Equals proxy. What this does is simply copy the value of one variable, and paste it into another. Additionally, it can also specify where it should put your value, if there are multiple values, like in $fogcolor. You should setup an Equals proxy for each of your rgb values like this:
Code:
"Equals"
{
"srcVar1" "$fogr" // The name of the variable you want to copy
"resultVar" "$fogcolor[0]" // The last number indicates where you want to insert the variable. 0 is for red, 1 is for green, and 2 is for blue.
}

And that should be it. I haven't actually tested it, but theoreticly, it should work.
 
Last edited:

lunarpumpkin

L2: Junior Member
Aug 31, 2016
72
15
true but what i want is for the golor to go from 1 0 0 to 1 1 0 to 0 1 0 to 0 1 1 to 0 0 1 to 1 0 1 to 1 0 0 again and so on , so im gonna use a bunch of conditions to achieve this result , thx for the help tho
 

Pocket

Half a Lambert is better than one.
aa
Nov 14, 2009
4,694
2,579
If you can figure it out, let me know. I'm not good enough with math to convert the available functions into the perfect hue cycling you've described, so the best I could do was set three sine functions that are offset by a third of the length of the period. Which results in the yellow, teal, and fuchsia phases being dimmer than they ought to be, among other things.
 

lunarpumpkin

L2: Junior Member
Aug 31, 2016
72
15
wait can color in sin go beyond and bellow 0 and 1? but lock at 0 and 1? if so just make it 2 0 -1 and make them folow with the same speed , they should hit the max color and stay on it till the other tunt fade off and the new one show
 

lunarpumpkin

L2: Junior Member
Aug 31, 2016
72
15
it worked , enjoy

"Water"
{
"%keywords" "tf"
"%tooltexture" "lunarpumpkin/water/lunarwater_normal"
"%compilewater" 1
"$forceexpensive" 1
"$envmap" "env_cubemap"
// "$abovewater" 1
$underwateroverlay "lunarpumpkin/water/lunarwater04_overlay"

"$refracttexture" "_rt_WaterRefraction"
"$refractamount" ".75"
"$refracttint" "{0 0 50}"

"$reflectentities" 1
"$reflecttexture" "_rt_WaterReflection"
"$reflectamount" ".75"
"$reflecttint" "{0 0 50}"

"$scale" "[1 1]"

"$bumpmap" "lunarpumpkin/water/lunarwater_dudv"
"$normalmap" "lunarpumpkin/water/lunarwater_normal"

"$surfaceprop" "water"
"$bottommaterial" "lunarpumpkin/water/lunarwater04_beneath.vmt"
"$bumpframe" "0"

$lunarvar1 0
$lunarvar2 0
$lunarvar3 0


"$fogenable" 1
"$fogcolor" "[0.0 0.0 1.0]"
"$fogstart" "0"
"$fogend" "800"

"Proxies"
{

"Sine"
{
"sineperiod" "9"
"sinemin" "-1.0"
"sinemax" " 2.0"
"timeoffset" "0"
"resultVar" "$lunarvar1"
}

"Sine"
{
"sineperiod" "9"
"sinemin" "-1.0"
"sinemax" " 2.0"
"timeoffset" "3"
"resultVar" "$lunarvar2"
}

"Sine"
{
"sineperiod" "9"
"sinemin" "-1.0"
"sinemax" " 2.0"
"timeoffset" "6"
"resultVar" "$lunarvar3"
}

"Equals"
{
"srcVar1" "$lunarvar1"
"resultVar" "$fogcolor[0]"
}

"Equals"
{
"srcVar1" "$lunarvar2"
"resultVar" "$fogcolor[1]"
}

"Equals"
{
"srcVar1" "$lunarvar3"
"resultVar" "$fogcolor[2]"
}

"AnimatedTexture"
{
"animatedtexturevar" "$normalmap"
"animatedtextureframenumvar" "$bumpframe"
"animatedtextureframerate" 30.00
}

"TextureScroll"
{
"texturescrollvar" "$bumptransform"
"texturescrollrate" .1
"texturescrollangle" 0
}
"WaterLOD"
{
"dummy" 0
}
}
}