Refract: Difference between revisions
Gaming chair (talk | contribs) mNo edit summary |
Deprecated (talk | contribs) (Revamped with MatParam templates, added new parameters) |
||
Line 3: | Line 3: | ||
[[File:Refract.jpg|thumb|250px|A refracting [[func_brush]].]] | [[File:Refract.jpg|thumb|250px|A refracting [[func_brush]].]] | ||
{{Shader|Refract}} It distorts objects behind it. It is similar to <code>[[Water (shader)|Water]]</code>, 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. | 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 in older engines.}} | {{note|Will not work when applied to [[world brush]]es in older engines.{{clarify}}}} | ||
{{note|When being used on a model, you must specify [[$model|$model "1"]].}} | {{note|When being used on a model, you must specify <code>[[$model|$model "1"]]</code>.}} | ||
{{note|Multiple layers of the Refract shader will not render when applied on the same entity.}} | {{note|Multiple layers of the <code>Refract</code> 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 23: | Line 23: | ||
} | } | ||
{{MatParam|$normalmap|texture}} | |||
{{MatParam|$dudvmap|texture|The pattern of refraction is defined by a normal map (DX9+) or DUDV map (DX8-). May be animated.|dx8=1}} | |||
{{MatParam|$normalmap2|texture|If a second normal map is specified, it will be blended with the first one.|since={{src07}}|dx9=1}} | |||
{{MatParam|$bumpframe|and=$bumpframe2|int|The frame to start an animated bump map on.}} | |||
{{MatParam|$bumptransform|and=$bumptransform2|vector3|Transforms the bump map texture. | |||
{{VMT UVtransform}}}} | |||
{{MatParam|$refracttint|RGB matrix}} | |||
{{MatParam|$refracttinttexture|texture|Tints the colour of the refraction either uniformly or per-texel.}} | |||
{{MatParam|$refracttinttextureframe|int|Frame to start an animated <code>$refracttinttexture</code> on.}} | |||
{{MatParam|$refractamount|float|Controls the strength of the refraction by multiplying the normal map intensity.}} | |||
{{MatParam|$bluramount|int|Adds a blur effect. Valid values are 0, 1 and 2 (0 and 1 for DX8-).}} | |||
{{MatParam|$forcerefract|bool|Forces the shader to be used for cards with poor fill rate.|dx8=1}} | |||
{{MatParam|[[$envmap]]|texture|Adds a cubemap reflection on top of the refraction.}} | |||
{{MatParam|$envmaptint|RGB matrix|Controls the intensity of the reflection's red, green and blue color channels. Any positive number can be used. Default is <code>"[1 1 1]"</code>, which means 100% intensity. | |||
: {{Note|You must use quotemarks, as there are space characters within the value.}}}} | |||
{{MatParam|$envmapcontrast|normal|Controls the [[Wikipedia:Contrast (vision)|contrast]] of the reflection. 0 is natural contrast, while 1 is the full squaring of the color (i.e. color*color).}} | |||
: {{Note|You must use quotemarks, as there are space characters within the value.}} | {{MatParam|$envmapsaturation|normal|Controls the colour saturation of the reflection. 0 is greyscale, while 1 is natural saturation.}} | ||
{{MatParam|$fresnelreflection|float|{{Bug|'''Broken''' - Not implemented for this shader despite the parameter existing.}}|since={{src06}}}} | |||
{{MatParam|$fadeoutonsilhouette|bool|Fades out the refraction effect around the edges.}} | |||
{{MatParam|$vertexcolormodulate||{{todo|Use the vertex color to affect the refract color. Alpha will adjust refract amount. See {{ent|$vertexcolor}}.}}|since={{src07}}|dx9=1}} | |||
{{MatParam|$basetexture|texture|Use a texture instead of rendering the view for the source of the distorted pixels.|dx9=1}} | |||
{{MatParam|$masked|bool|{{todo|''mask using dest alpha''}}}} | |||
{{MatParam|$forcealphawrite|bool|{{todo|''Force the material to write alpha to the dest buffer''}}|dx9=1|since={{src13}}}} | |||
{{MatParam|$nowritez|int|{{todo|''0 {{=}}{{=}} write z, 1 {{=}} no write z''}}}} | |||
{{MatParam|$noviewportfixup|int|Don't adjust UVs for current viewport.|since={{as}}}} | |||
{{MatParam|$mirroraboutviewportedges|int|Don't sample outside of the viewport.|since={{as}}}} | |||
{{MatParam|$magnifyenable|bool|Enable magnification of the refracted image around the <code>$magnifycenter</code> screen position by <code>$magnifyscale</code>.|since={{as}}}} | |||
{{MatParam|$magnifycenter|vector2|Magnify the refracted image around this screen position.|since={{as}}}} | |||
{{MatParam|$magnifyscale|float|Magnify the refracted image by this factor.|since={{as}}}} | |||
{{MatParam|$localrefract|bool|Use the alpha channel of the base texture to create a parallax effect.|since={{portal2}}}} | |||
{{MatParam|$localrefractdepth|float|Depth of the parallax effect in units.|since={{portal2}}}} | |||
== Caveats == | == 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 | * 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 <code>$normalmap</code>. Using another normal of your choice you can then define a normal map for <code>$normalmap2</code>. <code>$normalmap2</code> 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 <code>Refract</code> is used on a part of a model, the rest of the model will be rendered invisible when seen through the refractive part due to render sorting. Consider making the refractive part a separate model to remedy the issue. | |||
* If Refract is used on a part of a model, the rest of the model will be rendered invisible when seen through the refractive part. Consider making the refractive part a separate model to remedy the issue. | |||
== See also == | == See also == |
Revision as of 18:53, 28 August 2020

Refract
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.


$model "1"
.
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|$envmap]]
$envmaptint
$envmapcontrast
$envmapsaturation
$fresnelreflection
$fadeoutonsilhouette
$vertexcolormodulate
$basetexture
$masked
$forcealphawrite
$nowritez
$noviewportfixup
$mirroraboutviewportedges
$magnifyenable
$magnifycenter
$magnifyscale
$localrefract
$localrefractdepth
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, the rest of the model will be rendered invisible when seen through the refractive part due to render sorting. Consider making the refractive part a separate model to remedy the issue.