From 6f03d9f70774b064c9b7148b9db81c5b7b6b5344 Mon Sep 17 00:00:00 2001 From: Blixibon Date: Sun, 7 Nov 2021 08:56:45 -0600 Subject: [PATCH] Added WIP SDK_Sky shader with WIP texture blending (temp branch; do not merge directly) --- .../SDK_sky_hdr_compressed_ps2x.fxc | 88 ++++ .../SDK_sky_hdr_compressed_rgbs_ps2x.fxc | 141 ++++++ .../stdshaders/SDK_sky_ps2x.fxc | 70 +++ .../stdshaders/SDK_sky_vs20.fxc | 64 +++ .../stdshaders/game_shader_dx9_mapbase.vpc | 3 + sp/src/materialsystem/stdshaders/sky_dx9.cpp | 204 ++++++-- .../materialsystem/stdshaders/sky_hdr_dx9.cpp | 456 +++++++++++++++--- 7 files changed, 917 insertions(+), 109 deletions(-) create mode 100644 sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_ps2x.fxc create mode 100644 sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_rgbs_ps2x.fxc create mode 100644 sp/src/materialsystem/stdshaders/SDK_sky_ps2x.fxc create mode 100644 sp/src/materialsystem/stdshaders/SDK_sky_vs20.fxc diff --git a/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_ps2x.fxc b/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_ps2x.fxc new file mode 100644 index 00000000..167d3900 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_ps2x.fxc @@ -0,0 +1,88 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "USES_TEXTURE_BLENDS" "0..1" +// STATIC: "HAS_BLEND1" "0..1" +// STATIC: "HAS_BLEND2" "0..1" +// STATIC: "HAS_BLEND3" "0..1" +// STATIC: "HAS_BLEND4" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND1 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND2 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND3 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND4 ) + +#include "common_ps_fxc.h" + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +sampler ExposureTextureSampler0 : register( s0 ); +sampler ExposureTextureSampler1 : register( s1 ); +sampler ExposureTextureSampler2 : register( s2 ); + +#if USES_TEXTURE_BLENDS +const float4 g_TextureBlends : register( c1 ); +#endif + +#if HAS_BLEND2 +sampler ExposureTexture2Sampler0 : register( s3 ); +sampler ExposureTexture2Sampler1 : register( s4 ); +sampler ExposureTexture2Sampler2 : register( s5 ); +#endif +#if HAS_BLEND3 +sampler ExposureTexture3Sampler0 : register( s6 ); +sampler ExposureTexture3Sampler1 : register( s7 ); +sampler ExposureTexture3Sampler2 : register( s8 ); +#endif +#if HAS_BLEND4 +sampler ExposureTexture4Sampler0 : register( s9 ); +sampler ExposureTexture4Sampler1 : register( s10 ); +sampler ExposureTexture4Sampler2 : register( s11 ); +#endif + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ +#if USES_TEXTURE_BLENDS + HALF3 color0 = {0,0,0}; + HALF3 color1 = {0,0,0}; + HALF3 color2 = {0,0,0}; + +#if HAS_BLEND1 + color0 = lerp( color0, 0.25*tex2D( ExposureTextureSampler0, i.baseTexCoord ), g_TextureBlends[0] ); + color1 = lerp( color1, 2.0*tex2D( ExposureTextureSampler1, i.baseTexCoord ), g_TextureBlends[0] ); + color2 = lerp( color2, 16.0*tex2D( ExposureTextureSampler2, i.baseTexCoord ), g_TextureBlends[0] ); +#endif +#if HAS_BLEND2 + color0 = lerp( color0, 0.25*tex2D( ExposureTexture2Sampler0, i.baseTexCoord ), g_TextureBlends[1] ); + color1 = lerp( color1, 2.0*tex2D( ExposureTexture2Sampler1, i.baseTexCoord ), g_TextureBlends[1] ); + color2 = lerp( color2, 16.0*tex2D( ExposureTexture2Sampler2, i.baseTexCoord ), g_TextureBlends[1] ); +#endif +#if HAS_BLEND3 + color0 = lerp( color0, 0.25*tex2D( ExposureTexture3Sampler0, i.baseTexCoord ), g_TextureBlends[2] ); + color1 = lerp( color1, 2.0*tex2D( ExposureTexture3Sampler1, i.baseTexCoord ), g_TextureBlends[2] ); + color2 = lerp( color2, 16.0*tex2D( ExposureTexture3Sampler2, i.baseTexCoord ), g_TextureBlends[2] ); +#endif +#if HAS_BLEND4 + color0 = lerp( color0, 0.25*tex2D( ExposureTexture4Sampler0, i.baseTexCoord ), g_TextureBlends[3] ); + color1 = lerp( color1, 2.0*tex2D( ExposureTexture4Sampler1, i.baseTexCoord ), g_TextureBlends[3] ); + color2 = lerp( color2, 16.0*tex2D( ExposureTexture4Sampler2, i.baseTexCoord ), g_TextureBlends[3] ); +#endif + +#else + HALF3 color0 = 0.25*tex2D( ExposureTextureSampler0, i.baseTexCoord ); + HALF3 color1 = 2.0*tex2D( ExposureTextureSampler1, i.baseTexCoord ); + HALF3 color2 = 16.0*tex2D( ExposureTextureSampler2, i.baseTexCoord ); +#endif + + // This is never fogged. +// return FinalOutput( float4( max(max(color0,color1),color2), 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, WRITE_DEPTH_TO_DESTALPHA, 1e20 ); //when writing depth to dest alpha, write a value guaranteed to saturate + return FinalOutput( float4(1,0,0,1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, WRITE_DEPTH_TO_DESTALPHA, 1e20 ); //when writing depth to dest alpha, write a value guaranteed to saturate +} diff --git a/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_rgbs_ps2x.fxc b/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_rgbs_ps2x.fxc new file mode 100644 index 00000000..fbe69d33 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/SDK_sky_hdr_compressed_rgbs_ps2x.fxc @@ -0,0 +1,141 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "USES_TEXTURE_BLENDS" "0..1" +// STATIC: "HAS_BLEND1" "0..1" +// STATIC: "HAS_BLEND2" "0..1" +// STATIC: "HAS_BLEND3" "0..1" +// STATIC: "HAS_BLEND4" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND1 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND2 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND3 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND4 ) + +#include "common_ps_fxc.h" + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +sampler RGBSTextureSampler : register( s0 ); +HALF4 InputScale : register( c0 ); + +#if USES_TEXTURE_BLENDS +const float4 g_TextureBlends : register( c1 ); +#endif + +#if HAS_BLEND2 +sampler RGBSTexture2Sampler : register( s1 ); +#endif +#if HAS_BLEND3 +sampler RGBSTexture3Sampler : register( s2 ); +#endif +#if HAS_BLEND4 +sampler RGBSTexture4Sampler : register( s3 ); +#endif + +float2 texWidthHeight : register( c1 ); + +float4 texOffsets : register( c2 ); + +struct PS_INPUT +{ +//#if defined( _X360 ) +// float2 baseTexCoord : TEXCOORD0; +//#else + float2 baseTexCoord00 : TEXCOORD0; + float2 baseTexCoord01 : TEXCOORD1; + float2 baseTexCoord10 : TEXCOORD2; + float2 baseTexCoord11 : TEXCOORD3; + float2 baseTexCoord_In_Pixels: TEXCOORD4; +//#endif +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 result; + +//#if defined( _X360 ) //360 has a cheaper way to handle RGBscale +// float4 Weights; +// float4 samples_0; //no arrays allowed in inline assembly +// float4 samples_1; +// float4 samples_2; +// float4 samples_3; +// float2 vTexCoord = i.baseTexCoord; +// +// asm { +// tfetch2D samples_0, vTexCoord.xy, RGBSTextureSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false +// tfetch2D samples_1, vTexCoord.xy, RGBSTextureSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false +// tfetch2D samples_2, vTexCoord.xy, RGBSTextureSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false +// tfetch2D samples_3, vTexCoord.xy, RGBSTextureSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false +// +// getWeights2D Weights, vTexCoord.xy, RGBSTextureSampler +// }; +// +// Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y ); +// +// result.rgb = samples_0.rgb * (samples_0.a * Weights.x); +// result.rgb += samples_1.rgb * (samples_1.a * Weights.y); +// result.rgb += samples_2.rgb * (samples_2.a * Weights.z); +// result.rgb += samples_3.rgb * (samples_3.a * Weights.w); +// +//#else + +#if USES_TEXTURE_BLENDS + float4 s00 = {0,0,0,0}; + float4 s10 = {0,0,0,0}; + float4 s01 = {0,0,0,0}; + float4 s11 = {0,0,0,0}; + +#if HAS_BLEND1 + s00 = lerp( s00, tex2D( RGBSTextureSampler, i.baseTexCoord00 ), g_TextureBlends[0] ); + s10 = lerp( s10, tex2D( RGBSTextureSampler, i.baseTexCoord10 ), g_TextureBlends[0] ); + s01 = lerp( s01, tex2D( RGBSTextureSampler, i.baseTexCoord01 ), g_TextureBlends[0] ); + s11 = lerp( s11, tex2D( RGBSTextureSampler, i.baseTexCoord11 ), g_TextureBlends[0] ); +#endif +#if HAS_BLEND2 + s00 = lerp( s00, tex2D( RGBSTexture2Sampler, i.baseTexCoord00 ), g_TextureBlends[1] ); + s10 = lerp( s10, tex2D( RGBSTexture2Sampler, i.baseTexCoord10 ), g_TextureBlends[1] ); + s01 = lerp( s01, tex2D( RGBSTexture2Sampler, i.baseTexCoord01 ), g_TextureBlends[1] ); + s11 = lerp( s11, tex2D( RGBSTexture2Sampler, i.baseTexCoord11 ), g_TextureBlends[1] ); +#endif +#if HAS_BLEND3 + s00 = lerp( s00, tex2D( RGBSTexture3Sampler, i.baseTexCoord00 ), g_TextureBlends[2] ); + s10 = lerp( s10, tex2D( RGBSTexture3Sampler, i.baseTexCoord10 ), g_TextureBlends[2] ); + s01 = lerp( s01, tex2D( RGBSTexture3Sampler, i.baseTexCoord01 ), g_TextureBlends[2] ); + s11 = lerp( s11, tex2D( RGBSTexture3Sampler, i.baseTexCoord11 ), g_TextureBlends[2] ); +#endif +#if HAS_BLEND4 + s00 = lerp( s00, tex2D( RGBSTexture4Sampler, i.baseTexCoord00 ), g_TextureBlends[3] ); + s10 = lerp( s10, tex2D( RGBSTexture4Sampler, i.baseTexCoord10 ), g_TextureBlends[3] ); + s01 = lerp( s01, tex2D( RGBSTexture4Sampler, i.baseTexCoord01 ), g_TextureBlends[3] ); + s11 = lerp( s11, tex2D( RGBSTexture4Sampler, i.baseTexCoord11 ), g_TextureBlends[3] ); +#endif + +#else + float4 s00 = tex2D(RGBSTextureSampler, i.baseTexCoord00); + float4 s10 = tex2D(RGBSTextureSampler, i.baseTexCoord10); + float4 s01 = tex2D(RGBSTextureSampler, i.baseTexCoord01); + float4 s11 = tex2D(RGBSTextureSampler, i.baseTexCoord11); +#endif + + float2 fracCoord = frac(i.baseTexCoord_In_Pixels); + + s00.rgb*=s00.a; + s10.rgb*=s10.a; + + s00.xyz = lerp(s00, s10, fracCoord.x); + + s01.rgb*=s01.a; + s11.rgb*=s11.a; + s01.xyz = lerp(s01, s11, fracCoord.x); + + result = lerp(s00, s01, fracCoord.y); + +//#endif + + // This is never fogged. + return FinalOutput( float4( InputScale*result, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, WRITE_DEPTH_TO_DESTALPHA, 1e20 ); //when writing depth to dest alpha, write a value guaranteed to saturate +} diff --git a/sp/src/materialsystem/stdshaders/SDK_sky_ps2x.fxc b/sp/src/materialsystem/stdshaders/SDK_sky_ps2x.fxc new file mode 100644 index 00000000..15673fbe --- /dev/null +++ b/sp/src/materialsystem/stdshaders/SDK_sky_ps2x.fxc @@ -0,0 +1,70 @@ +// HDRFIXME: Make this work with nonHDR +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "USES_TEXTURE_BLENDS" "0..1" +// STATIC: "HAS_BLEND1" "0..1" +// STATIC: "HAS_BLEND2" "0..1" +// STATIC: "HAS_BLEND3" "0..1" +// STATIC: "HAS_BLEND4" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND1 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND2 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND3 ) +// SKIP: ( !$USES_TEXTURE_BLENDS ) && ( $HAS_BLEND4 ) + +#include "common_ps_fxc.h" + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +sampler BaseTextureSampler : register( s0 ); +HALF4 InputScale : register( c0 ); + +#if USES_TEXTURE_BLENDS +const float4 g_TextureBlends : register( c1 ); +#endif + +#if HAS_BLEND2 +sampler BaseTexture2Sampler : register( s1 ); +#endif +#if HAS_BLEND3 +sampler BaseTexture3Sampler : register( s2 ); +#endif +#if HAS_BLEND4 +sampler BaseTexture4Sampler : register( s3 ); +#endif + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ +#if USES_TEXTURE_BLENDS + HALF4 color = {0,0,0,0}; + +#if HAS_BLEND1 + color = lerp( color, tex2D( BaseTextureSampler, i.baseTexCoord.xy ), g_TextureBlends[0] ); +#endif +#if HAS_BLEND2 + color = lerp( color, tex2D( BaseTexture2Sampler, i.baseTexCoord.xy ), g_TextureBlends[1] ); +#endif +#if HAS_BLEND3 + color = lerp( color, tex2D( BaseTexture3Sampler, i.baseTexCoord.xy ), g_TextureBlends[2] ); +#endif +#if HAS_BLEND4 + color = lerp( color, tex2D( BaseTexture4Sampler, i.baseTexCoord.xy ), g_TextureBlends[3] ); +#endif + +#else + HALF4 color = tex2D( BaseTextureSampler, i.baseTexCoord.xy ); +#endif + color.rgb *= InputScale.rgb; + + // This is never fogged. + return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, WRITE_DEPTH_TO_DESTALPHA, 1e20 ); //when writing depth to dest alpha, write a value guaranteed to saturate +} diff --git a/sp/src/materialsystem/stdshaders/SDK_sky_vs20.fxc b/sp/src/materialsystem/stdshaders/SDK_sky_vs20.fxc new file mode 100644 index 00000000..1bc2a3e6 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/SDK_sky_vs20.fxc @@ -0,0 +1,64 @@ +#include "common_vs_fxc.h" + +const float4 g_vTextureSizeInfo : register( SHADER_SPECIFIC_CONST_0 ); +const float4 g_mBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + //SHADER_SPECIFIC_CONST_2 + +#define TEXEL_XINCR (g_vTextureSizeInfo.x) +#define TEXEL_YINCR (g_vTextureSizeInfo.y) +#define U_TO_PIXEL_COORD_SCALE (g_vTextureSizeInfo.z) +#define V_TO_PIXEL_COORD_SCALE (g_vTextureSizeInfo.w) + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + +//#if defined( _X360 ) +// float2 baseTexCoord : TEXCOORD0; +//#else + float2 baseTexCoord00 : TEXCOORD0; + float2 baseTexCoord01 : TEXCOORD1; + float2 baseTexCoord10 : TEXCOORD2; + float2 baseTexCoord11 : TEXCOORD3; + float2 baseTexCoord_In_Pixels: TEXCOORD4; +//#endif +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = mul( v.vPos, cModelViewProj ); + + float4 vTexCoordInput = { v.vTexCoord0.x, v.vTexCoord0.y, 0.0f, 1.0f }; + float2 vTexCoord; + vTexCoord.x = dot( vTexCoordInput.xyzw, g_mBaseTexCoordTransform[0] ); + vTexCoord.y = dot( vTexCoordInput.xyzw, g_mBaseTexCoordTransform[1] ); + +//#if defined( _X360 ) +// o.baseTexCoord.xy = vTexCoord.xy; +//#else + // Compute quantities needed for pixel shader texture lerping + o.baseTexCoord00.x = vTexCoord.x - TEXEL_XINCR; + o.baseTexCoord00.y = vTexCoord.y - TEXEL_YINCR; + o.baseTexCoord10.x = vTexCoord.x + TEXEL_XINCR; + o.baseTexCoord10.y = vTexCoord.y - TEXEL_YINCR; + + o.baseTexCoord01.x = vTexCoord.x - TEXEL_XINCR; + o.baseTexCoord01.y = vTexCoord.y + TEXEL_YINCR; + o.baseTexCoord11.x = vTexCoord.x + TEXEL_XINCR; + o.baseTexCoord11.y = vTexCoord.y + TEXEL_YINCR; + + o.baseTexCoord_In_Pixels.xy = o.baseTexCoord00.xy; + o.baseTexCoord_In_Pixels.x *= U_TO_PIXEL_COORD_SCALE; + o.baseTexCoord_In_Pixels.y *= V_TO_PIXEL_COORD_SCALE; +//#endif + + return o; +} diff --git a/sp/src/materialsystem/stdshaders/game_shader_dx9_mapbase.vpc b/sp/src/materialsystem/stdshaders/game_shader_dx9_mapbase.vpc index d6a8480d..ec981888 100644 --- a/sp/src/materialsystem/stdshaders/game_shader_dx9_mapbase.vpc +++ b/sp/src/materialsystem/stdshaders/game_shader_dx9_mapbase.vpc @@ -66,6 +66,9 @@ $Project $File "depthoffield_dx9.cpp" $File "core_dx9.cpp" + + $File "sky_dx9.cpp" + $File "sky_hdr_dx9.cpp" } //$Shaders "mapbase_dx9_20b.txt" diff --git a/sp/src/materialsystem/stdshaders/sky_dx9.cpp b/sp/src/materialsystem/stdshaders/sky_dx9.cpp index 93eb6115..38100c1e 100644 --- a/sp/src/materialsystem/stdshaders/sky_dx9.cpp +++ b/sp/src/materialsystem/stdshaders/sky_dx9.cpp @@ -6,17 +6,34 @@ // $NoKeywords: $ //=============================================================================// #include "BaseVSShader.h" -#include "sky_vs20.inc" -#include "sky_ps20.inc" -#include "sky_ps20b.inc" +#include "SDK_sky_vs20.inc" +#include "SDK_sky_ps20.inc" +#include "SDK_sky_ps20b.inc" #include "convar.h" -BEGIN_VS_SHADER( Sky_DX9, "Help for Sky_DX9 shader" ) +BEGIN_VS_SHADER( SDK_Sky_DX9, "Help for SDK_Sky_DX9 shader" ) BEGIN_SHADER_PARAMS SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_VEC3, "[ 1 1 1]", "color multiplier", SHADER_PARAM_NOT_EDITABLE ) SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + +#ifdef MAPBASE + SHADER_PARAM( USE_TEXTURE_BLENDS, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( BLEND1, SHADER_PARAM_TYPE_FLOAT, "1.0", "How much to blend $basetexture" ) + + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "A second sky base texture" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture2" ) + SHADER_PARAM( BLEND2, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture2" ) + + SHADER_PARAM( BASETEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "A third sky base texture" ) + SHADER_PARAM( FRAME3, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture3" ) + SHADER_PARAM( BLEND3, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture3" ) + + SHADER_PARAM( BASETEXTURE4, SHADER_PARAM_TYPE_TEXTURE, "", "A fourth sky base texture" ) + SHADER_PARAM( FRAME4, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture4" ) + SHADER_PARAM( BLEND4, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture4" ) +#endif END_SHADER_PARAMS SHADER_FALLBACK @@ -28,10 +45,36 @@ BEGIN_VS_SHADER( Sky_DX9, "Help for Sky_DX9 shader" ) return 0; } + inline void CheckSkySGRB( IShaderShadow* pShaderShadow, ITexture *txtr, Sampler_t iSampler ) + { + ImageFormat fmt = txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead( iSampler, false ); + else + pShaderShadow->EnableSRGBRead( iSampler, true ); + } + + inline void BlendSkyRGBA( float &flMult, float flBlend, ITexture *txtr ) + { + ImageFormat fmt = txtr->GetImageFormat(); + if ((fmt == IMAGE_FORMAT_RGBA16161616) || ((fmt == IMAGE_FORMAT_RGBA16161616F) && (g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER))) + { + flMult = Lerp( flBlend, flMult, 16.0f ); + } + else + { + flMult = Lerp( 1.0f - flBlend, 0.0f, flMult ); + } + } + SHADER_INIT_PARAMS() { SET_FLAGS( MATERIAL_VAR_NOFOG ); SET_FLAGS( MATERIAL_VAR_IGNOREZ ); + +#ifdef MAPBASE + InitFloatParam( BLEND1, params, 1.0f ); +#endif } SHADER_INIT { @@ -40,6 +83,23 @@ BEGIN_VS_SHADER( Sky_DX9, "Help for Sky_DX9 shader" ) ImageFormat fmt = params[BASETEXTURE]->GetTextureValue()->GetImageFormat(); LoadTexture( BASETEXTURE, (fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616) ? 0 : TEXTUREFLAGS_SRGB ); } +#ifdef MAPBASE + if (params[BASETEXTURE2]->IsDefined()) + { + ImageFormat fmt = params[BASETEXTURE2]->GetTextureValue()->GetImageFormat(); + LoadTexture( BASETEXTURE2, (fmt == IMAGE_FORMAT_RGBA16161616F) || (fmt == IMAGE_FORMAT_RGBA16161616) ? 0 : TEXTUREFLAGS_SRGB ); + } + if (params[BASETEXTURE3]->IsDefined()) + { + ImageFormat fmt = params[BASETEXTURE3]->GetTextureValue()->GetImageFormat(); + LoadTexture( BASETEXTURE3, (fmt == IMAGE_FORMAT_RGBA16161616F) || (fmt == IMAGE_FORMAT_RGBA16161616) ? 0 : TEXTUREFLAGS_SRGB ); + } + if (params[BASETEXTURE4]->IsDefined()) + { + ImageFormat fmt = params[BASETEXTURE4]->GetTextureValue()->GetImageFormat(); + LoadTexture( BASETEXTURE4, (fmt == IMAGE_FORMAT_RGBA16161616F) || (fmt == IMAGE_FORMAT_RGBA16161616) ? 0 : TEXTUREFLAGS_SRGB ); + } +#endif } SHADER_DRAW { @@ -49,27 +109,67 @@ BEGIN_VS_SHADER( Sky_DX9, "Help for Sky_DX9 shader" ) // pShaderShadow->EnableAlphaWrites( true ); pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); - ITexture *txtr=params[BASETEXTURE]->GetTextureValue(); - ImageFormat fmt=txtr->GetImageFormat(); - if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) - pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false); - else - pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,true); + CheckSkySGRB( pShaderShadow, params[BASETEXTURE]->GetTextureValue(), SHADER_SAMPLER0 ); + +#ifdef MAPBASE + bool bUsesBlends = params[USE_TEXTURE_BLENDS]->GetIntValue() > 0; + bool bShouldBlend[4] = { true, false, false, false }; + if (bUsesBlends) + { + //bShouldBlend[0] = (params[BLEND1]->GetFloatValue() > 0.0f); + + if (params[BASETEXTURE2]->IsDefined()) + { + //bShouldBlend[1] = (params[BLEND2]->GetFloatValue() > 0.0f); + bShouldBlend[1] = true; + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + CheckSkySGRB( pShaderShadow, params[BASETEXTURE2]->GetTextureValue(), SHADER_SAMPLER1 ); + } + if (params[BASETEXTURE3]->IsDefined()) + { + //bShouldBlend[2] = (params[BLEND3]->GetFloatValue() > 0.0f); + bShouldBlend[2] = true; + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + CheckSkySGRB( pShaderShadow, params[BASETEXTURE3]->GetTextureValue(), SHADER_SAMPLER2 ); + } + if (params[BASETEXTURE4]->IsDefined()) + { + //bShouldBlend[3] = (params[BLEND4]->GetFloatValue() > 0.0f); + bShouldBlend[3] = true; + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + CheckSkySGRB( pShaderShadow, params[BASETEXTURE4]->GetTextureValue(), SHADER_SAMPLER3 ); + } + } +#endif pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, NULL, 0 ); - DECLARE_STATIC_VERTEX_SHADER( sky_vs20 ); - SET_STATIC_VERTEX_SHADER( sky_vs20 ); + DECLARE_STATIC_VERTEX_SHADER( sdk_sky_vs20 ); + SET_STATIC_VERTEX_SHADER( sdk_sky_vs20 ); if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_STATIC_PIXEL_SHADER( sky_ps20b ); - SET_STATIC_PIXEL_SHADER( sky_ps20b ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_ps20b ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_ps20b ); } else { - DECLARE_STATIC_PIXEL_SHADER( sky_ps20 ); - SET_STATIC_PIXEL_SHADER( sky_ps20 ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_ps20 ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_ps20 ); } // we are writing linear values from this shader. pShaderShadow->EnableSRGBWrite( true ); @@ -88,35 +188,75 @@ BEGIN_VS_SHADER( Sky_DX9, "Help for Sky_DX9 shader" ) { memcpy(c0,params[COLOR]->GetVecValue(),3*sizeof(float)); } - ITexture *txtr=params[BASETEXTURE]->GetTextureValue(); - ImageFormat fmt=txtr->GetImageFormat(); - if ( - (fmt==IMAGE_FORMAT_RGBA16161616) || - ( (fmt==IMAGE_FORMAT_RGBA16161616F) && - (g_pHardwareConfig->GetHDRType()==HDR_TYPE_INTEGER)) - ) + +#ifdef MAPBASE + if (params[USE_TEXTURE_BLENDS]->GetIntValue()) { - c0[0]*=16.0; - c0[1]*=16.0; - c0[2]*=16.0; + float flBlends[4] = { params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 1, flBlends, 1 ); + + float flMult = 0.0f; + if (flBlends[0] > 0.0f) + { + BlendSkyRGBA( flMult, flBlends[0], params[BASETEXTURE]->GetTextureValue() ); + } + + if (flBlends[1] > 0.0f) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE2, FRAME2 ); + BlendSkyRGBA( flMult, flBlends[1], params[BASETEXTURE2]->GetTextureValue() ); + } + + if (flBlends[2] > 0.0f) + { + BindTexture( SHADER_SAMPLER2, BASETEXTURE3, FRAME3 ); + BlendSkyRGBA( flMult, flBlends[2], params[BASETEXTURE3]->GetTextureValue() ); + } + + if (flBlends[3] > 0.0f) + { + BindTexture( SHADER_SAMPLER3, BASETEXTURE4, FRAME4 ); + BlendSkyRGBA( flMult, flBlends[3], params[BASETEXTURE4]->GetTextureValue() ); + } + + c0[0] *= flMult; + c0[1] *= flMult; + c0[2] *= flMult; + } + else +#endif + { + ITexture *txtr=params[BASETEXTURE]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ( + (fmt==IMAGE_FORMAT_RGBA16161616) || + ( (fmt==IMAGE_FORMAT_RGBA16161616F) && + (g_pHardwareConfig->GetHDRType()==HDR_TYPE_INTEGER)) + ) + { + c0[0]*=16.0; + c0[1]*=16.0; + c0[2]*=16.0; + } } pShaderAPI->SetPixelShaderConstant(0,c0,1); - DECLARE_DYNAMIC_VERTEX_SHADER( sky_vs20 ); - SET_DYNAMIC_VERTEX_SHADER( sky_vs20 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( sdk_sky_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( sdk_sky_vs20 ); // Texture coord transform SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BASETEXTURETRANSFORM ); if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); - SET_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20b ); } else { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20 ); - SET_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20 ); } } Draw( ); diff --git a/sp/src/materialsystem/stdshaders/sky_hdr_dx9.cpp b/sp/src/materialsystem/stdshaders/sky_hdr_dx9.cpp index 285879c0..9aacd129 100644 --- a/sp/src/materialsystem/stdshaders/sky_hdr_dx9.cpp +++ b/sp/src/materialsystem/stdshaders/sky_hdr_dx9.cpp @@ -6,21 +6,21 @@ // $NoKeywords: $ //=============================================================================// #include "BaseVSShader.h" -#include "sky_vs20.inc" -#include "sky_ps20.inc" -#include "sky_ps20b.inc" -#include "sky_hdr_compressed_ps20.inc" -#include "sky_hdr_compressed_ps20b.inc" -#include "sky_hdr_compressed_rgbs_ps20.inc" -#include "sky_hdr_compressed_rgbs_ps20b.inc" +#include "SDK_sky_vs20.inc" +#include "SDK_sky_ps20.inc" +#include "SDK_sky_ps20b.inc" +#include "SDK_sky_hdr_compressed_ps20.inc" +#include "SDK_sky_hdr_compressed_ps20b.inc" +#include "SDK_sky_hdr_compressed_rgbs_ps20.inc" +#include "SDK_sky_hdr_compressed_rgbs_ps20b.inc" #include "convar.h" static ConVar mat_use_compressed_hdr_textures( "mat_use_compressed_hdr_textures", "1" ); -DEFINE_FALLBACK_SHADER( Sky, Sky_HDR_DX9 ) +DEFINE_FALLBACK_SHADER( SDK_Sky, SDK_Sky_HDR_DX9 ) -BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) +BEGIN_VS_SHADER( SDK_Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) BEGIN_SHADER_PARAMS SHADER_PARAM( HDRBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "base texture when running with HDR enabled" ) SHADER_PARAM( HDRCOMPRESSEDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "base texture (compressed) for hdr compression method A" ) @@ -28,13 +28,42 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) SHADER_PARAM( HDRCOMPRESSEDTEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "compressed base texture1 for hdr compression method B" ) SHADER_PARAM( HDRCOMPRESSEDTEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "compressed base texture2 for hdr compression method B" ) SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_VEC3, "[ 1 1 1]", "color multiplier", SHADER_PARAM_NOT_EDITABLE ) + +#ifdef MAPBASE + SHADER_PARAM( USE_TEXTURE_BLENDS, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( BLEND1, SHADER_PARAM_TYPE_FLOAT, "1.0", "How much to blend $basetexture" ) + + SHADER_PARAM( HDRBASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "A second HDR sky base texture" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE_2, SHADER_PARAM_TYPE_TEXTURE, "", "second base texture (compressed) for hdr compression method A" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE0_2, SHADER_PARAM_TYPE_TEXTURE, "", "second compressed base texture0 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE1_2, SHADER_PARAM_TYPE_TEXTURE, "", "second compressed base texture1 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE2_2, SHADER_PARAM_TYPE_TEXTURE, "", "second compressed base texture2 for hdr compression method B" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture2" ) + SHADER_PARAM( BLEND2, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture2" ) + + SHADER_PARAM( HDRBASETEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "A third HDR sky base texture" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE_3, SHADER_PARAM_TYPE_TEXTURE, "", "third base texture (compressed) for hdr compression method A" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE0_3, SHADER_PARAM_TYPE_TEXTURE, "", "third compressed base texture0 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE1_3, SHADER_PARAM_TYPE_TEXTURE, "", "third compressed base texture1 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE2_3, SHADER_PARAM_TYPE_TEXTURE, "", "third compressed base texture2 for hdr compression method B" ) + SHADER_PARAM( FRAME3, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture3" ) + SHADER_PARAM( BLEND3, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture3" ) + + SHADER_PARAM( HDRBASETEXTURE4, SHADER_PARAM_TYPE_TEXTURE, "", "A fourth HDR sky base texture" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE_4, SHADER_PARAM_TYPE_TEXTURE, "", "fourth base texture (compressed) for hdr compression method A" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE0_4, SHADER_PARAM_TYPE_TEXTURE, "", "fourth compressed base texture0 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE1_4, SHADER_PARAM_TYPE_TEXTURE, "", "fourth compressed base texture1 for hdr compression method B" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE2_4, SHADER_PARAM_TYPE_TEXTURE, "", "fourth compressed base texture2 for hdr compression method B" ) + SHADER_PARAM( FRAME4, SHADER_PARAM_TYPE_INTEGER, "", "frame number for $basetexture4" ) + SHADER_PARAM( BLEND4, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much to blend $basetexture4" ) +#endif END_SHADER_PARAMS SHADER_FALLBACK { if( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) { - return "Sky_DX9"; + return "SDK_Sky_DX9"; } return 0; } @@ -43,18 +72,23 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) { SET_FLAGS( MATERIAL_VAR_NOFOG ); SET_FLAGS( MATERIAL_VAR_IGNOREZ ); + +#ifdef MAPBASE + InitFloatParam( BLEND1, params, 1.0f ); +#endif } - SHADER_INIT + + void LoadSkyTexture( IMaterialVar **params, int iHDRBaseTexture, int iHDRCompressedTexture, int iHDRCompressedTexture0, int iHDRCompressedTexture1, int iHDRCompressedTexture2 ) { // First figure out if sampler zero wants to be sRGB int nSamplerZeroFlags = 0; - if ( (params[HDRCOMPRESSEDTEXTURE]->IsDefined()) && mat_use_compressed_hdr_textures.GetBool() ) + if ( (params[iHDRCompressedTexture]->IsDefined()) && mat_use_compressed_hdr_textures.GetBool() ) { nSamplerZeroFlags = 0; } else { - if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined()) + if (params[iHDRCompressedTexture0]->IsDefined()) { nSamplerZeroFlags = 0; } @@ -62,9 +96,9 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) { nSamplerZeroFlags = TEXTUREFLAGS_SRGB; - if ( params[HDRBASETEXTURE]->IsDefined() && params[HDRBASETEXTURE]->IsTexture() ) + if ( params[iHDRBaseTexture]->IsDefined() && params[iHDRBaseTexture]->IsTexture() ) { - ITexture *txtr=params[HDRBASETEXTURE]->GetTextureValue(); + ITexture *txtr=params[iHDRBaseTexture]->GetTextureValue(); ImageFormat fmt=txtr->GetImageFormat(); if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) { @@ -75,51 +109,87 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) } // Next, figure out which texture will be on sampler zero - int nSampler0 = HDRCOMPRESSEDTEXTURE; - if ( params[HDRCOMPRESSEDTEXTURE]->IsDefined() && mat_use_compressed_hdr_textures.GetBool() ) + int nSampler0 = iHDRCompressedTexture; + if ( params[iHDRCompressedTexture]->IsDefined() && mat_use_compressed_hdr_textures.GetBool() ) { - nSampler0 = HDRCOMPRESSEDTEXTURE; + nSampler0 = iHDRCompressedTexture; } else { - if ( params[HDRCOMPRESSEDTEXTURE0]->IsDefined() ) + if ( params[iHDRCompressedTexture0]->IsDefined() ) { - nSampler0 = HDRCOMPRESSEDTEXTURE0; + nSampler0 = iHDRCompressedTexture0; } else { - nSampler0 = HDRBASETEXTURE; + nSampler0 = iHDRBaseTexture; } } // Load the appropriate textures, making sure that the texture set on sampler 0 is sRGB if necessary - if ( params[HDRCOMPRESSEDTEXTURE]->IsDefined() && (mat_use_compressed_hdr_textures.GetBool() ) ) + if ( params[iHDRCompressedTexture]->IsDefined() && (mat_use_compressed_hdr_textures.GetBool() ) ) { - LoadTexture( HDRCOMPRESSEDTEXTURE, HDRCOMPRESSEDTEXTURE == nSampler0 ? nSamplerZeroFlags : 0 ); + LoadTexture( iHDRCompressedTexture, iHDRCompressedTexture == nSampler0 ? nSamplerZeroFlags : 0 ); } else { - if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined()) + if (params[iHDRCompressedTexture0]->IsDefined()) { - LoadTexture( HDRCOMPRESSEDTEXTURE0, HDRCOMPRESSEDTEXTURE0 == nSampler0 ? nSamplerZeroFlags : 0 ); - if ( params[HDRCOMPRESSEDTEXTURE1]->IsDefined() ) + LoadTexture( iHDRCompressedTexture0, iHDRCompressedTexture0 == nSampler0 ? nSamplerZeroFlags : 0 ); + if ( params[iHDRCompressedTexture1]->IsDefined() ) { - LoadTexture( HDRCOMPRESSEDTEXTURE1, HDRCOMPRESSEDTEXTURE1 == nSampler0 ? nSamplerZeroFlags : 0 ); + LoadTexture( iHDRCompressedTexture1, iHDRCompressedTexture2 == nSampler0 ? nSamplerZeroFlags : 0 ); } - if ( params[HDRCOMPRESSEDTEXTURE2]->IsDefined()) + if ( params[iHDRCompressedTexture2]->IsDefined()) { - LoadTexture( HDRCOMPRESSEDTEXTURE2, HDRCOMPRESSEDTEXTURE2 == nSampler0 ? nSamplerZeroFlags : 0 ); + LoadTexture( iHDRCompressedTexture2, iHDRCompressedTexture2 == nSampler0 ? nSamplerZeroFlags : 0 ); } } else { - if ( params[HDRBASETEXTURE]->IsDefined() ) + if ( params[iHDRBaseTexture]->IsDefined() ) { - LoadTexture( HDRBASETEXTURE, HDRBASETEXTURE == nSampler0 ? nSamplerZeroFlags : 0 ); + LoadTexture( iHDRBaseTexture, iHDRBaseTexture == nSampler0 ? nSamplerZeroFlags : 0 ); } } } } + + inline void CheckSkySGRB( IMaterialVar **params, IShaderShadow* pShaderShadow, ITexture *txtr, Sampler_t iSampler ) + { + ImageFormat fmt = txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead( iSampler, false ); + else + pShaderShadow->EnableSRGBRead( iSampler, true ); + } + + inline void BlendSkyRGBA( float &flMult, float flBlend, ITexture *txtr ) + { + ImageFormat fmt = txtr->GetImageFormat(); + if ((fmt == IMAGE_FORMAT_RGBA16161616) || ((fmt == IMAGE_FORMAT_RGBA16161616F) && (g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER))) + { + flMult = Lerp( flBlend, flMult, 16.0f ); + } + else + { + flMult = Lerp( 1.0f - flBlend, 0.0f, flMult ); + } + } + + SHADER_INIT + { + LoadSkyTexture( params, HDRBASETEXTURE, HDRCOMPRESSEDTEXTURE, HDRCOMPRESSEDTEXTURE0, HDRCOMPRESSEDTEXTURE1, HDRCOMPRESSEDTEXTURE2 ); + +#ifdef MAPBASE + if (params[USE_TEXTURE_BLENDS]->GetIntValue() > 0) + { + LoadSkyTexture( params, HDRBASETEXTURE2, HDRCOMPRESSEDTEXTURE_2, HDRCOMPRESSEDTEXTURE0_2, HDRCOMPRESSEDTEXTURE1_2, HDRCOMPRESSEDTEXTURE2_2 ); + LoadSkyTexture( params, HDRBASETEXTURE3, HDRCOMPRESSEDTEXTURE_3, HDRCOMPRESSEDTEXTURE0_3, HDRCOMPRESSEDTEXTURE1_3, HDRCOMPRESSEDTEXTURE2_3 ); + LoadSkyTexture( params, HDRBASETEXTURE4, HDRCOMPRESSEDTEXTURE_4, HDRCOMPRESSEDTEXTURE0_4, HDRCOMPRESSEDTEXTURE1_4, HDRCOMPRESSEDTEXTURE2_4 ); + } +#endif + } SHADER_DRAW { @@ -131,8 +201,45 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, NULL, 0 ); - DECLARE_STATIC_VERTEX_SHADER( sky_vs20 ); - SET_STATIC_VERTEX_SHADER( sky_vs20 ); +#ifdef MAPBASE + bool bUsesBlends = params[USE_TEXTURE_BLENDS]->GetIntValue() > 0; + bool bShouldBlend[4] = { true, false, false, false }; + if (bUsesBlends) + { + //bShouldBlend[0] = (params[BLEND1]->GetFloatValue() > 0.0f); + //bShouldBlend[1] = (params[BLEND2]->GetFloatValue() > 0.0f); + //bShouldBlend[2] = (params[BLEND3]->GetFloatValue() > 0.0f); + //bShouldBlend[3] = (params[BLEND4]->GetFloatValue() > 0.0f); + bShouldBlend[1] = (params[HDRBASETEXTURE2]->IsDefined() || params[HDRCOMPRESSEDTEXTURE_2]->IsDefined() || params[HDRCOMPRESSEDTEXTURE0_2]->IsDefined()); + bShouldBlend[2] = (params[HDRBASETEXTURE3]->IsDefined() || params[HDRCOMPRESSEDTEXTURE_3]->IsDefined() || params[HDRCOMPRESSEDTEXTURE0_3]->IsDefined()); + bShouldBlend[3] = (params[HDRBASETEXTURE4]->IsDefined() || params[HDRCOMPRESSEDTEXTURE_4]->IsDefined() || params[HDRCOMPRESSEDTEXTURE0_4]->IsDefined()); + + if (bShouldBlend[1]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); + } + if (bShouldBlend[2]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, false ); + } + if (bShouldBlend[3]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); + } + + Msg( "HDR sky uses blends: %f %f %f %f\n", params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() ); + } + else + { + Msg( "HDR sky does not use blends\n" ); + } +#endif + + DECLARE_STATIC_VERTEX_SHADER( sdk_sky_vs20 ); + SET_STATIC_VERTEX_SHADER( sdk_sky_vs20 ); if ( (params[HDRCOMPRESSEDTEXTURE]->IsDefined()) && mat_use_compressed_hdr_textures.GetBool() ) @@ -140,13 +247,27 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false); if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20b ); - SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20b ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20b ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20b ); } else { - DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); - SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20 ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20 ); } } else @@ -159,35 +280,122 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false); pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false); pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false); + +#ifdef MAPBASE + if (bUsesBlends) + { + if (bShouldBlend[1]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false ); + } + if (bShouldBlend[2]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER8, false ); + } + if (bShouldBlend[3]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER9, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER10, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER11, true ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER9, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER10, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER11, false ); + } + } +#endif + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); - SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20b ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20b ); } else { - DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); - SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20 ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20 ); } } else { - ITexture *txtr=params[HDRBASETEXTURE]->GetTextureValue(); - ImageFormat fmt=txtr->GetImageFormat(); - if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) - pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false); - else - pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,true); - - if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + CheckSkySGRB( params, pShaderShadow, params[HDRBASETEXTURE]->GetTextureValue(), SHADER_SAMPLER0 ); + +#ifdef MAPBASE + if (bUsesBlends) { - DECLARE_STATIC_PIXEL_SHADER( sky_ps20b ); - SET_STATIC_PIXEL_SHADER( sky_ps20b ); + if (bShouldBlend[1]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + CheckSkySGRB( params, pShaderShadow, params[HDRBASETEXTURE2]->GetTextureValue(), SHADER_SAMPLER1 ); + } + if (bShouldBlend[2]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + CheckSkySGRB( params, pShaderShadow, params[HDRBASETEXTURE3]->GetTextureValue(), SHADER_SAMPLER2 ); + } + if (bShouldBlend[3]) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + CheckSkySGRB( params, pShaderShadow, params[HDRBASETEXTURE4]->GetTextureValue(), SHADER_SAMPLER3 ); + } + + Msg( "Non-HDR sky uses blends: %f %f %f %f\n", params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() ); } else { - DECLARE_STATIC_PIXEL_SHADER( sky_ps20 ); - SET_STATIC_PIXEL_SHADER( sky_ps20 ); + Msg( "Non-HDR sky does not use blends\n" ); + } +#endif + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_ps20b ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sdk_sky_ps20 ); +#ifdef MAPBASE + SET_STATIC_PIXEL_SHADER_COMBO( USES_TEXTURE_BLENDS, bUsesBlends ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND1, bShouldBlend[0] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND2, bShouldBlend[1] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND3, bShouldBlend[2] ); + SET_STATIC_PIXEL_SHADER_COMBO( HAS_BLEND4, bShouldBlend[3] ); +#endif + SET_STATIC_PIXEL_SHADER( sdk_sky_ps20 ); } } } @@ -199,8 +407,8 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) DYNAMIC_STATE { - DECLARE_DYNAMIC_VERTEX_SHADER( sky_vs20 ); - SET_DYNAMIC_VERTEX_SHADER( sky_vs20 ); + DECLARE_DYNAMIC_VERTEX_SHADER( sdk_sky_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( sdk_sky_vs20 ); // Texture coord transform SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BASETEXTURETRANSFORM ); @@ -223,20 +431,48 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) float c1[4]={0.5/w-FUDGE, 0.5/h-FUDGE, w, h }; pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, c1); +#ifdef MAPBASE + bool bUsesBlends = params[USE_TEXTURE_BLENDS]->GetIntValue() > 0; + if (bUsesBlends) + { + float flBlends[4] = { params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 1, flBlends, 1 ); + + if (flBlends[1] > 0.0f) + { + BindTexture( SHADER_SAMPLER1, HDRCOMPRESSEDTEXTURE_2, FRAME2 ); + } + if (flBlends[2] > 0.0f) + { + BindTexture( SHADER_SAMPLER2, HDRCOMPRESSEDTEXTURE_3, FRAME3 ); + } + if (flBlends[3] > 0.0f) + { + BindTexture( SHADER_SAMPLER3, HDRCOMPRESSEDTEXTURE_4, FRAME4 ); + } + + Msg( "In dynamic mode, HDR sky uses blends: %f %f %f %f\n", flBlends[0], flBlends[1], flBlends[2], flBlends[3] ); + } + else + { + Msg( "In dynamic mode, HDR sky doesn't use blends\n" ); + } +#endif + BindTexture( SHADER_SAMPLER0, HDRCOMPRESSEDTEXTURE, FRAME ); c0[0]*=8.0; c0[1]*=8.0; c0[2]*=8.0; if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20b ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); - SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20b ); } else { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); - SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_rgbs_ps20 ); } } else @@ -249,44 +485,110 @@ BEGIN_VS_SHADER( Sky_HDR_DX9, "Help for Sky_HDR_DX9 shader" ) BindTexture( SHADER_SAMPLER0, HDRCOMPRESSEDTEXTURE0, FRAME ); BindTexture( SHADER_SAMPLER1, HDRCOMPRESSEDTEXTURE1, FRAME ); BindTexture( SHADER_SAMPLER2, HDRCOMPRESSEDTEXTURE2, FRAME ); +#ifdef MAPBASE + bool bUsesBlends = params[USE_TEXTURE_BLENDS]->GetIntValue() > 0; + if (bUsesBlends) + { + float flBlends[4] = { params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 1, flBlends, 1 ); + + if (flBlends[1] > 0.0f) + { + BindTexture( SHADER_SAMPLER3, HDRCOMPRESSEDTEXTURE0_2, FRAME ); + BindTexture( SHADER_SAMPLER4, HDRCOMPRESSEDTEXTURE1_2, FRAME ); + BindTexture( SHADER_SAMPLER5, HDRCOMPRESSEDTEXTURE2_2, FRAME ); + } + if (flBlends[2] > 0.0f) + { + BindTexture( SHADER_SAMPLER6, HDRCOMPRESSEDTEXTURE0_3, FRAME ); + BindTexture( SHADER_SAMPLER7, HDRCOMPRESSEDTEXTURE1_3, FRAME ); + BindTexture( SHADER_SAMPLER8, HDRCOMPRESSEDTEXTURE2_3, FRAME ); + } + if (flBlends[3] > 0.0f) + { + BindTexture( SHADER_SAMPLER9, HDRCOMPRESSEDTEXTURE0_4, FRAME ); + BindTexture( SHADER_SAMPLER10, HDRCOMPRESSEDTEXTURE1_4, FRAME ); + BindTexture( SHADER_SAMPLER11, HDRCOMPRESSEDTEXTURE2_4, FRAME ); + } + } +#endif if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); - SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20b ); } else { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); - SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_hdr_compressed_ps20 ); } } else { BindTexture( SHADER_SAMPLER0, HDRBASETEXTURE, FRAME ); - ITexture *txtr=params[HDRBASETEXTURE]->GetTextureValue(); - ImageFormat fmt=txtr->GetImageFormat(); - if ( - (fmt==IMAGE_FORMAT_RGBA16161616) || - ( (fmt==IMAGE_FORMAT_RGBA16161616F) && - (g_pHardwareConfig->GetHDRType()==HDR_TYPE_INTEGER)) - ) + +#ifdef MAPBASE + if (params[USE_TEXTURE_BLENDS]->GetIntValue()) { - c0[0]*=16.0; - c0[1]*=16.0; - c0[2]*=16.0; + float flBlends[4] = { params[BLEND1]->GetFloatValue(), params[BLEND2]->GetFloatValue(), params[BLEND3]->GetFloatValue(), params[BLEND4]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 1, flBlends, 1 ); + + float flMult = 0.0f; + if (flBlends[0] > 0.0f) + { + BlendSkyRGBA( flMult, flBlends[0], params[HDRBASETEXTURE]->GetTextureValue() ); + } + + if (flBlends[1] > 0.0f) + { + BindTexture( SHADER_SAMPLER1, HDRBASETEXTURE2, FRAME2 ); + BlendSkyRGBA( flMult, flBlends[1], params[HDRBASETEXTURE2]->GetTextureValue() ); + } + + if (flBlends[2] > 0.0f) + { + BindTexture( SHADER_SAMPLER2, HDRBASETEXTURE3, FRAME3 ); + BlendSkyRGBA( flMult, flBlends[2], params[HDRBASETEXTURE3]->GetTextureValue() ); + } + + if (flBlends[3] > 0.0f) + { + BindTexture( SHADER_SAMPLER3, HDRBASETEXTURE4, FRAME4 ); + BlendSkyRGBA( flMult, flBlends[3], params[HDRBASETEXTURE4]->GetTextureValue() ); + } + + c0[0] *= flMult; + c0[1] *= flMult; + c0[2] *= flMult; + } + else +#endif + { + ITexture *txtr=params[HDRBASETEXTURE]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ( + (fmt==IMAGE_FORMAT_RGBA16161616) || + ( (fmt==IMAGE_FORMAT_RGBA16161616F) && + (g_pHardwareConfig->GetHDRType()==HDR_TYPE_INTEGER)) + ) + { + c0[0]*=16.0; + c0[1]*=16.0; + c0[2]*=16.0; + } } if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20b ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); - SET_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20b ); } else { - DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20 ); - SET_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + DECLARE_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sdk_sky_ps20 ); } } }