Refract: Difference between revisions
SirYodaJedi (talk | contribs) No edit summary |
SirYodaJedi (talk | contribs) |
||
Line 66: | Line 66: | ||
== See also == | == See also == | ||
* < | * <kbd>[[Water (shader)|Water]]</kbd> | ||
* <kbd>[[Predator]]</kbd> - an earlier (deprecated) version of Refract | |||
== External links == | |||
* [https://a248.e.akamai.net/f/248/10/10/http.developer.nvidia.com/GPUGems2/gpugems2_chapter19.html Article about similar shaders] | * [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 07:53, 18 April 2025

Refract
is a Pixel shader available in all Source games. It distorts objects behind it. It is similar to
Water
, but does not have real-time reflections and so is not restricted to flat surfaces. Can be used to create distorting glass windows, ice, 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.



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
$dudvmap
$normalmap2
$bumpframe
$bumptransform
$refracttint
$refracttinttexture
$refracttinttextureframe
$refractamount
$bluramount
$forcerefract
$envmap
$envmaptint
$envmapcontrast
$envmapsaturation
$fresnelreflection
$fadeoutonsilhouette
$vertexcolormodulate
$basetexture
$masked
$forcealphawrite
$nowritez
$noviewportfixup
$mirroraboutviewportedges
$magnifyenable
$magnifycenter
$magnifyscale
$localrefract
$localrefractdepth
$spitternoisetexture
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 normal map with an alpha channel, and define that as the first
$normalmap
. Using another normal of your choice you can then define a normal map 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 normal map can provide the alpha, and the second normal map can move along that alpha. - If
Refract
is used on a part of a model, you must specify$mostlyopaque
parameter to the qc of the model and$nowritez "1"
&$model "1"
to refract vmt. - This shader doesn't work properly with water dynamic reflections and sky_camera. Only for brushes, if a brush is world geometry or func_detail. This bug doesn't happen with ther secondary cameras (func_reflective_glass, func_monitor and portals).