aboutsummaryrefslogtreecommitdiff
path: root/sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-12-23 14:58:45 -0800
committerJoe Ludwig <[email protected]>2013-12-23 15:00:03 -0800
commit7309a5f13f63fdcc7b1e090f6c176113a9d95061 (patch)
treead65c7fbe46a3c70bdc0a1426e88247ce1b0d7f5 /sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc
parentMerge pull request #182 from ardneran/master (diff)
downloadsource-sdk-2013-7309a5f13f63fdcc7b1e090f6c176113a9d95061.tar.xz
source-sdk-2013-7309a5f13f63fdcc7b1e090f6c176113a9d95061.zip
Added many shader source files
This should include the latest version of every shader that was in the 2007 SDK. It also includes a smattering of debug shaders, both VR distortion shaders, and other assorted shaders that will hopefully be useful. None of these new files are included in the game shader DLL project. If you need to modify one of these shaders for use in your mod you will need to rename it so that you don't collide with the version of that shader that lives in stdshader_dx9.dll.
Diffstat (limited to 'sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc')
-rw-r--r--sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc78
1 files changed, 78 insertions, 0 deletions
diff --git a/sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc b/sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc
new file mode 100644
index 00000000..331c1897
--- /dev/null
+++ b/sp/src/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc
@@ -0,0 +1,78 @@
+// DYNAMIC: "CMBO_HUDUNDISTORT" "0..1"
+
+#include "shader_constant_register_map.h"
+#include "common_ps_fxc.h"
+
+sampler BaseTextureSampler : register( s0 );
+sampler DistortMapTextureSampler : register( s1 );
+
+const float4 DistortBounds : register( c0 );
+const int bHudTranslucent : register( c1 );
+
+struct PS_INPUT
+{
+ float2 vBaseTexCoord : TEXCOORD0;
+};
+
+float4 main( PS_INPUT i ) : COLOR
+{
+ float2 vOriginal = i.vBaseTexCoord.xy;
+
+
+ // The full uv 0->1 range of the base texture here is shifted/scaled so that it maps
+ // to the region that would be minUV->maxUV of the base texture in the regular undistort
+ // code. This lets us overlay a higher-resolution inset rectangle directly onto the
+ // render target with undistort, which results in a much higher-quality HUD.
+
+ float2 minUV = DistortBounds.xy;
+ float2 maxUV = DistortBounds.zw;
+ float2 scaleUV = 1.0 / ( maxUV - minUV );
+
+
+ float2 vGreen;
+ float4 vFinal;
+
+ #if ( CMBO_HUDUNDISTORT )
+ {
+ float4 vRead = tex2D( DistortMapTextureSampler, vOriginal );
+
+ float2 vRed = vRead.xy;
+ float2 vBlue = vRead.zw;
+
+ vGreen = ( vRed + vBlue ) / 2.0;
+
+ vRed = ( vRed - minUV ) * scaleUV;
+ vGreen = ( vGreen - minUV ) * scaleUV;
+ vBlue = ( vBlue - minUV ) * scaleUV;
+
+ vFinal.r = tex2D( BaseTextureSampler, vRed ).r;
+ vFinal.ga = tex2D( BaseTextureSampler, vGreen ).ga;
+ vFinal.b = tex2D( BaseTextureSampler, vBlue ).b;
+ }
+ #else
+ {
+ vGreen = ( vOriginal - minUV ) * scaleUV;
+ vFinal = tex2D( BaseTextureSampler, vGreen );
+ }
+ #endif
+
+
+ // When the HUD isn't supposed to be rendered as translucent, some of its elements do occasionally have non-unit alpha.
+ // We always have blending and alphatest enabled here, so if the hud itself is not supposed to be translucent we need
+ // to fix up the alphas.
+ vFinal.a = lerp( 1, vFinal.a, bHudTranslucent );
+
+
+ // Smooth off the edges of the quad. This also gives (0,0,0,0) in the outer areas, for alpha test and for blackout.
+
+ const float edgeRampFrac = 0.005;
+ float2 uvEdgeRamp = smoothstep( float2(-edgeRampFrac,-edgeRampFrac), float2(edgeRampFrac,edgeRampFrac), vGreen ) *
+ ( 1 - smoothstep( float2(1-edgeRampFrac,1-edgeRampFrac), float2(1+edgeRampFrac,1+edgeRampFrac), vGreen ) );
+
+ float edgeRamp = uvEdgeRamp.x * uvEdgeRamp.y;
+
+ vFinal *= edgeRamp;
+
+
+ return vFinal;
+}