User:DJFluXion/Making Your Own Water: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
Tag: New redirect
 
Line 1: Line 1:
'''[[Water]]''' is one of the Source engine's most complex material types/shaders.
#redirect [[User:VectorFluxion/Making Your Own Water]]
 
Water does not have a <code>$basetexture</code> value by default, but rather, is made up of a real-time transforming [[wp:normal map|normal map]], fog, a combination of reflection and refraction, a flow map (for dx90 users and below), and an [[env_cubemap]] to give the water surface a [[specular reflection]] effect.
 
Water in the Source engine, is composed of three different elements:
*A material for when the observer is above the water surface, facing down into it;
*A material for when the observer is beneath the water surface, looking upwards; and,
*A scrolling overlay screen effect that the observer sees when underwater.
 
=="Expensive" vs. "Cheap" Water==
Cheap water has all the properties of expensive water; however, there are some notable differences.
*Cheap water is completely opaque from the surface, does not refract, and has limited reflection.
*Cheap water is commonly used at at distance, solely for optimization purposes.
**The entity that controls the distance in hammer units, that the expensive water begins fading to cheap water, is the [[water_lod_control]].
 
==Generic VMT Files For Water==
[[File:TF2FlowMap.png|150px|thumb|The flow map used by TF2's water, for sub-dx90 users.]]
The general code for the three elements of water.
 
For color values, both RGB and HSV can be used. Use square brackets for denote a HSV value <code>"[H S V]"</code> and curly brackets to denote a RGB value <code>"{R G B}"</code>.
 
For sub-dx90 users, a flow map (pictured to the right) must be used, as this will be transformed instead of a normal map. A flow map is also called a du/dv map, a derivative map, and a movement map. The flow map will be specified using the <code>$bumpmap</code> material parameter. <code>$bumpmap</code> should only be used in [[fallback materials]], and specified in the main water file, using the <code><dx90</code> rule, with the <code>$fallbackmaterial</code> material parameter inside.
 
It is generally recommended to make a fallback material for water, as water can be a memory-hog on older computers.
 
===Above water material:===
 
<pre>
"Water"
{
"%compilewater" 1
"%keywords" "<string>"
"%tooltexture" "<path> relative to <game abbr>/materials/"
"$abovewater" 1
"$underwateroverlay" "<path> relative to <game abbr>/materials/"
"$refracttexture" "_rt_WaterRefraction"
"$refracttint" "<RGB>" or "<HSV>"
"$normalmap" "<path> relative to <game abbr>/materials/"
"$refractamount" <value>
"$envmap" "env_cubemap"
"$refractblur" 1
"$surfaceprop" water
"$bottommaterial" "<path> relative to <game abbr>/materials/"
"$scale" "[1 1]"
"$bumpframe" 0
"$fogenable" <bool>
"$fogcolor" "<RGB>" or "<HSV>"
"$fogstart" <value in HU>
"$fogend" <value in HU>
"$temp" "[0 0]"
"$curr" 0
"$curr2" 0
"Proxies"
{
"AnimatedTexture"
{
"animatedtexturevar" "$normalmap"
"animatedtextureframenumvar" "$bumpframe"
"animatedtextureframerate" 30
}
"TextureTransform"
{
"translatevar" "$temp"
"resultvar" "$bumptransform"
}
"Sine"
{
"sineperiod" 20
"sinemax" .6
"sinemin" -.6
"resultvar" "$curr"
}
"Sine"
{
"sineperiod" 15
"sinemax" -.6
"sinemin" .6
"resultvar" "$curr2"
}
"Equals"
{
"srcvar1" "$curr2"
"resultvar" "$temp[0]"
}
"Equals"
{
"srcvar1" "$curr"
"resultvar" "$temp[1]"
}
"WaterLOD"
{
"dummy" 0
}
}
}
</pre>
 
===Below water material:===
<pre>
"Water"
{
"%compilewater" 1
"%keywords" "<string>"
"%tooltexture" "<path> relative to <game abbr>/materials/"
"$abovewater" 0
"$cheapwaterstartdistance" <value in HU>
"$cheapwaterenddistance" <value in HU>
"$refractamount" <value>
"$reflectamount" 1
"$refracttint" "<RGB>" or "<HSV>"
"$reflecttint" "<RGB>" or "<HSV>"
"$refracttexture" "_rt_WaterRefraction"
"$scale" "[1 1]"
"$blurrefract" 1
"$normalmap" "<path> relative to <game abbr>/materials/"
"$underwateroverlay" "<path> relative to <game abbr>/materials/"
"$surfaceprop" "water"
"$bumpframe" 0
"$fogenable" <bool>
"$fogcolor" "<RGB>" or "<HSV>"
"$fogstart" <value in HU>
"$fogend" <value in HU>
"Proxies"
{
"AnimatedTexture"
{
"animatedtexturevar" "$normalmap"
"animatedtextureframenumvar" "$bumpframe"
"animatedtextureframerate" 30
}
"TextureScroll"
{
"texturescrollvar" "$bumptransform"
"texturescrollrate" .3
"texturescrollangle" 60
}
}
}
</pre>
 
===Screen distortion overlay effect:===
<pre>
"Refract"
{
"%keywords" "<string>"
"%tooltexture" "<path> relative to <game abbr>/materials/"
"$refractamount" <value>
"$refracttint" "<RGB>" or "<HSV>"
"$refractblur" <bool>
"$bluramount" <0, 1, 2>
"$ignorez" <bool>
"$scale" "[1 1]"
"$bumpmap" "<path> relative to <game abbr>/materials/"
"$normalmap" "<path> relative to <game abbr>/materials/"
"$bumpframe" 0
"Proxies"
{
"AnimatedTexture"
{
"animatedtexturevar" "$normalmap"
"animatedtextureframenumvar" "$bumpframe"
"animatedtextureframerate" 30
}
"TextureScroll"
{
"texturescrollvar" "$bumptransform"
"texturescrollrate" .2
"texturescrollangle" 45
}
}
}
</pre>
 
==Fallback Materials==
Fallback materials are versions of existing materials that players will see if they are running older versions of DirectX. Fallback materials are invoked in the main material's VMT file, using a "fallback rule" and the <code>$fallbackmaterial</code> material parameter. Because of its complex nature, it is generally recommended to make a fallback material for custom water materials. The code for the fallback material is roughly the same as the main material file; however, instead of using a normal map, a flow map is used. It is invoked using the <code>$bumpmap</code> material parameter.
 
<pre>
"Water"
{
...
<dx90
{
"$fallbackmaterial" "<path> relative to <game abbr>/materials/"
}
}
</pre>
 
===The difference between bump maps and normal maps===
There is a lot of confusion in determining the difference between a normal map and a bump map, moreover the difference between <code>$bumpmap</code> and <code>$normalmap</code>. Although the terms "normal map" and "bump map" are often incorrectly used interchangeably, they are in fact, different things.
 
A '''normal map''' is actually a type of bump map. <code>$bumpmap</code> can be used to invoke a normal map in most cases; however, in cases like these where both <code>$normalmap</code> and <code>$bumpmap</code> are used, using the <code>$bumpmap</code> parameter too liberally will cause problems with your material. In this case, we used <code>$normalmap</code> to invoke the normal map, because <code>$bumpmap</code> is used to invoke a flow map in fallback materials. A flow map is just another type of bump map. For <code>LightmappedGeneric</code> textures, using either one will suffice. Think of the <code>$normalmap</code> parameter as just a more specific version of <code>$bumpmap.</code>
 
==See Also==
*[[Water]]
*[[Normal]] mapping

Latest revision as of 20:42, 7 November 2020