Refract: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(added the fact that it must specify the $model command to use it effectivly on a model or it won't work)
(Added more shader parameters)
Line 3: Line 3:
[[File:Refract.jpg|thumb|250px|A refracting [[func_brush]].]]
[[File:Refract.jpg|thumb|250px|A refracting [[func_brush]].]]


The '''<code>Refract</code>''' shaders distorts objects behind it. It is similar to <code>[[Water (shader)|Water]]</code>, but does not reflect and so is not restricted to flat surfaces. Can be used to create distorting glass windows etc.
The '''<code>Refract</code>''' shaders distorts objects behind it. It is similar to <code>[[Water (shader)|Water]]</code>, but does not reflect and so is not restricted to flat surfaces. Can be used to create distorting glass windows etc.
 
The refraction effect is achieved by first rendering the view without the refracting surface, and then using the normal map to distort the image by replacing pixel coordinates with new ones from the pre-rendered view by projecting along the normals.


{{note|Will not work when applied to [[world brush]]es (including [[func_detail]]).}}
{{note|Will not work when applied to [[world brush]]es (including [[func_detail]]).}}
{{note|When being used on a model, you must specify [[$model|$model "1"]].}}
{{note|When being used on a model, you must specify [[$model|$model "1"]].}}
{{note|Multiple layers of the Refract shader will not render when applied on the same entity.}}


Keep in mind that refraction is expensive to render when sorted. Multiple layers of refraction can cause immense overdraw. Avoid having large amounts of particle sheets, or multiple surfaces with refract that render above each other.
Keep in mind that refraction is expensive to render when sorted. Multiple layers of refraction can cause immense overdraw. Avoid having large amounts of particle sheets, or multiple surfaces with refract that render above each other.
Line 22: Line 25:
; <code>[[$normalmap]] <[[string]]></code>
; <code>[[$normalmap]] <[[string]]></code>
; <code>[[$dudvmap]] <string></code>
; <code>[[$dudvmap]] <string></code>
: The pattern of refraction is defined by a bump map (DX9+) or DUDV map (DX8-). May be animated.
: The pattern of refraction is defined by a normal map (DX9+) or DUDV map (DX8-). May be animated.
; <code>$normalmap2 <string></code>
: If a second normal map is specified, it will be blended with the first one.
; <code>$refracttint <[[color]]></code>
; <code>$refracttint <[[color]]></code>
; <code>$refracttinttexture <string></code>
; <code>$refracttinttexture <string></code>
: Tints the colour of the refraction either uniformly or per-texel.
: Tints the colour of the refraction either uniformly or per-texel.
; <code>$refractamount <[[float]]></code>
; <code>$refractamount <[[float]]></code>
; <code>$bluramount <float></code>
: Controls the strength of the refraction by multiplying the normal map intensity.
: Strength of the effect. Use low values.
; <code>$bluramount <int></code>
; <code>$forcerefract</code>
: Adds a blur effect. Valid values are 0, 1 and 2 (0 and 1 for DX8-).
: {{confirm|Override for users running with low detail settings?}}
; <code>$forcerefract <bool></code>
: Forces the shader to be used for cards with poor fill rate (DX8 only).
; <code>$vertexcolormodulate</code>
; <code>$vertexcolormodulate</code>
: {{todo|See [[$vertexcolor]].}}
: {{todo|See [[$vertexcolor]].}}
; <code>$basetexture <string></code>
: Uses a texture instead of rendering the view for the source of the distorted pixels (DX9+ only).
; <code>$masked <bool></code>
: {{todo|''mask using dest alpha''}}
; <code>$forcealphawrite <bool></code>
: {{todo|''Force the material to write alpha to the dest buffer''}} (DX9+ only)
; <code>$fresnelreflection <float></code>
: '''Broken''' - Not implemented despite the parameter existing.


== Caveats ==
== Caveats ==
Line 41: Line 55:


* <code>[[Water (shader)|Water]]</code>
* <code>[[Water (shader)|Water]]</code>
* [https://a248.e.akamai.net/f/248/10/10/http.developer.nvidia.com/GPUGems2/gpugems2_chapter19.html Article about similar shaders]


[[Category:Shaders]]
[[Category:Shaders]]

Revision as of 10:40, 13 September 2015

Template:Otherlang2

A refracting func_brush.

The Refract shaders distorts objects behind it. It is similar to Water, but does not reflect and so is not restricted to flat surfaces. Can be used to create distorting glass windows etc.

The refraction effect is achieved by first rendering the view without the refracting surface, and then using the normal map to distort the image by replacing pixel coordinates with new ones from the pre-rendered view by projecting along the normals.

Note.pngNote:Will not work when applied to world brushes (including func_detail).
Note.pngNote:When being used on a model, you must specify $model "1".
Note.pngNote:Multiple layers of the Refract shader will not render when applied on the same entity.

Keep in mind that refraction is expensive to render when sorted. Multiple layers of refraction can cause immense overdraw. Avoid having large amounts of particle sheets, or multiple surfaces with refract that render above each other.

Syntax

Refract
{
	$normalmap ...
	$dudvmap ...
	$refracttint "[1 1 1]"
	$refractamount .2
}
$normalmap <string>
$dudvmap <string>
The pattern of refraction is defined by a normal map (DX9+) or DUDV map (DX8-). May be animated.
$normalmap2 <string>
If a second normal map is specified, it will be blended with the first one.
$refracttint <color>
$refracttinttexture <string>
Tints the colour of the refraction either uniformly or per-texel.
$refractamount <float>
Controls the strength of the refraction by multiplying the normal map intensity.
$bluramount <int>
Adds a blur effect. Valid values are 0, 1 and 2 (0 and 1 for DX8-).
$forcerefract <bool>
Forces the shader to be used for cards with poor fill rate (DX8 only).
$vertexcolormodulate
Todo: See $vertexcolor.
$basetexture <string>
Uses a texture instead of rendering the view for the source of the distorted pixels (DX9+ only).
$masked <bool>
Todo: mask using dest alpha
$forcealphawrite <bool>
Todo: Force the material to write alpha to the dest buffer
(DX9+ only)
$fresnelreflection <float>
Broken - Not implemented despite the parameter existing.

Caveats

  • Currently it is not possible to define an overall alpha mask to indicate where to fall-off refract. This however only applies to the brush based and model geometry, and not particles. To get alpha on brush or model based geometry you can create a normalmap with an alpha channel, and define that as the first $normalmap. Using another normal of your choice you can then define a normalmap for $normalmap2. $normalmap2 will inherit the alpha of the first normalmap, and will act accordingly. This is extremely useful for faking effects like scrolling water of a surface. Where the first normalmap can provide the alpha, and the second normalmap can move along that alpha.

See also