diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /materialsystem/stdshaders/rift_dx6.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'materialsystem/stdshaders/rift_dx6.cpp')
| -rw-r--r-- | materialsystem/stdshaders/rift_dx6.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/materialsystem/stdshaders/rift_dx6.cpp b/materialsystem/stdshaders/rift_dx6.cpp new file mode 100644 index 0000000..59ceab2 --- /dev/null +++ b/materialsystem/stdshaders/rift_dx6.cpp @@ -0,0 +1,112 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_SHADER( Rift_DX6, + "Help for Rift_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "second texture" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" ) + SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + if (params[TEXTURE2]->IsDefined()) + { + LoadTexture( TEXTURE2 ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + SetModulationShadowState(); + + // Either we've got a constant modulation + bool isTranslucent = IsAlphaModulating(); + + // Or we've got a texture alpha on either texture + isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) || + TextureIsTranslucent( TEXTURE2, true ); + + if ( isTranslucent ) + { + if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) ) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + } + else + { + if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) ) + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + } + + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 ); + DefaultFog(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // 1) Take a coordinate in camera space + // 2) Flip Y by multiplying by -1 + // 3) Transform from [-w,w] to [0,2*w] + // 4) Transform from [0,2*w] to [0,w] + // We'll end up dividing by w in the pixel shader to get to [0,1] + VMatrix matProjection, matYFlip, matHalf, matOffset, matBaseTransform; + s_pShaderAPI->GetMatrix( MATERIAL_PROJECTION, matProjection.m[0] ); + + MatrixTranspose( matProjection, matProjection ); + + MatrixBuildScale( matYFlip, 1.0f, -1.0f, 1.0f ); + MatrixBuildTranslation( matOffset, 1.0f, 1.0f, 0.0f ); + MatrixBuildScale( matHalf, 0.5f, 0.5f, 1.0f ); + + MatrixMultiply( matYFlip, matProjection, matBaseTransform ); + MatrixMultiply( matOffset, matBaseTransform, matBaseTransform ); + MatrixMultiply( matHalf, matBaseTransform, matBaseTransform ); + + // tranpose before going into the shaderapi. . . suck + MatrixTranspose( matBaseTransform, matBaseTransform ); + s_pShaderAPI->MatrixMode( MATERIAL_TEXTURE0 ); + s_pShaderAPI->LoadMatrix( &matBaseTransform[0][0] ); + + // NOTE: This *must* be set after LoadMatrix since LoadMatrix slams the texture dimension + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 3, true ); + + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, TEXTURE2TRANSFORM ); + + SetModulationDynamicState(); + } + Draw(); + } +END_SHADER |